Does anyone have a formula for finding the time in seconds from TIMER0 on PIC16. I know my frequency, prescaler, and number of cycles (overflow and normal)... I can't connect the dots properly -.-

Views: 66

Reply to This

Replies to This Discussion

Isn't it 
Time = 256 * prescaler * number of cycles / (frequency)? And then you add (number of cycles taken up by your interrupt code) / (frequency) while the timer is inactive.

TIMER0 maxes out at 255 so unless you're measuring milliseconds it won't be very useful. Usually you look at the number of overflows (which you can track in your ISR because an overflow will cause an interrupt). At 1:256 prescaler on the 10MHz clock TIMER0 will overflow ~38 times per second

My main issue is that my number of cycles is pretty random when I change my prescaler - like I'm getting 100 for a 1:256 and 51 for 1:2... isn't the 1:256 supposed to produce less cycles?

 

Are u sure your number of cycles isnt also overflowing? Remember any register maxes out at 255

 that number was the overflow counter, but yeah, that might be it xD Thanks!!

RSS

© 2024   Created by PML.   Powered by

Badges  |  Report an Issue  |  Terms of Service