I try to use hardware PWM on RPI 3b+ (Linux 11 bullseye) by using bcm2835.h (ver. 1.71) with small C code given below
#include <bcm2835.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char **argv)
{
if (!bcm2835_init()) return 1;
bcm2835_gpio_fsel(18, BCM2835_GPIO_FSEL_ALT5);
bcm2835_pwm_set_clock(2);
bcm2835_pwm_set_mode(0, 1, 1);
bcm2835_pwm_set_range(0, 2);
bcm2835_pwm_set_data(0, 1);
bcm2835_close();
return 0;
}
It was compiled, built and run with no errors, but oscilloscope connected to corresponding pin shows that output signal has duty cycle approx ~ 99%, not 50%, as expected. Changing corresponding argument in bcm2835_pwm_set_data() has no effect, duty cycle does not change. Changing arguments in bcm2835_pwm_set_clock() and bcm2835_pwm_set_range(0, 2) result in frequency changing, but duty cycle does not varying! Why it could be?