8 Replies Latest reply on Mar 10, 2014 12:52 AM by yuanpu

    Activate PWM signals from Linux command line

    Pablo_ESP

      Hello, I trying to activate PWM signals from linux command line, but I can't. I explain that I do. For example, to activate PWM of PIN3.

      I make sure I mux the pin is output, and has the value "1"

       

      root@clanton:/sys/class/gpio/gpio30# cat direction

      out

      root@clanton:/sys/class/gpio/gpio30# cat value

      1

       

      now, I configure the PWM3

       

      root@clanton:/sys/class/pwm/pwmchip0/pwm3# echo -n "1" > enable

      root@clanton:/sys/class/pwm/pwmchip0/pwm3# echo -n "1000000" > period

      root@clanton:/sys/class/pwm/pwmchip0/pwm3# echo -n "333000" > duty_cycle

       

      but not work..... any sugestion?

       

      The linux versión that I use is the SD version.

       

      Thanks in advance

        • 1. Re: Activate PWM signals from Linux command line
          Intel_Jesus

          Hi Pablo_ESP,

           

          In the Galileo Release Notes: https://communities.intel.com/docs/DOC-21837

          Page 9, Section 1.7.12

          It shows the Arduino pin and Cypress PWM port.

          Pin3: GPORT0_BIT4_PWM7

           

          Now take a look at the IO Mapping: https://communities.intel.com/docs/DOC-21920

          It shows that  GPORT0_BIT4_PWM7 is Linux GPIO ID 20.

           

          Try using gpio20 instead of gpio30 that might be the issue.

           

          Regards,

          Intel_JEspinoza

           

          • 2. Re: Activate PWM signals from Linux command line
            Pablo_ESP

            Hello Intel_jEspinoza, still not working. In the IO Mapping Document, the Arduino IDE ID column corresponds to the pins of Arduino? because IO3 is GPORT0_BIT2_PWM3, but can not find the port in the table of MUX ... and in Linux, what PWM corresponds with this? Thanks a lot!

             

            Pablo.

            • 3. Re: Activate PWM signals from Linux command line
              Intel_Jesus

              Hi Pablo_ESP,

               

              We have validated with a Voltmeter that the PWM on PWM3 is working. We followed your steps from the original post which they are correct. When we change the duty_cycle the voltage changes proportionally. We could not validate it with a speaker because we dont have an amplifier/shield because the current is so low that the speaker drained the current. How are you testing this?

              The Arduino IDE ID column is referring to the physical pins on the Galileo. I know the mux table is a bit confusing but GPORT0_BIT2_PWM3 is on the second column, second to last row. The mux for PWM3 is GPIO30.

               

              Regards,

              Intel_JEspinoza

              1 of 1 people found this helpful
              • 4. Re: Activate PWM signals from Linux command line
                Pablo_ESP

                For validate I use an oscilloscope. Are you using the Linux SD version? I have seen in some web pages that in the SPI-Linux works correctly... but I not found examples for SD Linux version. This night I try again. Thanks.

                 

                Regards.

                 

                Pablo.

                • 5. Re: Activate PWM signals from Linux command line
                  Intel_Jesus

                  Hi Pablo _ESP,

                   

                  I have validated the PWM on PWM3 with an oscilloscope. I used the Linux Image for SD for Galileo. I set the period to 1000000ns (1ms) and the duty cycle to 500000ns (.5ms). The image bellow shows the results with the duty cycle at 50%.

                  Oscilloscope Results 50.png

                   

                  Then I set the period to 1000000ns (1ms) and the duty cycle to 250000ns (.25ms). The image bellow shows the results with the duty cycle at 25%.

                  Oscilloscope Results 25.png

                   

                  Regards,

                  Intel_JEspinoza

                  • 6. Re: Activate PWM signals from Linux command line
                    AlexanderMerz

                    Did you try to enable the corresponding GPIO device of the Pin 3 first? (After the correct mux setting, but before exporting the pwm device)

                     

                    echo "18" > /sys/class/gpio/export
                    echo "out" > /sys/class/gpio/gpio18/direction

                    echo "strong" > /sys/class/gpio/gpio18/drive

                    echo "1" > /sys/class/gpio/gpio18/value

                    echo "18" > /sys/class/gpio/unexport

                     

                    (I'm not sure, if 18 is the right one or is 15 is correct)

                    • 7. Re: Activate PWM signals from Linux command line
                      Pablo_ESP

                      thanks!! I thought that the gpio18 is configured by the CYPRESS. thank you very much to both!!! I put here the correct steps to activate de PWM3 output from SD-Linux

                        login as: root

                        root@clanton:~# echo "out" > /sys/class/gpio/gpio30/direction

                        root@clanton:~# echo "1" > /sys/class/gpio/gpio30/value

                        root@clanton:~# echo "out" > /sys/class/gpio/gpio18/direction

                        root@clanton:~# echo "1" > /sys/class/gpio/gpio18/value

                        root@clanton:~# echo "strong" > /sys/class/gpio/gpio18/drive

                        root@clanton:~# echo "1" > /sys/class/pwm/pwmchip0/pwm3/enable

                        root@clanton:~# echo "1000000" > /sys/class/pwm/pwmchip0/pwm3/period

                        root@clanton:~# echo "50000" > /sys/class/pwm/pwmchip0/pwm3/duty_cycle

                       

                      in Linux SD version, the export command is not necessary.

                       

                      Thanks a lot!

                      • 8. Re: Activate PWM signals from Linux command line
                        yuanpu

                        great answers, very useful.

                        it helps understand the intel io mapping.pdf

                        Galileo_Linux_IO.png