[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 580: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 636: sizeof(): Parameter must be an array or an object that implements Countable
Brads Electronic Projects Forum • programming a 6 hour delay
Page 1 of 1

programming a 6 hour delay

Posted: Wed Aug 28, 2013 7:42 am
by MrDEB
I need to include a six hour delay in a project I am working on. Was contemplating just using
delayms(1000 * 60) = 600 seconds or 10 minutes I think? but going out to 6 hours??delayms(1000 *
Just need to toggle a port for 20 minutes every 6 hours. I looked over the modules in SF but? I realize using delayms is not very accurate but in the application I don't need dead on accuracy.

Re: programming a 6 hour delay

Posted: Wed Aug 28, 2013 7:51 am
by MrDEB
I may have located an old file I had on a hard drive that kinda went south but was able to recover some of the data.Not sure if this is really what I want but will ponder the results etc. but any better solutions perhaps?

Code: Select all

}
Interrupt MyInt()
    TMR2IF=0
    Count=Count+1
    If Count=50 Then
        Count=0
        IntFlag=1
    EndIf
End Interrupt
Sub Delay(Seconds As Word)
Dim x As Word
    For x=0 To Seconds
        While(IntFlag=0)
        Wend
        IntFlag=0
    Next
End Sub
OSCCON = $72            // select 8MHz internal clock
ADCON1  = $7f           //all digital
NOT_RBPU=0              //WPUs on port B
T2CON = %01001110       //pre=16 post=10
PR2 = 249               //=8000000/4/16/10/250 = 50Hz
TMR2IE=1                //enable timer 2 interrupts
Enable(MyInt)           //set interrupt going
While true
    LED(1)              //light LED 1    
    Delay(5)            //wait 5 seconds
    LED(2)              //light LED 2
    Delay(1)            //wait 1 second
Wend

Re: programming a 6 hour delay

Posted: Thu Aug 29, 2013 2:19 am
by bitfogav
There's Several ways you could do it?.

A really simple but hacky way would be to use a For Loop, especially if your not looking for accuracy.
But your programme will be stuck in this For Loop for 6hours, so your programme won't be able to do other things, thats if you want it too?:

Code: Select all

Dim i as word
For i = 1 to 21600	// 21600 secs in 6hours
  DelayMS(1000) 	// 1sec delay
Next
Another way is to use Swordfish ISRTimer.bas Module, set a timer event handler and a counter to count secs?.

Or like you have posted use ISR, There's some good information here about timers Soft RTC

Re: programming a 6 hour delay

Posted: Thu Aug 29, 2013 7:14 am
by brad
bitfogav's ideas would certainly do the trick.

I was thinking you could get a cheap real time clock module from ebay (for about $2) but then realised the microcontroller can do this all by itself!

Re: programming a 6 hour delay

Posted: Sun Sep 01, 2013 1:54 am
by MrDEB
Biogravs HACKY method looks easy enough. I like to KISS. Just need to insert the ds18B20 section in between the counting. Then a 20 miniute delay.
This is for a beer cooler that I got working last year but still have issues with the evaporators freezing up. Was told that I need a defrost timer. Contemplating an adjustable defrost timer.

Re: programming a 6 hour delay

Posted: Sun Sep 01, 2013 2:13 am
by bitfogav
MrDEB wrote:Biogravs HACKY method looks easy enough. I like to KISS. Just need to insert the ds18B20 section in between the counting. Then a 20 miniute delay.
This is for a beer cooler that I got working last year but still have issues with the evaporators freezing up. Was told that I need a defrost timer. Contemplating an adjustable defrost timer.
MrDeb.. If I was making a project to cool down a beer cooler and to stop the evaporators freezing up then I would probably want to monitor the DS18B20 temp sensor constantly? Or maybe switch the cooler on for an hour and then check the temperture? if the evaporators are freezing up then have some sort of delay to switch the cooler off for a period of time?.
Then recheck the evaporators temp, if all ok then switch the cooler back on?.

In fact I might have two temperature sensors 1x for the beer cooler and 1x for the evaporator?.

Re: programming a 6 hour delay

Posted: Sun Sep 01, 2013 9:51 pm
by brad
Where does the 6 hour delay play a part?