Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

GPIOMods: more than one SoftPWM function block in one project

scan
2020-07-07
1 day ago
  • scan

    scan - 2020-07-07

    Hello,

    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
    Andreas


    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.

      Cheers,
      Ingo

       
  • 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 s.th. 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.

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

      Cheers,
      Ingo

       
      πŸ‘
      1
  • bernie-bbq

    bernie-bbq - 2021-01-03

    Hi, I do not understand how to install / run /setup the SoftPWM function block on my Codesys v3.5 SP16 Patch 2 (64-bit) with a RPI 2. Can anyone point me in the right direction ? Thx

     
    • Ingo

      Ingo - 2021-01-03

      In general:

      • define a high priority task
      • call the FB there
      • map the digital output of the FB to a GPIO output

      That's it πŸ˜‰

      But as you might have read this thread, it seems to only work with one
      output. Seems like the GPIO driver has problems with multiple outputs.

       
      • bernie-bbq

        bernie-bbq - 2021-01-04

        Hi, I am a real newbie at this ... I have spent weeks getting the RTU
        modbus working, now I just need to get the PWM working so I can use that
        signal to obtain a 4-20mA signal to drive a triac on my solar power
        diverter (the engineering side is easy... but I struggle with the software).

        Codesys highlights the problems I have, missing licences & and an identity
        problem with SoftPWM I suspect. I think the problem may be obvious to you
        ... but it certainly is not obvious to me where /how I get the missing bits
        :) I would greatly appreciate your further assistance if you can make the
        time. Thx. Bernard

        [image: image.png]
        [image: image.png]

        On Sun, 3 Jan 2021 at 22:19, Ingo forge@codesys.com wrote:

        In general:

        • define a high priority task
        • call the FB there
        • map the digital output of the FB to a GPIO output

        That's it πŸ˜‰

        But as you might have read this thread, it seems to only work with one
        output. Seems like the GPIO driver has problems with multiple outputs.


        GPIOMods: more than one SoftPWM function block in one project
        https://forge.codesys.com/forge/talk/forge/thread/6ceff9d39e/?limit=25#72d2/37d2


        Sent from forge.codesys.com because you indicated interest in
        https://forge.codesys.com/forge/talk/forge/

        To unsubscribe from further messages, please visit
        https://forge.codesys.com/auth/subscriptions/

         
        • Ingo

          Ingo - 2021-01-04

          OK, then you should give us an explaination of your problem first.
          Currently I only know, that you have problems. But I don't know which.

          • explain what you did
          • explain what doesn't work as expected
          • give us the error messages, if there were some
          • ...
           
          • bernie-bbq

            bernie-bbq - 2021-01-06

            Hi,

            Thx for your time but I have decided to simplify the software side and
            design an electronic interface for the 4-20 mA signal. I will use 4 digital
            I/O outputs to drive 4 constant current sources (1mA) (2mA)(4mA) (16mA)
            utilising opto-couplers for voltage isolation. These I will then combine to
            give me a 4-20mA output with a 1 mA resolution which is more than
            satisfactory for my application. I will select the combination of outputs
            required from simple logic on the PLC side. In fact, this will probably
            result in a better & more robust result than utilising a PWM as my initial
            driver. As I am driving a hot water element, PID type motion control is
            simply not required.

            Thx again for your support / time

            Regards

            Bernard

            PS As soon as I tried adding the functional blocks (comparators) to the
            previous software the PLC 'Build' request called up missing Libraries ...
            as a hobbyist I do not want to spend money on additional Libraries
            licences when I may not have the skill to utilise them anyway. I will
            simply stick to what I do best ... electronics & power engineering with
            simple PLC logic.

            On Mon, 4 Jan 2021 at 20:04, Ingo forge@codesys.com wrote:

            OK, then you should give us an explaination of your problem first.
            Currently I only know, that you have problems. But I don't know which.

            • explain what you did
            • explain what doesn't work as expected
            • give us the error messages, if there were some
            • ...

            GPIOMods: more than one SoftPWM function block in one project
            https://forge.codesys.com/forge/talk/forge/thread/6ceff9d39e/?limit=25#72d2/37d2/48e6/caf7


            Sent from forge.codesys.com because you indicated interest in
            https://forge.codesys.com/forge/talk/forge/

            To unsubscribe from further messages, please visit
            https://forge.codesys.com/auth/subscriptions/

             

Log in to post a comment.