15
« on: November 11, 2014, 03:10:57 PM »
I think I got it now... Thanks!
I'm trying to jam most commands into custom functions so I can build libraries. This is to control a furnace with a max duty cycle of 30%. I know there is a lot of ways to skin the cat but the while loops seem to work well for me in my rookie programming.
**************Heat Loop Custom Function**************
'This will "roughly" count in minutes how long this custom function/latch has been running.
If testio(Latch) = 1
DM[10]= DM[10]+1
ENDIF
'There are three 5 minute "heat on" blocks which are triggered by a "heat demand" custom function.
'A time count is in place to ensure only 15 minutes of 50 minutes will have heat (total 30% duty cycle).
'The first 5 minute block is automatic. The other blocks are checked with while loops at 6 minutes
'and 11 minutes.
N=DM[10]
'*****FIRST 5 MIN BLOCK*****
IF dm[10] <= 5
setio furnace_on : setio Hold_Off
ENDIF
'*****At 6 mins, if want heat, give heat, if not shut down*****
WHILE N = 6
if testio(Want_Heat)=1
setio furnace_on : setio Hold_Off : exit
elseif testio(Want_Heat)=0
clrio furnace_on : setio Hold_Off : exit
endif
exit
ENDWHILE
'*****At 10 min, if want heat, give heat, if not shut down*****
WHILE N = 11
if testio(Want_Heat)=1
setio furnace_on : setio Hold_Off : exit
elseif testio(Want_Heat)=0
clrio furnace_on : setio Hold_Off : exit
endif
exit
ENDWHILE
'*****At 16 mins, cut heat, wait*****
WHILE N = 16
if testio(Want_Heat)=1
clrio furnace_on : setio Hold_Off : exit
endif
exit
ENDWHILE
IF N >= 50
clrio Latch : DM[10] = 0 : setlcd 0,0, chr$(1) : clrio Furnace_On : N=0 :clrio Hold_Off
ENDIF
setlcd 1,1, "DM[10] "+str$(dm[10])
setlcd 2,1, "N= "+str$(n)