OK I've re-written the code to use the multiple spwm routine produced by DT, but still can't get the delay working right.
This is the routine that calculates the fade (or pause duration) for the dutycycle
Code:
Fade:
Vb_1 = ((B_Day_On_H - B_Dawn_On_H)*60) ' difference between day start and dawn start hour, converted to min
Vb_2 = (B_Day_On_M - B_Dawn_On_M) ' difference between day start and dawn start mins
Vb_5 = (Vb_1+Vb_2)*60 ' Get total duration time in seconds
Vb_6 = B_Max - B_Min ' Work out the 'distance' the lights go from min to max
B_Fadein_Time = Vb_5 / Vb_6 ' Get number of seconds between each PWM pulse
Setting the dusk start time to 8:00 and the day on time to 8:05 I get the following results for the variables (B_Min = 0 and B_Max = 255) on the LCD
Vb_5 = 600
Vb_6 = 255
B_Fadein_time = 2
I then have the following statement which should increment the duty cycle until it reaches 255, with each cycle paused 2 seconds
Code:
case DAWN
lcdout $FE,$94,"BLUE: DAWN "
DutyCycle1 = DutyCycle1 +1
pause B_Fadein_Time
if DutyCycle1=B_Max then
Blue_Day_Cycle = DAY
endif
However when run the duty cycle cycles from 0 to 255 so fast you can hardly notice it. Right, so the pause 2 statement is going to be too low, as pause 1000 equates to 1 second, so I multiplied the result by 1000 - the net result was too slow, it never reached 255 by the time the 5 minutes were up. Doing the maths I need to divide 600 seconds by 255 steps = 2.352941176470588. So I really need to convert this to a manageable number, say 2.353. ( B_Fadein_time is a word variable so should be able to store that result), and then convert this into seconds to use in the delay loop, but in a way that actually works !
Assistance would be appeciated
Bookmarks