5 Replies Latest reply on Jul 28, 2016 10:46 PM by xbolshe

    How to change the polarity of PWM signal?

    Oliverleure

      Hi Makers,

       

      I'm successfully using PWM signals on Galileo Gen2, but I cannot figure out how to change the polarity of the signal?

      As per documentation I have found so far,

      (in /sys/class/pwm/pwmchip0/pwm1/ folder) polarity - Changes the polarity of the PWM signal (read/write).Writes to this property only work if the PWM chip supports changing the polarity. The polarity can only be changed if the PWM is not enabled. Value is the string "normal" or "inversed".

       

      So I have tried:

      echo "normal" /sys/class/pwm/pwmchip0/pwm1/polarity

      or

      echo "inversed" /sys/class/pwm/pwmchip0/pwm1/polarity

       

      And I get the following error: -sh: echo: write error: Function not implemented

       

      So my question is: Does the PWM chip support changing the polarity? If yes, how to do that? If no, is there a work arround?

       

      Thanks for your help on that Guys,

       

      Olivier

        • 1. Re: How to change the polarity of PWM signal?
          xbolshe

          Hi,

           

          yes, PWM chip PCA9685 used in Galileo Gen2 supports a polarity inversion.

          As I see PWM driver (kernel module for Gen2) does not support this feature.

          Need to rewrite a kernel PWM driver to enable a polarity inversion.

           

          BR,

          xbolshe

          2 of 2 people found this helpful
          • 2. Re: How to change the polarity of PWM signal?
            FGT

            Hi Oliverleure,

             

            Just curious: why do you need to invert the polarity? Isn't it enough to "invert" duty cycle?

             

            Fernando.

            • 3. Re: How to change the polarity of PWM signal?
              Oliverleure

              Hi Fernando,

               

              I want to be able to change the direction of a DC motor. Inverting the duty cycle would work but apparently the driver doesn't support it.

               

              Olivier

              • 4. Re: How to change the polarity of PWM signal?
                FGT

                Hi Olivier,

                 

                I tought your problem was solved, because the question is marked as "answered"... please "unmark" it if not.

                 

                Oliverleure wrote:

                 

                Hi Fernando,

                 

                I want to be able to change the direction of a DC motor. Inverting the duty cycle would work but apparently the driver doesn't support it.

                 

                I see... I've made it relatively simple, what did you mean by "PWM chip" in your original post

                 

                Does the PWM chip support changing the polarity?

                 

                Did you mean the PCA9685 referred to by xbolshe? I know nothing about that chip and/or its usage. It does not seem to be related to DC motors according to

                PCA9685|NXP

                www.nxp.com/documents/data_sheet/PCA9685.pdf

                but again, I do not know the PCA9685.

                 

                Anoyhow, I've always used some H-bridge, such as L9110S or L293D for controlling DC motors... I use them in an Arduino controlled car (Proyecto con Galileo  - Intel Galileo - Arduino Car - YouTube ). I've not used them in an Intel Galileo, but it should be the same. If you think it would be useful I could make some experiments and report back.

                 

                HTH,

                 

                Fernando.

                 

                 

                 

                • 5. Re: How to change the polarity of PWM signal?
                  xbolshe

                  Hi,

                   

                  need to speak about a logic inversion, not a voltage inversion in case of PCA9685.

                  •INVRT bit (MODE2 register) can be used to keep the LED PWM control firmware the

                  same independently of the type of external driver. This bit allows LED output polarity inversion/non-inversion only when OE=0

                   

                  invert.png

                   

                  A voltage inversion requires to use external drivers for Galileo Gen2 board.

                   

                  From Kernel documentation:

                  https://www.kernel.org/doc/Documentation/pwm.txt

                   

                  polarity - Changes the polarity of the PWM signal (read/write).

                  Writes to this property only work if the PWM chip supports changing

                  the polarity. The polarity can only be changed if the PWM is not

                  enabled. Value is the string "normal" or "inversed".

                   

                  When implementing polarity support in a PWM driver, make sure to respect the

                  signal conventions in the PWM framework. By definition, normal polarity

                  characterizes a signal starts high for the duration of the duty cycle and

                  goes low for the remainder of the period. Conversely, a signal with inversed

                  polarity starts low for the duration of the duty cycle and goes high for the

                  remainder of the period.

                  BR,

                  xbolshe