typedef enum pwm_cmp_mode {pwm_cmp_mode_output_compare = 0, /**< output compare*/pwm_cmp_mode_input_capture = 1, /**< input compare*/} pwm_cmp_mode_t;
typedef enum pwm_register_update {pwm_shadow_register_update_on_shlk = 0, /**< after software set shlk bit of shlk register*/pwm_shadow_register_update_on_modify = 1, /**< immediately after the register being modified*/pwm_shadow_register_update_on_hw_event = 2, /**< after hardware event assert*/pwm_shadow_register_update_on_sh_synci = 3, /**< after SHSYNCI assert */} pwm_shadow_register_update_trigger_t;
void config_pwm(PWM_Type *ptr, uint8_t pin, uint8_t cmp_index, uint32_t reload, bool cmp_initial_zero, uint8_t hw_event_cmp){pwm_cmp_config_t cmp_config = {0};pwm_config_t pwm_config = {0};pwm_stop_counter(ptr);pwm_get_default_pwm_config(ptr, &pwm_config);//复位默认pwm寄存器配置pwm_get_default_cmp_config(ptr, &cmp_config);//复位默认比较寄存器配置pwm_config.enable_output = false;pwm_config.dead_zone_in_half_cycle = 0;//半周期PWM死区设定pwm_config.invert_output = false;//反转输出电平设定pwm_set_reload(ptr, 0, reload);//设置重装载值pwm_set_start_count(ptr, 0, 0);//设置PWM定时器起始值//预配置寄存器信息cmp_config.mode = pwm_cmp_mode_output_compare;//设定PWM定时器比较模式为cmp_config.cmp = cmp_initial_zero ? 0 : reload + 1;//设定比较值cmpcmp_config.update_trigger = pwm_shadow_register_update_on_modify;//更新触发方式为立即更新pwm_config_cmp(ptr, cmp_index, &cmp_config);//PWM配置更新//更新触发器类型,以便在硬件事件(重新加载)时更新比较值cmp_config.update_trigger = pwm_shadow_register_update_on_hw_event;//将pwm配置为cmp驱动的输出if (status_success != pwm_setup_waveform(ptr, pin, &pwm_config, cmp_index, &cmp_config, 1)) {printf("failed to setup waveformn");while(1);}//pwm_setup_waveform设定输出PWM波形//配置硬件事件cmp_config.cmp = reload - 1;cmp_config.update_trigger = pwm_shadow_register_update_on_hw_event;pwm_load_cmp_shadow_on_match(ptr, hw_event_cmp, &cmp_config);//设定影子寄存器}
static inline void pwm_start_counter(PWM_Type *pwm_x)intc_m_enable_irq_with_priority(irq, priority)
全部0条评论
快来发表一下你的评论吧 !