3 Replies Latest reply on Sep 16, 2016 1:20 PM by Intel Corporation

    PWM doesn't work properly.




      After generating pulses using PWM when the PWM device is closed using mraa_pwm_close() or even if it is disabled using mraa_pwm_enable(dev, 0), sometimes it is observed that PWM remains HIGH.

      This is especially when the duty cycle is changed in run-time using mraa_pwm_write() and the device is closed/disabled.

      Is there any setting to correct it or is it a known issue?




        • 1. Re: PWM doesn't work properly.
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello Gurudatta_Bhakte,

          We will try to help you determine why PWM is behaving this way. Does this happen every time? Which image are you using? And, which mraa version are you using? 

          We would like to replicate the issue, could you please post the code you are using?

          We'll be waiting for your response.

          • 2. Re: PWM doesn't work properly.

            Hello Pedro,


            This issue is not consistent but easily reproducible. We are using latest image and the library version is libmraa.so.1.

            I created a small code to reproduce this issue:


            #include <stdio.h>

            #include <stdlib.h>

            #include "mraa.h"


            int main() {

              /* Setup your example here, code that should run once


              mraa_result_t status = MRAA_SUCCESS;

              mraa_pwm_context dev;

              float duty_cycle = 0.1;


              /* Code in this loop will run repeatedly


              for (;;) {

              status = mraa_init();

              if (status != MRAA_SUCCESS) {

                  fprintf(stderr,"\nMRAA initialization failed with error %d!!\n", status);

                  return status;


              dev = mraa_pwm_init(6);

              status = mraa_pwm_period_us(dev, 9*1000);

              status = mraa_pwm_write(dev, duty_cycle);

              status = mraa_pwm_enable(dev, 1);

              fprintf(stderr,"\n PWM ON!!\n");



              status = mraa_pwm_enable(dev, 0);

              status = mraa_pwm_close(dev);

              fprintf(stderr,"\n PWM OFF!!\n");



              return 0;



            Please connect LED to PWM pin and run this program. When PWM is ON and you enter char it will close PWM, then we should get ZERO output on PWM pin and LED should be OFF, but sometimes LED remains ON with Full brightness that is PWM becomes HIGH still after closing PWM device.

            Is it hardware issue? Or some setting are missing?




            • 3. Re: PWM doesn't work properly.
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Hi Gurudatta,

              I have just tried you code, I can confirm that I replicated the behavior you mentioned (using mraa version 1.3.0). Right now, I believe the best option would be for you to submit an issue in mraa's github (https://github.com/intel-iot-devkit/mraa/issues). They should be able to provide you a more accurate response there.

              Let me know if they reply to you there.

              1 of 1 people found this helpful