programming a 6 hour delay

Post here to discuss programming with swordfish basic

Moderators: Chuckt, Garth, bitfogav

Post Reply
MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am

programming a 6 hour delay

Post by MrDEB » Wed Aug 28, 2013 7:42 am

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.

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am

Re: programming a 6 hour delay

Post by MrDEB » Wed Aug 28, 2013 7:51 am

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

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: programming a 6 hour delay

Post by bitfogav » Thu Aug 29, 2013 2:19 am

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
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm

Re: programming a 6 hour delay

Post by brad » Thu Aug 29, 2013 7:14 am

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!

MrDEB
I practically live here!
I practically live here!
Posts: 372
Joined: Fri Feb 18, 2011 4:24 am

Re: programming a 6 hour delay

Post by MrDEB » Sun Sep 01, 2013 1:54 am

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.

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: programming a 6 hour delay

Post by bitfogav » Sun Sep 01, 2013 2:13 am

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?.
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm

Re: programming a 6 hour delay

Post by brad » Sun Sep 01, 2013 9:51 pm

Where does the 6 hour delay play a part?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests