모터 > 쿼드콥터 변속기 - 모터로 소리를 내는 코드

TODAY455 TOTAL2,930,571
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 모터 | BLDC모터 | 쿼드콥터 변속기 - 모터로 소리를 내는 코드

페이지 정보

작성자 키트 작성일2017-09-05 15:04 조회1,287회 댓글0건

본문

davide gironi 소스를 보면

모터가 회전하기 위한 commutation step은


/* * output a motor step */
void run_step(U_C step){ //define positions for running phases depending on hall sensor
    switch (step){
        case 0: if(dir==DIR_CW)RUN6 else RUN5 break; // 101CW=RUN6, 101CCW=RUN5
        case 1: if(dir==DIR_CW)RUN1 else RUN4 break; // 100CW=RUN1, 100CCW=RUN4
        case 2: if(dir==DIR_CW)RUN2 else RUN3 break; // 110CW=RUN2, 110CCW=RUN3
        case 3: if(dir==DIR_CW)RUN3 else RUN2 break; // 010CW=RUN3, 010CCW=RUN2
        case 4: if(dir==DIR_CW)RUN4 else RUN1 break; // 011CW=RUN4, 011CCW=RUN1
        case 5: if(dir==DIR_CW)RUN5 else RUN6 break; // 001CW=RUN5, 001CCW=RUN6
    }
}

RUN1~RUN6까지 순서대로 되어 있습니다. (반대 방향으로 돌아 갈 때는 역순)

 

/* power on sound */

void power_on_sound(){ sounder(1,20,20,1200); sounder(1,20,120,1200); sounder(1,20,240,1200); }
처음 전원 넣고 나는 3개의 비프음은 위 함수에서 실행 합니다.

관련 함수를 올리고 다시보죠


void sounder(U_C repet,U_C duration,U_I ontime,U_I offtime){
    U_C i=0,q=0;
    for(i=0;i<repet;i++){
        for(q=0; q<duration; q++){
            RUN1; sound_cycle(ontime,offtime);

            RUN4; sound_cycle(ontime,offtime);

            RUN3; sound_cycle(ontime,offtime);
            RUN6; sound_cycle(ontime,offtime);

            RUN5; sound_cycle(ontime,offtime);

            RUN2; sound_cycle(ontime,offtime);
        }
        delay_ms(30);
    }
}

 

void sound_cycle(U_I ontime,U_I offtime){ /* * do one sound cycle */
    U_I i=0;
    for(i=0;i<ontime;i++)delay_us(1); BREAK; STOP; for(i=0;i<offtime;i++)delay_us(1);
}

 

void power_on_sound(){

  sounder(1,20, 20,1200); //(1200+ 20)us * 20 = 24.0ms 주기, 주파수 820Hz

  sounder(1,20,120,1200); //(1200+120)us * 20 = 26.4ms 주기, 주파수 758Hz

  sounder(1,20,240,1200); //(1200+240)us * 20 = 28.8ms 주기, 주파수 695Hz

}
딜레이 시간만으로 계산 한 것이라서 실제는 이보다 더 낮은 주파수가 될겁니다.

//

            RUN1; sound_cycle(ontime,offtime);

            RUN4; sound_cycle(ontime,offtime);

            RUN3; sound_cycle(ontime,offtime);
            RUN6; sound_cycle(ontime,offtime);

            RUN5; sound_cycle(ontime,offtime);

            RUN2; sound_cycle(ontime,offtime); 

commutation step 순서도 맞지 않습니다.

이렇게 순서를 엉터리로 해야지 모터가 회전하지 않고 소리만 나게 되는 것이죠

//

 

 

이번에는 tgy6a 소스를 보죠(i2c_r09)

  beep_f1(); delay_ms(30);
  beep_f2(); delay_ms(30);
  beep_f3(); delay_ms(120);
  beep_f4(); beep_f4(); beep_f4();  // 같은 음의 소리를 길게 내기 위해서 3번 반복 
4가지 음으로 소리를 내고 있습니다.

 

// beeper: timer0 is set to 1탎/count
void beep_f1(){ beep( 80,200); } // 625Hz, 128ms
void beep_f2(){ beep(100,180); } // 695Hz, 144ms
void beep_f3(){ beep(130,160); } // 781Hz, 167ms
void beep_f4(){ beep(200,100); } // 1250Hz, 160ms

 

void beep(tp2,tp4):
 unsigned char i;
 int d;
 d=tp4<<3; //tp4*8 us
 for(i=0;i<tp2;i++){ BpFET_on; AnFET_on; delay_us(32); BpFET_off; AnFET_off; delay_us(d); }
}
delay_us(d); <-- us 딜레이 함수는 변수 허용이 안된다는 것은 알고 계시죠?

어셈블러를 c로 바꾸면서 이해를 돕기 위해서 넣어둔 것이니 대충 넘어가시면 됩니다.^^

 

이 소스에서는 한개의 commutation step만으로 소리를 만들고 있습니다.

댓글 0

조회수 1,287

등록된 댓글이 없습니다.

모터HOME > 모터 > 전체 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기