#### greencardigan

##### Senior Member

Currently I roast coffee beans in a hot air type popcorn maker but the roast times are to quick due to lack of temperature control.

I have seen PID controllers on ebay but cant justify the cost of using these for a $20 popcorn maker.

So, is it possible/worthwhile to implement a PICAXE PID system to control the heating element in the popcorn maker?

Expected temps are in the range of 10 deg C to 250 deg C.

Not sure what kind of sensor I'd need? K-type thermocouple?

A few limitations I only have experience with 08Ms atm. Needs to be cheap.

I've looked at a few bit of PID code here (thanks BeanieBots) and have whacked the following code together. The tuning parameters used are arbitrary atm as I dont have a physical system to test it on yet.

Just wondering if I am on the right track with respect to the code and the project in general.

symbol Kp = 500 'proportional factor

symbol Ki = 11 'integral factor

symbol Kd = 10 'derivative factor

symbol dt = 3

symbol pt = b0 'previous temp

symbol t = b1 'measured temp

symbol sp = b2 'set point

symbol e = b3 'error

symbol pe = b4 'previous error

symbol PID = w3

sp = 150

PID = 32768

do

pt = t

readadc 4,t

pe = e

if t <= sp then 'for negative errors

e = sp - t

w4 = Ki * e * dt max 500 'INTEGRAL..........................

PID = PID + w4 max 52768

w4 = Kp * e max 12000 'PROPORTIONAL......................

PID = PID + w4 max 52768

else 'for positive errors

e = t - sp

w4 = Ki * e * dt max 500 'INTEGRAL.........................

PID = PID - w4 min 32400

w4 = Kp * e max 12000 'PROPORTIONAL....................

PID = PID - w4 min 12768

endif

if t > pt then 'temp increasing

w4 = t - pt

w4 = w4 * Kd max 10000 'DERIVATIVE ......................

PID = PID - w4

elseif t < pt then 'temp decreasing

w4 = pt - t

w4 = w4 * Kd max 10000 'DERIVATIVE ......................

PID = PID + w4 max 52768

else

w4 = 0 'no derivative part

endif

if PID <= 32678 then

output = 0

else

output = PID - 32678

output = output / 200

endif

pause 500

loop