Hello,
The code below was used in an incubator. The user could set the mean temperature and the range. The day was divided into 96 fifteen minute segments and at 6 AM and 6 PM the temperature was set to the user commanded mean temperature. the "range" is a sinusoidal function that adds or subtracts from the mean. For example a mean of 24 with a range of 10 would cause the incubator to be at 24 degrees at 6 AM and 6 PM. At noon the temperature would be 24 + 10 = 34 and at midnight the temperature would be 24 - 10 = 14 Celsius.
CalculateSetPoint:
read 0, meantemp
read 1, range
' SetPoint = 10* (meantemp + range * sine (timeslot * 255/96)) with allowances
' for the sign and integer truncation plus an 18 hour time shift.
w = (255 * timeslot/96) ' 0 to 255 in 2.667 chunks
b = sin w ' 0 to 127 in 2's complement
if b.7 = 1 then negative
positive:
x = 10*meantemp + (20*b*range/255)
goto timeslotdone
negative:
b = (b ^ %11111111) + 1 ' 2's complement to unsigned integer
x = 10*meantemp - (20*b*range/255)
TimeSlotDone:
setpoint = x
HTH
BrianT
Bookmarks