Hardware pwm clock frequency on rockpi4b?

Hi all, I was using Raspberry Pi3b and now I would like to try hardware pwm on the Rock Pi4b. With the bcm2835 chip, it reads “The PWM clock can be set to control the PWM pulse widths. The PWM clock is derived from a 19.2MHz clock. You can set any divider, but some common ones are provided by the BCM2835_PWM_CLOCK_DIVIDER_* values of bcm2835PWMClockDivider.”
http://www.airspayce.com/mikem/bcm2835/

What about the hardware clock on the rockpi4b?
I would like to use libmraa to drive the hardware pwm to 1 MHz for some 3 wire laser pointer. Are there any example codes similar to pigpio as in http://abyz.me.uk/rpi/pigpio/cif.html#gpioHardwarePWM

Thank you!

checkout the pwm section of libmraa:

https://wiki.radxa.com/Rockpi4/dev/libmraa

Hi Jack,
Thanks and I tried the c example that comes with mraa.
If I set PWM_FREQ 1000, it works ok and I have a 1kHz square pulse. But if I set PWM_FREQ 100, it returns with MRAA: Invalid resource.

How can I have 1MHz square pulse?

Thanks

/* standard headers */

#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

/* mraa header */
#include “mraa/pwm.h”

/* PWM declaration */
#define PWM 11

/* PWM period in us */
#define PWM_FREQ 1000

volatile sig_atomic_t flag = 1;

void
sig_handler(int signum)
{
    if (signum == SIGINT) {
        fprintf(stdout, "Exiting...\n");
        flag = 0;
    }

}

int main(void)
{
mraa_result_t status = MRAA_SUCCESS;
mraa_pwm_context pwm;
float value = 0.0f;
//float output;

/* initialize mraa for the platform (not needed most of the times) */
mraa_init();

//! [Interesting]
pwm = mraa_pwm_init(PWM);
if (pwm == NULL) {
    fprintf(stderr, "Failed to initialize PWM\n");
    mraa_deinit();
    return EXIT_FAILURE;
}

/* set PWM period */
status = mraa_pwm_period_us(pwm, PWM_FREQ);
if (status != MRAA_SUCCESS) {
    goto err_exit;
}

/* enable PWM */
status = mraa_pwm_enable(pwm, 1);
if (status != MRAA_SUCCESS) {
    goto err_exit;
}

while (flag) {
    //value = value + 0.01f;
    value = 0.5f;

    /* write PWM duty cyle */
    status = mraa_pwm_write(pwm, value);
    if (status != MRAA_SUCCESS) {
        goto err_exit;
    }

    //usleep(100);

    //if (value >= 1.0f) {
    //    value = 0.0f;
    //}

    /* read PWM duty cyle */
    //output = mraa_pwm_read(pwm);
    //fprintf(stdout, "PWM value is %f\n", output);
}

/* close PWM */
mraa_pwm_close(pwm);

//! [Interesting]
/* deinitialize mraa for the platform (not needed most of the times) */
mraa_deinit();

return EXIT_SUCCESS;

err_exit:
mraa_result_print(status);

/* close PWM */
mraa_pwm_close(pwm);

/* deinitialize mraa for the platform (not needed most of the times) */
mraa_deinit();

return EXIT_FAILURE;

}

Hello rolly,
The libmraa has not support repeatedly change pwm clock frequency.
Change source code:

/* PWM period in us */
#define PWM_FREQ 100

Compiled it, reboot your rock pi 4 and then run the program,you can change pwm period to 100ms.
You can call the mraa_pwm_get_max_period and mraa_pwm_get_min_period functions to get current pwn output max and min period.

Hi Jubian,
Thank you and it works to 1 MHz with
/* PWM period in us */
#define PWM_FREQ 1
I suppose this is the fastest I can get with mraa as the unit is in microsecond?
Anyway, I found the pigpio library is easier than mraa with pwm, anyone tried to port the pigpio to rockpi4?

Best,
rolly