I'm trying to make my own PID temperature controller using Arduino. Arduino PID library outputs a PWM signal. I need to control 230VAC using this PWM like a triac phase angle controlling. If I use a triac phase angle method, I have to dedicate lot of processing power for zero-crossing detection for interrupt.

Is their any alternating way to do this?

  • 1
    \$\begingroup\$ You could just send the PWM to a non-zero crossing opto-coupler which drives a triac. Trying to synchronize your code to it would be tricky, as for 60 HZ you have a zero crossing every 8.08 mS, and 10 mS if 50 HZ power. \$\endgroup\$ – Sparky256 Aug 30 '18 at 6:07
  • 2
    \$\begingroup\$ Is there a good reason why your thermal mass can't be handled with an integral number of half-cycles of power? The MOC3063, for example, has built-in zero-cross detection. You'd just control it as on/off control with your software based upon the measured temperature and your PID algorithm. No PWM involved. If you absolutely MUST have PWM, could you explain why? (I did this for a small thermal mass used in what amounts to an electronic cigarette device wired to mains. For that I continually adjusted an MSP430 DCO, via PID, to sync a fixed number of MCU cycles between each mains cycle. Harder.) \$\endgroup\$ – jonk Aug 30 '18 at 6:22
  • \$\begingroup\$ @jonk The Arduino PID library outputs a PWM signal.That's why PWM is needed. Anyway, on/off controlling is better like some industrial temparature controllers. But, How can I manage it with output PWM signal from PID library?Can you explain? \$\endgroup\$ – user_fs10 Aug 30 '18 at 11:51
  • 1
    \$\begingroup\$ @NSiri Okay. So I'll assume you are using library code that provides the PID and only PWM output. Can you set the PWM frequency? (The PWM duty cycle will be the PID output, I assume.) For example, can you set the PWM frequency to be 5 Hz? \$\endgroup\$ – jonk Aug 30 '18 at 21:18
  • \$\begingroup\$ @jonk PWM frequency changing is much more complicated as I think. As you said before I decided to use time proportional control method. But problem is on/off controlling is worked until PID output reach to maximum value(TimeWindow value) after reaching the maximum value relay Output remaining off. Temperature is below setpoint. do you know any reason for that? \$\endgroup\$ – user_fs10 Aug 31 '18 at 7:15

Your application here uses PWM as the output from a PID library routine, I gather. If possible, your PWM period (inverse of frequency, of course) should be the same as the temperature sampling period.

Your sampling period should be as rock-solid repeatable as you can make it; with shorter sampling times being usually better, too. However, variability in temperature sampling translates immediately into poorer performance of the PID, so keep the repeatable nature of the sampling time to below about (in my book) 1:1000 or 0.1%, if possible. This means that if you sample temperature once per second, you want to make sure that you do so down to less than 1 millisecond of variation between samples and, hopefully, as close to zero drift over time as possible, too.

Only when your thermal mass is extremely small and your process is very fast should you consider using phase-angle firing -- because you have little choice about it, then. So in this case, with \$50\:\text{Hz}\$ mains AC say, you should be sampling temperature perhaps at \$100\:\text{Hz}\$ (once per half-cycle.) You'd then apply phase-angle firing and operate your PWM period to match your half-cycle temperature sampling period (also \$100\:\text{Hz}\$ with the PWM duty cycle determining the firing angle where "100%" would mean an immediate trigger going to the MOC3023 [which doesn't have a zero-cross circuit in it] and where "0%" would mean no trigger during that half-cycle.)

For slower thermal mass, which is far more likely I suspect, the PWM period can and should be much longer. Here, you absolutely do want to avoid phase-angle firing to avoid nasty levels of system noise. Here, you will want zero-cross firing that you get with the MOC3063, instead.

For zero-cross firing, the duty-cycle value technically should be an integer multiple of your AC half-cycle period. However, in your case using a library, you may not have any control over that. Instead, the PWM duty cycle duration may be near, but not exactly at, two different integer multiples of the AC half-cycles. This can be a problem, depending on how closely you need to control the temperature and how you set up your PID control parameters.

You could consider improving this integer multiple problem by applying a digital differential analysis, used to adjust each successive actual duty cycle such that the overall average over some successive grouping of them yields the PWM duty cycle average you want to achieve. This helps avoid degrading long-term precision. But I don't know if your library supports this. So that's just another issue to consider, but not necessarily a solution you can implement here.

You have specified very little about exactly what you are trying to achieve. I don't even know the frequency of your mains supply, for example, because you haven't said anything about it. Nor have you specified anything about your thermal mass or, really, anything much else. So this is all that I can offer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.