shirko20
Member level 2
ATMega8 Frequency problem and i confused :|
HELLO. I wrote a code to atmega8 to Clear OC2 pin of avr in frequeny of 8MHZ AND i set cs20 of timer2 in no prescaling (clk of timer==clock of cpu);here is code but when i run this in proteus and use Counter Timer component in proteus to measure Frequency of OC2 PIN IT SHOWS 31.25KHz it means that==>> 8MHz/256=31.25KHz but i chosen Timer1 clocl== F_clock=8MHz:what is problem:: also i set CLCSEL FUSE INTERNAL 8MHz IN PROTEUS:
....................................................................................
#include <avr/io.h>
#include <util/delay.h>
void init_pwm()
{
TCCR2 |= (1<<CS20) | (1<<WGM20) | (1<<WGM21) |(1<<COM21);
TCNT2=0;
OCR2=128; //DutyCycle =50%
DDRB |=(1<<PB3);
}
int main(void)
{
init_pwm();
while(1)
{
}
}
HELLO. I wrote a code to atmega8 to Clear OC2 pin of avr in frequeny of 8MHZ AND i set cs20 of timer2 in no prescaling (clk of timer==clock of cpu);here is code but when i run this in proteus and use Counter Timer component in proteus to measure Frequency of OC2 PIN IT SHOWS 31.25KHz it means that==>> 8MHz/256=31.25KHz but i chosen Timer1 clocl== F_clock=8MHz:what is problem:: also i set CLCSEL FUSE INTERNAL 8MHz IN PROTEUS:
....................................................................................
#include <avr/io.h>
#include <util/delay.h>
void init_pwm()
{
TCCR2 |= (1<<CS20) | (1<<WGM20) | (1<<WGM21) |(1<<COM21);
TCNT2=0;
OCR2=128; //DutyCycle =50%
DDRB |=(1<<PB3);
}
int main(void)
{
init_pwm();
while(1)
{
}
}
Last edited: