bianchi77
Advanced Member level 4
- Joined
- Jun 11, 2009
- Messages
- 1,313
- Helped
- 21
- Reputation
- 44
- Reaction score
- 20
- Trophy points
- 1,318
- Location
- California
- Activity points
- 9,442
Guys,
Is my calculation right for generating 3.8 kHz PWM ?
PWM wave frequency is f= 16000000/(2*8*256) = 3.8 kHz
I want to put the output into OC1A,
Is my init code right ?
Thank you
Is my calculation right for generating 3.8 kHz PWM ?
PWM wave frequency is f= 16000000/(2*8*256) = 3.8 kHz
I want to put the output into OC1A,
Is my init code right ?
Code:
timer_init()
{
//page 136 ATMEGA128A datasheet
TCCR1A = 0xA7; // PWM, Phase Correct, 8-bit set OC1A on compare match, clear them at top,set OC1B on compare match, clear them at top
TCCR1B= 0x12;
}
int main(void)
{
DDRB=0xFF;
timer_init();
while(1)
{
OCR1A = 100; //beep on
//sound for 500ms
_delay_ms( 500 );
OCR1A = 0; //turn beep off
//wait 1s between beeps
_delay_ms( 1000 );
//TODO:: Please write your application code
}
}
Thank you
Last edited: