Is my calculation right for generating 8 kHz PWM ?

Status
Not open for further replies.

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
Visit site
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 ?
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:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…