This repository has been archived on 2023-07-17. You can view files and clone it, but cannot push or open issues or pull requests.
bl_mcu_sdk/examples/peripherals/pwm_v2/pwm_basic/main.c

32 lines
755 B
C
Raw Normal View History

#include "bflb_mtimer.h"
#include "bflb_pwm_v2.h"
2023-02-24 21:33:12 +08:00
#include "bflb_clock.h"
#include "board.h"
struct bflb_device_s *pwm;
int main(void)
{
board_init();
board_pwm_gpio_init();
pwm = bflb_device_get_by_name("pwm_v2_0");
/* period = .XCLK / .clk_div / .period = 40MHz / 40 / 1000 = 1KHz */
struct bflb_pwm_v2_config_s cfg = {
.clk_source = BFLB_SYSTEM_XCLK,
.clk_div = 40,
.period = 1000,
};
bflb_pwm_v2_init(pwm, &cfg);
bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH0, 100, 500); /* duty = (500-100)/1000 = 40% */
bflb_pwm_v2_channel_positive_start(pwm, PWM_CH0);
bflb_pwm_v2_start(pwm);
while (1) {
printf("pwm basic running\r\n");
bflb_mtimer_delay_ms(2000);
}
}