打印
[AT32F403/403A]

AT32F403ZGT6高级定时器1/8 PWM输出

[复制链接]
612|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
林权|  楼主 | 2022-10-30 22:39 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 林权 于 2022-10-30 22:46 编辑

关于定时器1,定时器8和定时器15,都要通过tmr_output_enable()把刹车寄存器BRK_OEN位置1才能输出,但这样只要配置位输出的通道都会输出,有没有配置具体通道输出而不影响其他通道的方法?
gpio_init_type  gpio_init_struct = {0};
tmr_output_config_type tmr_output_struct;
crm_clocks_freq_type crm_clocks_freq_struct = {0};

uint16_t timer_period = 0;
uint16_t channel1_pulse = 0, channel2_pulse = 0, channel3_pulse = 0, channel4_pulse = 0;

u8 test;
int main(void)
{

  /* congfig the system clock */
  system_clock_config();

        /* init at start board */
  at32_board_init();
      
  /* get system clock */
  crm_clocks_freq_get(&crm_clocks_freq_struct);

  /* enable tmr1/gpioa/gpiob clock */
  crm_periph_clock_enable(CRM_TMR1_PERIPH_CLOCK, TRUE);
  crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
      
        /* timer1 output pin(TMR1_CH1_PA8) Configuration */
  gpio_init_struct.gpio_pins = GPIO_PINS_10;
  gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
  gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
  gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
  gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
  gpio_init(GPIOA, &gpio_init_struct);

  timer_period = (crm_clocks_freq_struct.sclk_freq / 17570 ) - 1;

  /* compute c1dt value to generate a duty cycle at 50% for channel 1 and 1c */
  channel1_pulse = (uint16_t)(((uint32_t) 5 * (timer_period - 1)) / 10);

  /* tmr base configuration */
        tmr_repetition_counter_set(TMR1, PWM_NUM-1);
  tmr_base_init(TMR1, timer_period, 0);
  tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
  tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1);

  /* channel1 configuration in output mode */
  tmr_output_default_para_init(&tmr_output_struct);
  tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_B;
  tmr_output_struct.oc_output_state = TRUE;
  tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
  tmr_output_struct.oc_idle_state = TRUE;
  tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_3, &tmr_output_struct);
  tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_3, channel1_pulse);

  /* one cycle mode selection */
  tmr_one_cycle_mode_enable(TMR1, TRUE);

        /* ADVTMR output enable */
  tmr_output_enable(TMR1, TRUE);
  tmr_channel_enable(TMR1, TMR_SELECT_CHANNEL_3, TRUE);

//  tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_3, TRUE);
//  tmr_output_channel_switch_set(TMR1, TMR_SELECT_CHANNEL_3, TRUE);
  while(1)
  {
                tmr_counter_enable(TMR1, TRUE);
                delay_ms(100);               
  }
}

使用特权

评论回复
沙发
daye520| | 2022-11-2 08:56 | 只看该作者
不初始化相应的GPIO,它还会有输出吗?

使用特权

评论回复
评论
林权 2022-11-3 15:11 回复TA
不初始化的话没有输出,我是要使用定时器1的3,4通道输出PWM,只初始化一路,另一路没有输出 
板凳
vt2017| | 2022-11-3 17:36 | 只看该作者
tmr_output_struct.oc_output_state = TRUE;
这一句代码写FALSE即可。

使用特权

评论回复
评论
林权 2022-11-4 18:23 回复TA
已测试,确实可以解决问题,感谢 
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

18

帖子

0

粉丝