Thanks for the tip.
I have it working to a degree, and test so far are encouraging
Here's the main code
Code:
;-----------------------------------------------------------------------------
; ***** MAIN PROGRAMMING LOOP *****
;-----------------------------------------------------------------------------
Main:
if Cvar >12 then Cvar=0
LCDOUT $fe,$80+5,"Hot",$fe,$80+10,"Cool",$fe,$80+16,"Hum"
Cvar=Cvar+1
SetPoint1 = normtemp1
SetPoint2 = normtemp2
SetPoint3 = normtemp3
SetPoint4 = normtemp4
gosub FlushBuffer:
If SetButton=0 then ; jump to programming
Gosub SetButtonRelease
goto mainmenu
endif
If DecButton=0 then
Gosub SetButtonRelease
goto lightoveride ; manual overide of light
endif
If IncButton=0 then
Gosub SetButtonRelease
goto cancelalarm ; manual overide of alarm
endif
gosub displaytime ; update the clock and display the time
FOR pid_Channel = 0 TO 3 ; cycle thru all sensors
GOSUB SelectSensor
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Convert ; start a temperature conversion
GIE = 1 ; enable interrupts after 1-wire
NEXT pid_Channel
FOR TempWD = 0 TO 1000
IF RCIF=1 THEN GOSUB coms ; Check to see id PC application connected
PAUSE 1
NEXT TempWD
FOR pid_Channel = 0 TO 3 ; cycle thru all sensors
GOSUB SelectSensor
DS1820_Error = 0 ; clear any previous errors
DS1820_Flags = 0 ; clear status flags
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Stat ; check the sensors status
GIE = 1 ; enable interrupts after 1-wire
PAUSEUS 20
IF !DS1820_Done THEN SensorError ; if it's not done by now, error
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Read ; get the temperature result
GIE = 1 ; enable interrupts after 1-wire
GOSUB Check4Zeros
DS1820_Flags = 0
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Stat
GIE = 1 ; enable interrupts after 1-wire
IF (DS1820_Error = 0) AND DS1820_Done THEN ; if there were no errors
Temperatures(pid_Channel) = TempC
pid_Error = SetPoints(pid_Channel) - TempC
GOSUB PID
IF pid_Out.15 THEN pid_Out = 0 ; only keep positive values
IF ChannelPWR(pid_Channel) THEN
HeaterDrives(pid_Channel) = pid_Out
ELSE
HeaterDrives(pid_Channel) = 0
ENDIF
IF Temperatures(pid_Channel) > alarmhigh(pid_Channel) and Alarm = 1 then AlarmPin = 1
IF Temperatures(pid_Channel) > alarmhigh(pid_Channel) and Alarm = 0 then AlarmPin = 0
IF Temperatures(pid_Channel) <= alarmhigh(pid_Channel) then AlarmPin = 0
IF Temperatures(pid_Channel) <= alarmlow(pid_Channel) then AlarmPin = 0
if Temperatures(pid_Channel) < alarmlow(pid_Channel) and Alarm = 1 then AlarmPin = 1
if Temperatures(pid_Channel) < alarmlow(pid_Channel) and Alarm = 0 then AlarmPin = 0
ELSE
SensorError:
HeaterDrives(pid_Channel) = 0 ; turn off heater if sensor's bad
SensorActive(pid_Channel) = 0
ENDIF
NEXT pid_Channel
If Cvar >=1 and Cvar <=3 then GOto ShowLCD1
If Cvar >=4 and Cvar <=6 then GOto ShowLCD2 ; display info on LCD
If Cvar >=7 and Cvar <=9 then GOto ShowLCD3
If Cvar >=10 and Cvar <=12 then GOto ShowLCD4
check:
; ---------------------------------------------------------------------------
; check lighting periods and turn lights on or off accordingly
; ---------------------------------------------------------------------------
fn = 0 ; select the first Lights
if lightover = 0 then GOSUB CheckTimes ; if manual override set to off then go compare the programed period
if lightover = 1 then progON=1 ; if manual override flag set to on then lights on flag set to 1
IF ProgON THEN ; If in the program period
IF Lights1 = 0 THEN Lights1 = 1
ELSE
IF Lights1 = 1 THEN Lights1 = 0
ENDIF
fn = 1 ; select the second Lights
if lightover = 0 then GOSUB CheckTimes ; compare the programed period
IF ProgON THEN
IF Lights2 = 0 THEN Lights2 = 1
ELSE
IF Lights2 = 1 THEN Lights2 = 0
ENDIF
; ---------------------------------------------------------------------------
; Check for night time drops - if condition matched, drop temp
; ---------------------------------------------------------------------------
fn = 0 ; select the first setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[0]=Droptemp[0] ; change the corresponding set point to the drop temperature
ELSE
SetPoints[0]= normtemp[0] ; change the corresponding drop temperature to set point
ENDIF
fn = 1 ; select the second setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[1]=Droptemp[1] ; change the corresponding set point to the drop temperature
ELSE
SetPoints[1]= normtemp[1] ; change the corresponding drop temperature to set point
ENDIF
fn = 2 ; select the third setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[2]=Droptemp[2] ; change the corresponding set point to the drop temperature
ELSE
SetPoints[2]= normtemp[2] ; change the corresponding drop temperature to set point
ENDIF
fn = 3 ; select the fouth setting
GOSUB CheckTimes2 ; compare the programed period
IF ProgON2 THEN
SetPoints[3]=Droptemp[3] ; change the corresponding set point to the drop temperature
ELSE
Setpoints[3]= normtemp[3] ; change the corresponding drop temperature to set point
ENDIF
;-----------------------------------------------------------------------------
; ***** MAIN PROGRAMMING LOOP END *****
GOTO Main
;-----------------------------------------------------------------------------
And here are the four LDC routines
Code:
ShowLCD1:
Pid_channel=0
LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," " ; print to LCD
TempC = Temperatures(pid_Channel)
gosub read_dht
LCDOUT $FE,$C0+5
TempWD = TempC : GOSUB TempToLCD ; display TempC
LCDOUT $DF
if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
LCDOUT $fe,$94,dec Cvar
goto check
ShowLCD2:
Pid_channel=1
LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," " ; print to LCD
TempC = Temperatures(pid_Channel)
gosub read_dht
LCDOUT $FE,$C0+5
TempWD = TempC : GOSUB TempToLCD ; display TempC
LCDOUT $DF
if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
LCDOUT $fe,$94,dec Cvar
goto check
ShowLCD3:
Pid_channel=2
LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," " ; print to LCD
TempC = Temperatures(pid_Channel)
gosub read_dht
LCDOUT $FE,$C0+5
TempWD = TempC : GOSUB TempToLCD ; display TempC
LCDOUT $DF
if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
LCDOUT $fe,$94,dec Cvar
goto check
ShowLCD4:
Pid_channel=3
LCDOUT $FE,$C0,"Viv",DEC1 Pid_channel+1," " ; print to LCD
TempC = Temperatures(pid_Channel)
gosub read_dht
LCDOUT $FE,$C0+5
TempWD = TempC : GOSUB TempToLCD ; display TempC
LCDOUT $DF
if SensorActive(pid_Channel) = 0 then lcdout $FE,$C0+5,"N/C"
LCDOUT $fe,$94,dec Cvar
goto check
OK it may be crude, have lots of duplication but it achieves the result I'm after. The good news is that whilst it's cycling around the loop and displaying values for say viv3, the PID still works fine for Viv1. I might then tidy the layout up a bit so I can get the decimals in for the temperatures, but I'm not that bothered about the decimal points - I mean I'm sure my pythons and boa don't care if it's 32.9 or 33.0 C
Bookmarks