3

I'm tinkering with the pigpio [C] PWM functions and get ``pio bad dutycycle (nnn)'' messages while cycling an LED with increasing/decreasing gpioPWM() values.

As always, any help will be greatly appreciated.

Code:

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <pigpio.h>
#include <unistd.h>

unsigned int    PWM_PIN = 21,
                FREQ    = 1000,
                RANGE   = 125,
                PWM     = 255,
                DELAY   = 1E4;

int main(int argc, char *argv[]) {

   if (gpioInitialise() < 0) {
        fprintf(stderr, "GPIO initialization failed...exiting.\n");
        return(1);
    }

    gpioSetPWMfrequency(PWM_PIN, FREQ); 
    gpioSetPWMrange(PWM_PIN, RANGE);        

    while (1) {                                 
        for (int i = 0; i < PWM; i++) {
            gpioPWM(PWM_PIN, i);
            usleep(DELAY);
        }                                   

        for (int i = PWM; i > 0; i--) {
            gpioPWM(PWM_PIN, i);
            usleep(DELAY);

        }                                   
    }

    //printf(">>>\n");
    //getchar();
    //gpioTerminate();
    return 0;
}
1

You have set the range to 125 - the range is the number of steps between off (0) and fully on (125).

You then send values outside this range. PWM is 255, all values greater than 125 will be reported as an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.