PDA

View Full Version : Timer Function? Not sure what I need here.



wdmagic
- 15th April 2013, 01:01
I need to call a sub on a schedule, say every 30 minutes. The sub reads 8 ADC's into a VAR Array and sets PORTB based on those numbers.
I dont need it so accurate that I would need a RTC, but I would like to get in the neiborhood of 30 minutes. and I need it to do this like an interupt where it will fire even in a pause mode.

Here is what I need to call every 30 minutes (and optional on button would be nice but PORTB INT's are being used)


ReadVolts:
For X = 0 to 7
PORTE = X 'Activates Binary Relays
PAUSE 100 ' Allow Relay contacts to settle before ADC Conversion
ADCIN 0, VOLTS[X] ' Read Channel 0 data
VOLTS[X] = VOLTS[X] / 13 ' 64k = ~5000 mv (temporary math)
if VOLTS[X] > 4000 then
PORTB.0[X] = 1
ELSE
PORTB.0[X] = 0
ENDIF
PauseUS 100 ' Pause for ADC Refresh
NEXT X
RETURN


PORTB uses Bipolar LEDs for status indicators. I am going to assume I need to use one of the internal timers, but I have never used them. So if anyones got any ideas or code samples....

Demon
- 15th April 2013, 02:28
Have you looked at
http://www.picbasic.co.uk/forum/showthread.php?t=3251
?

Robert

Edit: checking if 30 minutes has passed is one possibility:
http://www.picbasic.co.uk/forum/showthread.php?t=3251

wdmagic
- 15th April 2013, 02:53
yea thats a thought, I didnt think of useing darrels INT's, I havent messed with them yet. I was waiting till I had a few days to play with them and other bits of his code.

right now I need to use a internal timer INT? I think. Using a 18F4550 chip. so something like timer1 set for every 30 minutes using DT's INT's
I might need a second timer to run a second sub to flash a led, not sure if this can be done so that they dont conflict. will post some code in a bit as example.
Do you think thats the best way though to do the 30 minute timer INT using DT_INTS? trying to KISS! "keep it simple stupid" want program small but stable.

HenrikOlsson
- 15th April 2013, 07:33
Hi,
You probably won't be able to set up any hardware timer to interrupt at a rate as low once every 30 minutes - if you don't run the PIC REALLY slow that is.
What you usually do is set it up to interrupt at something like 10Hz or whatever and then keep track of the number of interrupts in order to get a total of 30 minutes (18000 interrupts in this case). That way you can use the same timer and interrupt for the LED flashing and any other timing tasks you might need.

Darrels DT-Ints are a great way to this.

/Henrik.

Demon
- 15th April 2013, 14:19
Personally, I'd check if 30 minutes elapsed; as KISS as you get.

Check DT's thread and link to his site for details.

Robert