Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] ATMega8 Frequeny problem and i confused :|

Status
Not open for further replies.

shirko20

Member level 2
Joined
Sep 29, 2013
Messages
44
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
381
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)
{

}
}
 
Last edited:

Hi

I'm not sure if understand right..

8MHz without prescaler,
128 clock cycles low, 128 clock cycles high, makes 256 clock cycles for a complete square wave.
Makes 31.25kHz.

Did you expect something else?

Klaus
 
HI KlausST AND THANKS FOR REPLAY ; i did not understand the consept and that was my error,you helped me to remember that any thik of timer work at cpu clock and ocr2=256 of thiks ,thanks again
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top