Guyzz
I have a Olimex mt-128 board
http://www.olimex.com/dev/images...
And i'm trying to generate a 4-Khz buzzersignal , similar to this
The Buzzer is connected to =C3B & OC3C on the M128 , probably to get a "double swing" when driving the square , in opposite phases.
void BUZZER(void) { while (B4==0) { bit_clear(PORTE,BUZZ1); //250us bit_set(PORTE,BUZZ2); delay_us(125); bit_clear(PORTE,BUZZ2); //250us bit_set(PORTE,BUZZ1); delay_us(125); } }
But i would like to use CTC to generate the square signal , but have some problems getting the buzzer to say anything.
I have a One second timer in the stop_buzzer (and it should stop the OCRxx after that time) , and i can hear a faint "click" in the buzzer every second , but no "beep".
The Xtal is 16 Mhz , and it's one of my first try's with a M128.
Can anyone give a hint ???
I must admit i haven't had a scope on yet ...
#define T3_LOOP_125NS (uint16_t )(((F_CPU/T3_PRESCALER) / (1000000/125)) + 0.5) uint8_t start_buzzer(void) { uint8_t sreg; // // Buzzer CTC Mode OC3A not used , OC3B & 0C3C Toggled (Timer3) // // // Mode CTC , Prescaler None , Stop Timer // TCCR3B= ((0<<ICNC3) | (0<<ICES3) | (0<<0) | (0<<WGM33) | (1<<WGM32) | (0<<CS32) | (0<<CS31) | (0<<CS30)); // // Disconnect OCR3A , Toggle OCR3B & OCR3C // TCCR3A = ((0<<COM3A1) | (0<<COM3A0) | (0<<COM3B1) | (1<<COM3B0) | (0<<COM3C1) | (1<<COM3C0) | (0<<WGM31) | (0<<WGM30)); // // Force Output compare on OC3B , to make a toggle , and make sure it is the opposite of OC3C // TCCR3C=((0<<FOC3A) | (1<<FOC3B) | (1<<FOC3C) | (0<<0) | (0<<0) | (0<<0) | (0<<0) | (0<<0)); //Make these writes atomic sreg = SREG; asm("cli"); TCNT3 = 0; OCR3B = T3_LOOP_125NS - 1; // My Freq counter shows more accuracy when i match on OCR3C = T3_LOOP_125NS - 1; // My Freq counter shows more accuracy when i match on // one less than the calculated counter value thats why i use the -1 SREG = sreg; //TIMSK = (1<<OCIE0); // Enable CTC0 Interrupt // // Mode CTC , Prescaler 8 , Start Timer // TCCR3B= ((0<<ICNC3) | (0<<ICES3) | (0<<0) | (0<<WGM33) | (1<<WGM32) | (0<<CS32) | (1<<CS31) | (0<<CS30)); stop_buzzer(ON); return(ON); } uint8_t stop_buzzer(uint8_t state) { static uint16_t timer, buzzer; if(state == ON) { timer = 0; buzzer = ON; } if(buzzer == ON) { if(inttimerreached(&timer,(1 * ONE_SECOND))) { buzzer = OFF; // // Mode CTC , Prescaler None , Stop Timer // TCCR3B= ((0<<ICNC3) | (0<<ICES3) | (0<<0) | (0<<WGM33) | (1<<WGM32) | (0<<CS32) | (0<<CS31) | (0<<CS30)); // // Disconnect OCR3A , OCR3B & OCR3C // TCCR3A = ((0<<COM3A1) | (0<<COM3A0) | (0<<COM3B1) | (0<<COM3B0) | (0<<COM3C1) | (0<<COM3C0) | (0<<WGM31) | (0<<WGM30)); } } return(buzzer); }
/Bingo
[/code]