Hi,
I need a low frequency PWM signal (50 Hz) on the Due.
Does it make more sense to set the PWM frequency on the corresponding pin (found a sample somewhere in the forum on how to do that) or switch the pin "manually" on and off via digital i/o?
Is it correct that generating the PWM signal via analogWrite() does not use processor cycles and thus should be more efficient?
Thanks for any hints!
Juergen
It's not just "efficiency", it's also accuracy... If it comes time to send-out a pulse and your program is doing something else, the pulse will be delayed until your program gets-around to checking if it's time for a pulse.
If your program isn't doing much else it shouldn't make much difference, especially at 50Hz which is slow compared to the CPU clock.
I need a low frequency PWM signal (50 Hz) on the Due.
You are not trying to use it to trigger a Triac or SCR are you? If you are you need to synchronise it to the mains and that means using the PWM mechanism is not the way to do it.
Or, If your 50Hz PWM signal is for servo control, use the Servo library.
Thanks for the replies!
In fact I want to use it for a SolidStateRelais (with ZCC) driving a heating element. Thought that should be no problem...
What does it mean "synchronize it to the mains" and why not use PWM for it then?
Juergen
To avoid RFI, you need to get the phase relationship between the mains and the switching waveform correct; simply matching frequency is not sufficient.
thought that would be no problem due to the ZCC in the SSR. No...?
Thought that should be no problem..
Yes it is a problem. Depending on what sort of solid state relay you have, some have a zero crossing detector and others don't.
Either way a SSR will turn on when you give it a trigger and will not turn off until the mains cycle reaches zero. Therefore once on there is nothing you can do to turn it off.
This means if you just feed PWM into the gate it will turn on immediately but if the PWM signal is not synchronised to the mains frequency the two beat and drift together and the result is the device turns on and off for a random period of the cycle every cycle. If this were a light it would look to flicker and flash rapidly at times and other times slowly.
There is no way I know of synchronising the PWM mechanism to the mains frequency.
What does it mean "synchronize it to the mains"
It means that the PWM signal is not only the same frequency as the mains but that it is in a fixed phase relationship with it. For example that the PWM always goes high at the exact instant of a positive going zero crossing.
Using PWM like this ( if it were possible ) is known as phase angle control. Fortunately for a heater you do not need anything like this. The thermal time constant of the system means you only need turn it on and off with a duty cycle of a few seconds. So you could use PWM signal providing that:-
- It was a very very low frequency with a period of say 5 seconds. ( you can't use the normal PWM mechanism to do this because the divider ratios will not go that high ).
- You have a zero crossing SSR.
Ok, I think now I understood. Thanks for the explanation!
Actually I have a zero crossing SSR (S202 S02). If I understand correctly, the main point is, that due to the zero crossing circuit and the random shift if causes to the "on" phase, I would have very inexact results. If the frequency was much lower, I could ignore the inaccuracy. Somewhat right?
So the consequence is, I will use digital i/o and switch with a frequency of 5, 10 or 20 seconds. This should be ok?!