PID Control 127V 1200W oven resistance with a PWM signal from ESP32

Thread Starter

carlosmiguelf98

Joined Oct 9, 2023
5
This is my degree final project, I am building a remotely controlled oven using an ESP32 wifi connection. The pid control part and the app for sending and recieving information is done and working. But im heaving trouble switching the resistance with the PWM signal.

First I was told to use this circuit for the triac switching:
1697546703981.png
(Carga means LOAD in portuguese)
But it doesnt worked, so I started searching and around the forums and there is a lot of conflicting information about this subject, some say a i need to use a zero-detecting circuit, some say I dont, some say this is not useful and I can use a SSR.

I want to know what it would be the easiest way to implement this PID control with areasonable precision.
Thanks
 

crutschow

Joined Mar 14, 2008
38,462
im heaving trouble switching the resistance with the PWM signal.
What is the nature of your PWM signal?
With using a TRAC for AC control of a heater, the PWM frequency is low with the duty-cycle being ON for one or more AC cycles, and then OFF for one or more AC cycles (thus the maximum PWM frequency would be no more than a few HZ).
For that a zero-crossing circuit is typically used to minimize EMI and reduce stress on the TRIAC.
 

Jerry-Hat-Trick

Joined Aug 31, 2022
815
Maybe check out the Microchip application note https://www.microchip.com/en-us/application-notes/an958 ?

I question whether PID control is really necessary here. Seeing the problem more as a state machine, or fuzzy logic might be better. There can be a significant lag between turning the heater element on and off and measuring temperature. You may find that simply turning the heater fully on or fully off will actually get a better result. So for various target temperatures, by how much does it overshoot if you turn the heater off when it reaches temperature and how much does it overshoot when approaching a lower temperature. Turning it on and off a little early should allow the temperature to reach the target.

And at a given temperature what mark/space time is necessary to hold that temperature. You need to make it adaptive with lookup tables for various temperatures and to self tune, for example if it's just heating air or if there is something with significant thermal mass in the oven. Your PWM frequency can be really quite low, possibly a fraction of one second - similar to mechanical with hysteresis. In summary, it's not a linear system and PID, whilst fashionably still quoted in temperature control devices, is not really the right approach.

There will be others on this site who can probably explain this better, or point out the error of my ways!
 

Thread Starter

carlosmiguelf98

Joined Oct 9, 2023
5
I
What is the nature of your PWM signal?
With using a TRAC for AC control of a heater, the PWM frequency is low with the duty-cycle being ON for one or more AC cycles, and then OFF for one or more AC cycles (thus the maximum PWM frequency would be no more than a few HZ).
For that a zero-crossing circuit is typically used to minimize EMI and reduce stress on the TRIAC.
I can adjust the frequency of the pwm signal, if the tension from the line is 127v 60hz what would be a good pwm frequency to work with?
 

Thread Starter

carlosmiguelf98

Joined Oct 9, 2023
5
Maybe check out the Microchip application note https://www.microchip.com/en-us/application-notes/an958 ?

I question whether PID control is really necessary here. Seeing the problem more as a state machine, or fuzzy logic might be better. There can be a significant lag between turning the heater element on and off and measuring temperature. You may find that simply turning the heater fully on or fully off will actually get a better result. So for various target temperatures, by how much does it overshoot if you turn the heater off when it reaches temperature and how much does it overshoot when approaching a lower temperature. Turning it on and off a little early should allow the temperature to reach the target.

And at a given temperature what mark/space time is necessary to hold that temperature. You need to make it adaptive with lookup tables for various temperatures and to self tune, for example if it's just heating air or if there is something with significant thermal mass in the oven. Your PWM frequency can be really quite low, possibly a fraction of one second - similar to mechanical with hysteresis. In summary, it's not a linear system and PID, whilst fashionably still quoted in temperature control devices, is not really the right approach.

There will be others on this site who can probably explain this better, or point out the error of my ways!
I understand that using PID is probably not the best approach for this, and I can use a SSR just to turn ON and OFF at max power. But the project requires that I use PID
 

Jerry-Hat-Trick

Joined Aug 31, 2022
815
I can adjust the frequency of the pwm signal, if the tension from the line is 127v 60hz what would be a good pwm frequency to work with?
When below target temperature, turn it permantly on to get to target quickly, turning off just before you reach the temperature to prevent overshoot. Leave it off when target is a lower temperature. For holding temperature try one cycle on, five cycles off and increase or decrease the off cycles based on whether the temperature goes up or down. Save the changes in a lookup table. Use the rate of increase of temperature with heater on and the rate of decrease when heater is off to adjust for the actual thermal mass of the oven contents

Sorry, I just read your last post about having to used PID. Sorry if this is a bit blunt, but I'm not impressed by teaching staff who set tasks for using PID when it's not appropriate - especially as you are using a really powerful processor. It might make sense if you bin the processor and use an analogue approach.

If you make your Proportional term max out at a fairly small temperature error and make the Differential term as small as possible with the Integral term being the main variable maybe they'll be happy with that. I still think the on/off aproach I suggest in this post is okay, it's not a fixed PWM frequency with variable mark/space, it's a variable frrequency with fixed mark, variable space
 
Last edited:

crutschow

Joined Mar 14, 2008
38,462
I can adjust the frequency of the pwm signal, if the tension from the line is 127v 60hz what would be a good pwm frequency to work with?
Depends somewhat on the minimum duty-cycle.
For example, for a 10% minimum duty-cycle there would be 1 cycle ON and 9 cycles OFF, so that would require a PWM frequency of no higher that 60/10 = 6Hz.
To insure that you always get at least one cycle for that scenario, it probably should be no higher than 3Hz, unless the PWM signal is synchronized with the 60Hz.
If the oven has a high thermal time-constant, then you could use a PWM signal period of more than 1 second (less than 1 Hz).
 

Thread Starter

carlosmiguelf98

Joined Oct 9, 2023
5
Depends somewhat on the minimum duty-cycle.
For example, for a 10% minimum duty-cycle there would be 1 cycle ON and 9 cycles OFF, so that would require a PWM frequency of no higher that 60/10 = 6Hz.
To insure that you always get at least one cycle for that scenario, it probably should be no higher than 3Hz, unless the PWM signal is synchronized with the 60Hz.
If the oven has a high thermal time-constant, then you could use a PWM signal period of more than 1 second (less than 1 Hz).
I'll try to use 1hz because it's easy to implement, if necessary I'll try with a lower frequency, thanks.
 
Top