PDA

View Full Version : 30 minute timer



O2_Guy
- 27th December 2007, 04:12
I have an application that needs to output a Lo bit after the ADCIN (10bit) sees a full 1023 count for a continuous 30 minites.

I know what I have to do, but don't know exactly how to code it in PICBASIC Pro. Can anyone steer me in the right direction?

I'm using a PIC16F877A and a 4Mhz clock.

I will be keeping track of the TMR1IF with interrupts off (TMR1IE=0). With a 16 bit counter and 4Mhz clock, 4 the clk to instruction cycle divider, and 8 the maximum timer prescaler value, the maximum timer1 rollover time is (65536*4*8/4e106)= 524ms

If I keep track of the TMR1IF with a counter loaded to a value of rollovers equal to 30 min (in the above example that would be 30*60/.524 = 3435)

If the ADC routine sees a value of less than 1023 it loads the timeout of 3435.
Every time throught the program loop, TMR1IF flag is checked. If it is set it is cleared and the counter decremented. When the counter gets to 0 the Lo bit is output to an analog switch.

BobK
- 27th December 2007, 13:26
Hi O2,

Why don't you consider Darrel Taylor's Elapsed Timer program? It can be preset through your code to what ever amount of time you need.

Just goto the Code Examples section and look for it.

HTH,

BobK

Acetronics2
- 27th December 2007, 15:01
Hi,

A simple way could be to count how many times you have read "1023" and reset the counter if other reading ... there might be something like a timed loop in your program ...

from your TMR1 example ...

IF counter > 3435 then AUTO_DESTRUCT_LAUNCHED ...

"on interrupt" might be more than enough to flag the TMR1 Overflows and increment counter ...

Alain

O2_Guy
- 28th December 2007, 18:24
Haven't had too much response from my question. I have just about conquered it and will post the code when I'm done. In the meantime, if there are any ideas wihout interrupts, (since I'm using DIV32), please post.

skimask
- 28th December 2007, 19:05
if there are any ideas wihout interrupts, (since I'm using DIV32), please post.

What's the problem with using interrupts and DIV32? The manual tells you how to avoid problems with that.