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.

Need help: AVR 8-bit timer

Status
Not open for further replies.

Don_dody

Full Member level 1
Full Member level 1
Joined
Nov 4, 2012
Messages
96
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Indonesia
Visit site
Activity points
1,921
Can anybody tell me how to calculate OCR0 & OCR2 in timer0 and timer 2?

I've been searching and just found formula to calculate TCNT and OCR1A.

Help me please.
 

oh, so you mean calculation of OCR0 is the same as OCR1A?

Actually I just need the formula, but if you want to help:
I use AVR ATmega8535
12Mhz
prescaler 1024.

I need, 0.5 ms and 9 ms time interval.
 

The calculation is the same for any mcu.

First find the frequency of the timer, in your case 12000000/1024 =11718.75Hz

Then the period to see the time it takes for each tick of the timer 1/11718.75Hz= 85.3us

Nor calculate how many ticks you need for required delay.
For 0.5ms 0.0005/0.0000853 = 5.86 , the closest integer is 6 , the compare match value you should use is the result -1 so 6-1=5 (I assume CTC mode , if not you should wait for 6 ticks to get the delay you want)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top