Hi, I want to control an oven with a pic.
I basicaly have build the oven, including the temp-sensing with a NTC.
The oven will be used for making SMD PCB's.
Therefor it has to follow a temperature profile in time.
I want to do this with a PID-controller.
I calculated the PID parameters (gain, I, D) by the step response.

I also tried to build the PID algorithm.
Only, in case of overshoot, I will have a negative error (wish temp minus real temp).
I wrote a routine to handle negative values; to multiply and subtract negative values (see below).
As this is quite complex, does anyone know if there is a more simple (faster) method to implement a PID for this application?

code;
AminB: '*** PROCEDURE A - B ***
tekA=NCD(A)
tekB=NCD(B)
IF (tekA = 16 AND tekB = 16) OR (tekA <>16 AND tekB<>16) Then 'check if A and B have same sign
abswaardeAminB = ABS(A-B)
IF tekA = 16 Then
IF NCD(A-B) = 16 Then
tekAminB = 16
Else
tekAminB = 0
EndIF
Else
tekAminB = NCD(A-B)
EndIF
Else
abswaardeAminB = ABS(A) + ABS(B)
IF NCD(A-B) = 16 Then
tekAminB = 16
Else
tekAminB = 0
EndIF
EndIF
'assembly of the value
IF tekAminB = 16 Then
C= 0 - abswaardeAminB 'negative word
Else
C = abswaardeAminB
EndIF
Return

AmaalB: '*** AmaalB ***
IF NCD(A) = 16 XOR NCD(B) = 16 Then
C = ABS(A) * ABS(B)
C = 0 - C
Else
C = ABS(A) * ABS(B)
EndIF
Return

regelkring:
errlastlast = errlast
errlast = err
err = wenswaarde - adval2 'wish temp minus real temp
A = 2
B = errlast
GoSub AmaalB
A = C
B = errlastlast
GoSub AminB
A = err
B = C
GoSub AminB
B = C
A = D100 'd*100
GoSub AmaalB
DTERM = C
A = I100 'I*100
B = err
GoSub AmaalB
A = C 'ITerm
B = 0 - DTERM
GoSub AminB
ID = C 'IDterm
A = err
B = errlast
GoSub AminB 'C bevat Pterm
A = 100
B = C
GoSub AmaalB
A = C
B= 0 - ID
GoSub AminB 'P + ID = PID
A = gain10 'gain * 10
B = C
GoTo AmaalB
IF NCD(C) = 16 Then
C = ABS(c)/1000 'PID term
C = 0 - C
Else
C = C / 1000
EndIF
A = duty
B = 0 - C
GoSub AminB
duty = C
IF duty > 100 AND NCD(duty)<>16 Then duty = 100
IF NCD(duty) = 16 Then duty = 0

Return