OK guys I need some help here.
Here is the main part of the code which uses the timer overflow to generate the time, and from that derive the value for Counter1, which is then used to trigger the case statements and ramp up the lights, etc - This works. The percentages for the PWM are shown on the LCD and the case (Night, Dawn, Day and Dusk) all change depending on the logic.
Code:
'*******************************************************************************
'clock routine
ClockLoop: IF intcon.2=0 THEN ClockLoop 'Poll for TMRO overflow
INTCON.2=0 'Clear TMRO overflow flag
HzTimer=HzTimer-$1000 'decrement timer count
IF HzTimer < $1000 THEN
IF Col=10 THEN 'update time'
SS=SS+1
IF SS=60 THEN ' minute
SS=0
MM=MM+1
IF MM=60 THEN ' hour
MM=0
HH=HH+1
IF HH=24 THEN HH=0
ENDIF
counter1 = (HH*60)+MM
ENDIF
ENDIF
Col=Col+1
HzTimer=HzTimer+$7A12 'Add 0.5 seconds to count
ELSE
ENDIF
if Col=11 then
Col=1
endif
LCDOut $FE,$D4,#HH DIG 1,#HH DIG 0,":",#MM DIG 1,#MM DIG 0
'*******************************************************************************
'check what part of the cycle
If Counter1 < Blue_on_Time then
Blue_day_cycle = NIGHT
endif
if counter1 > blue_on_time and Counter1 > blue_off_Time and B_PWM > B_Min then
Blue_day_cycle = DUSK
endif
if counter1 => blue_on_time and Counter1 < blue_off_Time and B_PWM < B_MAX then
Blue_day_cycle = DAWN
endif
If Counter1< White_on_Time then
White_day_cycle = NIGHT
endif
if counter1 > white_on_time and Counter1 > white_off_Time and W_PWM > W_Min then
White_day_cycle = DUSK
endif
if Counter1 => white_on_time and Counter1 < white_off_Time and W_PWM < W_MAX then
White_day_cycle = DAWN
endif
'*******************************************************************************
'*** Do BLUE daily cycle
select case Blue_Day_Cycle
case DAWN
lcdout $FE,$80+13,"DAWN "
if ss//blue_delay_in = 0 then
if ss != old_ss_blue then
B_PWM=B_PWM+1
old_ss_blue=ss
endif
endif
if B_PWM = b_max then
Blue_Day_Cycle = DAY
endif
case DAY
lcdout $FE,$80+13,"DAY "
if B_max < B_PWM then
B_PWM=B_PWM - 1
endif
if counter1 =blue_off_time then
Blue_day_cycle = DUSK
endif
CASE DUSK
lcdout $FE,$80+13,"DUSK "
if ss//blue_delay_out= 0 then
if ss != old_ss_blue then
B_PWM=B_PWM-1
old_ss_blue=ss
endif
endif
if B_PWM = B_MIN then
Blue_Day_Cycle = NIGHT
endif
case NIGHT
lcdout $FE,$80+13,"NIGHT"
B_PWM=B_min
end select
'*******************************************************************************
'*** Do WHITE daily cycle
select case White_Day_Cycle
case DAWN
lcdout $FE,$C0+13,"DAWN "
if ss//white_delay_in= 0 then
if ss != old_ss_white then
W_PWM = W_PWM+1
old_ss_white=ss
endif
endif
if W_PWM = W_max then
White_Day_Cycle = DAY
endif
case DAY
lcdout $FE,$C0+13,"DAY "
if W_max < W_PWM then
W_PWM=W_PWM - 1
endif
if counter1 =white_off_time then
White_day_cycle = DUSK
endif
CASE DUSK
lcdout $FE,$C0+13,"DUSK "
if ss//white_delay_out= 0 then
if ss != old_ss_white then
W_PWM=W_PWM-1
old_ss_white=ss
endif
endif
if W_PWM = W_min then
White_Day_Cycle = NIGHT
endif
case NIGHT
lcdout $FE,$C0+13,"NIGHT"
W_PWM=W_min
end select
'*******************************************************************************
'do the business of sending pulse to drivers
hpwm 1,W_PWM,200
hpwm 2,B_PWM,200
'*******************************************************************************
'tidy up the display for the current percentage to remove stray zero's
If (B_PWM * 100)/255 = 100 then
lcdout $FE,$80,"BLUES ",dec3 (B_PWM *100)/255,"%"
endif
If (B_PWM * 100)/255 =0 or (B_PWM * 100)/255 <10 then
lcdout $FE,$80,"BLUES ",dec1 (B_PWM *100)/255,"% "
endif
if (B_PWM * 100)/255 >=10 and (B_PWM * 100)/255 <100 then
lcdout $FE,$80,"BLUES ",dec2 (B_PWM *100)/255,"% "
endif
If (W_PWM*100)/255 >= 100 then
lcdout $FE,$C0,"WHITES ",dec3 (W_PWM *100)/255,"%"
endif
If (W_PWM * 100)/255 <=0 or (W_PWM * 100)/255 <10 then
lcdout $FE,$C0,"WHITES ",dec1 (W_PWM *100)/255,"% "
endif
if (W_PWM * 100)/255 >=10 AND (W_PWM * 100)/255 <100 then
lcdout $FE,$C0,"WHITES ",dec2 (W_PWM *100)/255,"% "
endif
'*******************************************************************************
'Get and display the temperature
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
temperature = temperature */ 1600
lcdout $FE,$D4+11,"TEMP ",DEC(temperature / 100),$DF,"C"
GOTO Main
So all I did was to add in a few new variables for the RTC - and modify the line to display the counter to reflect the change of variables. This also works to a fashion, in that the time is displayed correctly and when the logic is met the case changes from NIGHT to DAWN at the correct set time. However the LEDs do not ramp up, and the values for Whites and Blues remain at zero percent. I've done nothing else to the code, certainly not with the case statements or the logic behind them.
Code:
Main:
If SetButton=0 then 'if presed jump to the menu
goto mainmenu
endif
'*******************************************************************************
' check for manual override of the lights
If H_butt = 0 then ' if pressed then change state of varible to 1
Light=1
endif
If light=1 then ' If the variable is 1 then output full PWM to lights
hpwm 1,255,200
hpwm 2,255,200
endif
If light=0 then ' If the variable is low then set value to 0 an turn off the lights
hpwm 1,0,200
hpwm 2,0,200
endif
If M_butt = 0 then ' if pressed then change state of varible back to 0
Light=0
endif
'*******************************************************************************
'clock routine
I2CREAD SDApin,SCLpin,$D0,$01,[RTCMin,RTCHour] ; read DS1307 chip
timeH=(RTCHour>>4) 'convert the BCD format of the hours register and store in variable timeH
timeH=(timeH &$03)*10
timeH=timeH+(RTCHour&$0F)
timeM=(RTCMin>>4)
timeM=(timeM &$07)*10
timeM=timeM+(RTCMin&$0F) 'convert the BCD format of the mins register and store in variable timeM
Counter1 = (TimeH *60)+ TimeM
LCDOut $FE,$D4,#TimeH DIG 1,#TimeH DIG 0,":",#TimeM DIG 1,#TimeM DIG 0
'*******************************************************************************
'check what part of the cycle
If Counter1 < Blue_on_Time then
Blue_day_cycle = NIGHT
endif
if counter1 > blue_on_time and Counter1 > blue_off_Time and B_PWM > B_Min then
Blue_day_cycle = DUSK
endif
if counter1 => blue_on_time and Counter1 < blue_off_Time and B_PWM < B_MAX then
Blue_day_cycle = DAWN
endif
If Counter1< White_on_Time then
White_day_cycle = NIGHT
endif
if counter1 > white_on_time and Counter1 > white_off_Time and W_PWM > W_Min then
White_day_cycle = DUSK
endif
if Counter1 => white_on_time and Counter1 < white_off_Time and W_PWM < W_MAX then
White_day_cycle = DAWN
endif
'*******************************************************************************
'*** Do BLUE daily cycle
select case Blue_Day_Cycle
case DAWN
lcdout $FE,$80+13,"DAWN "
if ss//blue_delay_in = 0 then
if ss != old_ss_blue then
B_PWM=B_PWM+1
old_ss_blue=ss
endif
endif
if B_PWM = b_max then
Blue_Day_Cycle = DAY
endif
case DAY
lcdout $FE,$80+13,"DAY "
if B_max < B_PWM then
B_PWM=B_PWM - 1
endif
if counter1 =blue_off_time then
Blue_day_cycle = DUSK
endif
CASE DUSK
lcdout $FE,$80+13,"DUSK "
if ss//blue_delay_out= 0 then
if ss != old_ss_blue then
B_PWM=B_PWM-1
old_ss_blue=ss
endif
endif
if B_PWM = B_MIN then
Blue_Day_Cycle = NIGHT
endif
case NIGHT
lcdout $FE,$80+13,"NIGHT"
B_PWM=B_min
end select
'*******************************************************************************
'*** Do WHITE daily cycle
select case White_Day_Cycle
case DAWN
lcdout $FE,$C0+13,"DAWN "
if ss//white_delay_in= 0 then
if ss != old_ss_white then
W_PWM = W_PWM+1
old_ss_white=ss
endif
endif
if W_PWM = W_max then
White_Day_Cycle = DAY
endif
case DAY
lcdout $FE,$C0+13,"DAY "
if W_max < W_PWM then
W_PWM=W_PWM - 1
endif
if counter1 =white_off_time then
White_day_cycle = DUSK
endif
CASE DUSK
lcdout $FE,$C0+13,"DUSK "
if ss//white_delay_out= 0 then
if ss != old_ss_white then
W_PWM=W_PWM-1
old_ss_white=ss
endif
endif
if W_PWM = W_min then
White_Day_Cycle = NIGHT
endif
case NIGHT
lcdout $FE,$C0+13,"NIGHT"
W_PWM=W_min
end select
'*******************************************************************************
'do the business of sending pulse to drivers
hpwm 1,W_PWM,200
hpwm 2,B_PWM,200
'*******************************************************************************
'tidy up the display for the current percentage to remove stray zero's
If (B_PWM * 100)/255 = 100 then
lcdout $FE,$80,"BLUES ",dec3 (B_PWM *100)/255,"%"
endif
If (B_PWM * 100)/255 =0 or (B_PWM * 100)/255 <10 then
lcdout $FE,$80,"BLUES ",dec1 (B_PWM *100)/255,"% "
endif
if (B_PWM * 100)/255 >=10 and (B_PWM * 100)/255 <100 then
lcdout $FE,$80,"BLUES ",dec2 (B_PWM *100)/255,"% "
endif
If (W_PWM*100)/255 >= 100 then
lcdout $FE,$C0,"WHITES ",dec3 (W_PWM *100)/255,"%"
endif
If (W_PWM * 100)/255 <=0 or (W_PWM * 100)/255 <10 then
lcdout $FE,$C0,"WHITES ",dec1 (W_PWM *100)/255,"% "
endif
if (W_PWM * 100)/255 >=10 AND (W_PWM * 100)/255 <100 then
lcdout $FE,$C0,"WHITES ",dec2 (W_PWM *100)/255,"% "
endif
'*******************************************************************************
'Get and display the temperature
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
temperature = temperature */ 1600
lcdout $FE,$D4+11,"TEMP ",DEC(temperature / 100),$DF,"C"
GOTO Main
The strange thing is, I have a diagnostics option so on the press of a button I can scroll through all the main variables so I can check that they match what's expected. These are all showing correct values, especially those for the fade in and fade out.
I'm using the HPWM pins on the PIC (18f4520) which are on port C.1 and C.2. But whilst if there was a conflict of hardware that prevented the LEDs lighting, I would still of expected the LCD to show the increase in PWM values given by the fact the variables have values.
Comments please
Bookmarks