Hello,
I'm wandering if there is a PWM library that changes the frequency of the PWM signal when a certain dutycycle is reached. This would be usefull for for instance controlling relays or power electronics that you would not want to switch to often and not to short.
This seems like a fairly basic feature but I don't know what searchterm to find it for. Does anyone know of a PWM library that does this?
If it's unclear what I mean in my description, Imagine I have a PID controller controlling my PWM output with a period time of 2 seconds, I don't want my PWM to turn on for less than 0.5 seconds (25% period). If I were to set the output to 12.5% I would want my pwm period time to change to 4s and be on for 0.5 seconds to still have the 12.5% dutycycle.
PWM is a digital signal that conveys an analog quantity: 0% to 100%. We want the frequency of this signal to be constant so that the receiver can just measure the time that the pulse is HIGH.
Maybe I need to be more clear about what i'm trying to achieve. I have an oven for burning out plaster for metal casting, this oven has to go to 800degrees c at the highest temperature so the heating element is very powerfull. 2kw in my case.
I'm controlling the oven via PWM and a relay that is in series with the heating element.
The PWM signal is controlled via a PID controller, period of the PWM is set to 2 seconds (So a frequency of 0.5hz). Relays as you probably know have a minimum on time of 0.25 to 0.5s. Which means i have a minimal dutycycle of 0.5 seconds or 25%. I can't set the minimum dutycyle to 25% because then the oven will reach 400-500 degrees c in this state. So I would want to increase deadtime between the 0.5s on pulses to still regulate my PWM. (So regulating and increasing deadtime after the 25% dutycycle(0.5s on time) at 0.5hz is reached.)
It seems this is not a feature supported by PWM libraries (If someone knows one please let me know!)
For now I will just go to 0% PWM under 12.5% dutycycle my PID regulates and to 25% dutycycle for everything in between 12.5 and 25%.
You just need to switch the relay off and on with a home made function using millis. It is not PWM. It seems a bad idea as your relay will die pretty quickly I would expect and with a standard inductive heating element the off and on does not need to be rapid to maintain a temperature
Presumably you have a thermometer in the system and your application does not sound like it needs 0.1degree centigrade accuracy so make a simple function which turns the element on until temperature is reached and then turns off until a hysteresis point is reached, say temp minus 5C. You can build some complexity into the code to prevent overshoot by starting a slow down cycle when approaching set temp.
If you replace your mechanical relay with a suitable zero-cross type SSR, you'll get much finer control of your power (½ cycle) which is 16.7 or 20 ms depending on the line frequency (60 or 50 Hz).
This can be further improved to finer control of temperature by using a function that improves the temerature regulation within each ½ cycle period.
Now with your software PWM set to 2000 ms, you can set the duty (on-period) from 0-2000 ms in 1 ms steps for fine temperature control using PID.
Yeah... You can make your own timers similar to the Blink Example or Bink Without Delay Example. And, you probably don't need to switch on or off more than once per second. You might have to wait several seconds before getting a significant or measurable temperature change.
Does your controller read the temperature?
Since temperature can't change instantly, typically heating & cooling systems simply switch on off to maintain constant temperature... Turn on when below 800 degrees and off when above 800 degrees. Temperature ramping works the same way with the target-temperature ramped.
In the real world there is usually some hysteresis, i.e. turning on at 799 degrees and off at 801 degrees, etc., to prevent relay "chatter".