in my recent project i am using the SoftPWM function block from the GPIOMods library.
Using only one SoftPWM is working fine, but i need 4 of them in one project parallel for 4 GPIO pins, and that is not working properly.
I put every function block in a separate task with high priority, but the PWM signal on the GPIO pin is not as it should be.
I recognized, that the Jitter of these tasks is extremely high (about 250000 µs).
Is there any way that i can use more than one function block while working properly?
Thanks and best regards
Talk Topic about project #gpio-mod
Nice to hear about your interest! 😉
Sounds like you did everything as intended. While the interpretation of the jitter might be wrong. Because the jitter calculation can't be done correctly, as the FB is changing the cycle time permanently.
So it would be first interesting to hear how the error shows. And if it ocours already with two PWM tasks, three or four.
thanks for your quick response.
I have a Raspberry Pi 4 (4GB), Codesys V3.5 SP16 and Codesys Runtime V220.127.116.11.
The 4 different PWM signals (range: 0...5000 Hz) should be on the GPIO pins 12, 13, 18 and 19.
If there is just one Task with one SoftPWM function block in it, it works perfectly (for example see oscilloscope picture "001": PWM signal with 4225 Hz).
But if I just add an additional task for the second SoftPWM function block, the signal of both SoftPWMs is not okay (see oscilloscope picture "002": should be 4225 Hz, but it is just an unstable signal with approx. 1 Hz).
And all the 4 SoftPWM function blocks cannot be in one task, because then they will all have the same frequency.
Thanks for your help.
Wow! That's bad! ;)
I can't explain why it can turn this bad. But it would be great if you could do a short test by reducing the frequency. Because 4kHz means that I have to schedule the task twice within 200us. That is tough for one task, but I believe it can stress the system with more than one.
But my expectation was, that your frequency would decrees slightly in this case, and not that it falls down to 1Hz.
But, what is if you try it with s.th. less than 1kHz!?
Sure, 5kHz is maybe not easy to generate, but at lower frequencies the problem still exists. I tried for example 5Hz, but it's still an unstable 1Hz signal.
I recognized, that just creating the second task for the PWM program creates problems, even if in this task is no program running.
I already tried different task cycle times from 100us up to 10ms. It changes a little the behavior of the signal, but still at about 1Hz and unstable.
To me it doesn't look like a generic issue. I did a test without hardware on a Linux PC (see attached screenshot).
This looks good. I'll also attach you the test project.
I uploaded your example project to my raspberry, but the problem still exists.
The traces are correct, but on the GPIO pins it's not working properly.
I am now trying to solve the problem by programming the PWM signal in a separate phyton program. It should be possible to access the variables of the plc program.
Sounds like the driver has a problem then. Then it doesn't like the usage
of the driver from different tasks. I'll file a bug for that.
Sorry, that it didn't work that easily!
Log in to post a comment.