PDA

View Full Version : TMR0 interupt bit



jmgelba
- 19th April 2005, 21:33
How do I assign a var word to the interupt flag? I need to count the number of times the overflow flag has been set, store this value then do some math with it and output that result to a display. The display part i've got working but I just need to identify an overflow condition and accumulate them in a var word somewhere. I can preload the counter with a number and I can get that number to display on my 7 seg displays.

Im sure I'll get the hang of this one day.

mister_e
- 19th April 2005, 21:53
if i understand what you want to do... the easiest solution will be to increment a variable on each TIMER0 interrupt. you'll do it in your interrupt routine.

jmgelba
- 20th April 2005, 00:22
Yeah, but I dont know how to. :-) Here's a go at it.....

display var word
count var word




display = 0 ' set initial value of counter display (This should appear on the 7 seg displays.)
TMR0 = $00 ' set timer value to 0
on interrupt goto setdisplay

disable
setdisplay:
count = count + 1
count = display
INTCON.2 = 0 ' clear overflow flag
TMR0 = $00 ' reload TMR0
resume
enable



However, I still cant see how the timer overflow registers in the count var word.

mister_e
- 20th April 2005, 03:59
you must tell to TIMER0 where to take it's clock to increment and enable interrupts.

let's say you have a 16F628. you'll find the setting in the INTCON and OPTION registers

OPTION register
by default TIMER0 get it's clock source from pin RA4, on a high to low transistion with a rate of 1:256... is this what you want?

INTCON register
To make your interrupt routine work, you must, at least, enable the TIMER0 interrupt and the global interrupt... they're disable when you boot the PIC

So INTCON=%10100000


what about now?

Dave
- 20th April 2005, 11:44
James, Also in your snipit of code you increment "counter" but then re-zero it by saying "counter = display". You load thenvariable "display" with zero and never increment it but pass it's value to "counter".

Dave Purola,
N8NTA

jmgelba
- 20th April 2005, 13:36
Ok, added the option_reg to set up the counter to count ra4, low to high, WDT with a 1:1 prescale.
Removed the count = display. Display should now increment? I can then use the value in display and send it out to the digits?

What I was trying to do there was have display = count so that display would continue being incremented and I could do all the math and segment work with count word. This is becuase I need to count 21600 interupts, and them send that out as a 1 to the 7 segments. Sort of like a custom interupt postscaler I guess.

Thanks for your help and insight everyone. Dave I already owe you one!

display var word


OPTION_REG = %11101000
INTCON = %10100000

display = 0 ' set initial value of counter display (This should appear on the 7 seg displays.)
TMR0 = $00 ' set timer value to 0
on interrupt goto setdisplay

disable
setdisplay:
display = display + 1

INTCON.2 = 0 ' clear overflow flag
TMR0 = $00 ' reload TMR0
resume
enable

jmgelba
- 20th April 2005, 13:41
I think a light just came on!!

Am I correct in thinking that you cant directly assign a word to the overflow flag, but when it interupts, your word can be embedded in the subroutine that you run on interupt? So the above code example would prove this by now having the display word being incremented whenever the timer overflows and provides the interupt.
Its all semantics!!

Dwayne
- 20th April 2005, 14:40
Hello JM,

Jm>> So the above code example would prove this by now having the display word being incremented whenever the timer overflows and provides the interupt.<<

That is correct...


Dwayne

jmgelba
- 21st April 2005, 13:41
DEFINE OSC 10

OPTION_REG = %11101000
INTCON = %10100000

Display var word


TMR0 = $00 ' set timer value to 0
on interrupt goto setdisplay


disable
setdisplay:
display = display + 1
write 100,display
INTCON.2 = 0 ' clear overflow flag
TMR0 = $00 ' reload TMR0
resume
enable

This will increment the value in location 5 which is great. However, when I add this line........


data @0,192,249,164,176,153,146,130,248,128,144 ' 0-9 segment data


.....location 100 will no longer store any value. What am I missing?

jmgelba
- 22nd April 2005, 15:42
Any thoughts on this?