GPIOMods: more than one SoftPWM function block in one project

18 hours ago
  • scan

    scan - 2020-07-07


    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

    • Ingo

      Ingo - 2020-07-07

      Hi Andreas!
      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.


  • scan

    scan - 2020-07-08

    Hi Ingo,

    thanks for your quick response.

    I have a Raspberry Pi 4 (4GB), Codesys V3.5 SP16 and Codesys Runtime V3.5.16.0.
    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.
    BR Andreas

    • Ingo

      Ingo - 2020-07-08

      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 less than 1kHz!?

  • scan

    scan - 2020-07-08

    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.

    BR Andreas

    • Ingo

      Ingo - 2020-07-08

      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.


      Last edit: Ingo 2020-07-08
  • scan

    scan - 2020-07-09

    Thanks Ingo!
    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.

    BR Andreas

    • Ingo

      Ingo - 2020-07-09

      A pity!
      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.