**0**

Hello Forum,

I'm struggling to implement a PID controller for my oven. The sampling rate is dictated by the time to read a MAX6675, which is 0.25 seconds to complete a full conversion.

The output should drive a homemade SSR, which using MOC3061 with ZCD. So I can only modulate the number of half sine wave on and off.

As far as my researches I found the AN964, but the parameters are different so I don't get the idea how to convert the 360 degree from that note into 100 pulses per minute in my attempt.

So the Kp, Ki and Kd can be an integer size and then there should be a divider to reduce them into fractional values. But the output should be from 0 to 100, with 250 mS time frame. So I'm puzzled to make the right corrections.

Currently I just implement a proportional method and it seems to be rather enough, as fas as I simulated it.

I should say that the temperature is reduced to one byte, as far as the range is from 40° to 260°C. When it's simulated I can see the oscillation is limited within 3 degrees, but when I trying the thermocouple it comes with a bigger hysteresis, that's why I suppose the PID would give a better solution.Code:Symbol MINTEMP 40 ' minimum temperature level Symbol MAXTEMP 260 ' maximum temperature level Symbol TEMPSPAN MAXTEMP - MINTEMP ' temperature span Clear Result ' forget last state Clear AlarmFlag ' forget The flag If currtemp > Setpoint Then ' when is over the Setpoint If currtemp > TEMPSPAN Then ' may be over the guard limit Btfss no_PID ' when the flag is clear Set AlarmFlag ' it will signalize an error End If Return ' Stop there, return result zeroed End If If no_PID = TRUE Then ' disable the proportional controller Set Result Return End If If currtemp > 0 Then ' whether is higher than minimum temperature _PP2 = currtemp * 100/TEMPSPAN y = currtemp * KPD /Setpoint If ticks >= y.LowByte Then ' the y higher the lesser ticks to stay on Set Result ' let fire the output End If Else ' in case it hasn't got to minimum level Set Result ' let the output to be on. End If EndProc

I found several pages, but all using floating point for the three constant Kp. Ki & Kd. I think I can do similar with integer values as long as using the method to multiply and divide with integers, such is done in that application note.