3623 views|1 replies

111

Posts

0

Resources
The OP
 

F350 pwm configuration failed [Copy link]

This post was last edited by tinnu on 2018-10-4 00:44
  1. void pwm_pin_config(void) { rcu_periph_clock_enable(RCU_GPIOA); gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLDOWN, GPIO_PIN_6|GPIO_PIN_7) ; gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_6|GPIO_PIN_7); gpio_af_set(GPIOA, GPIO_AF_5, GPIO_PIN_6|GPIO_PIN_7); } void pwm_timer_config(void) { timer_parameter_struct timer_initpara; timer_oc_para meter_struct pwm_initpara; pwm_pin_config(); rcu_periph_clock_enable(RCU_TIMER15); timer_deinit(TIMER15 ); timer_initpara.prescaler = 1800-1; timer_initpara.alignedmode = TIMER_COUNTER_EDGE; timer_initpara.counterdirection = TIMER_COUNTER_UP; timer_initpara.period = 1200-1; timer_initpara.clockdivision = TIMER_CKDIV_DIV1; // timer_initpara.repetitioncounter = 0; MER15,&timer_initpara) ; /* TIMERf15 channel control update interrupt enable*/ // timer_interrupt_enable(TIMER16,TIMER_INT_UP); // nvic_irq_enable(TIMER16_IRQn,0,1); pwm_initpara.outputstate = TIMER_CCX_ENABLE; //pwm_initpara.outputnstate = TIMER_CCXN_DISABLE; pwm_initpara.ocpolarity = TIMER_ OC_POLARITY_HIGH ; pwm_initpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; timer_channel_output_config(TIMER15, TIMER_CH_0, &pwm_initpara); timer_channel_output_mode_config(TIMER15, TIMER_CH_0, TIMER_OC_MODE_PWM1); timer_channel_output_pulse_value_config(TIMER15, TIMER_CH_0, 1000); timer_channel_output_shadow_config(TIMER15, TIMER_CH_0, TIMER_OC_SHADOW_ENABLE); /* TIMER15 counter enable*/ timer_enable(TIMER15); }
复制代码
There is no problem with the configuration of the actual timer part. Using the interrupt to flash the LED is successful, but the PA6 pin remains low and no PWM wave is generated.
This post is from GD32 MCU
 

111

Posts

0

Resources
2
 
I still haven't found the problem, but I switched to the CH1 channel of TIMER1 and used the PA1 output to change the above TIMER15 to TIMER1, CH0 to CH1, and PA6 to PA1, and the output can be normal. It is initially thought that there is something wrong with the TIMER1 timer. Some TIMER15 timer functions cannot be configured, or TIMER15 itself has bugs
  1. void pwm_pin_config(void) { rcu_periph_clock_enable(RCU_GPIOA); gpio_af_set(GPIOA, GPIO_AF_2, GPIO_PIN_1); gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO_PIN_1); gp io_output_options_set( GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_1); } /*! \ brief Configure TIMER peripherals \ param [in] none \ param [out] none \ retval none */ void pwm_timer_config(void) { timer_parameter_struct timer_initpara; timer_oc_parameter_struct pwm_initpara; pwm_pin_config(); rcu_periph_clock_enable(RCU_TIMER1); timer_deinit(TIMER1); .prescaler = 1800-1; timer_initpara.alignedmode = TIMER_COUNTER_EDGE; timer_initpara.counterdirection = TIMER_COUNTER_UP; timer_initpara.period = 1200-1; timer_initpara.clockdivision = TIMER_CKDIV_DIV1; timer_initpara.repetitioncounter = 0; timer_init(TIMER1,&timer_in itpara); /* TIMERf1 channel Control update interrupt enable*/ // timer_interrupt_enable(TIMER1,TIMER_INT_UP); // nvic_irq_enable(TIMER1_IRQn,0,1); /* Step 2: Compare mode configuration: Set the CHxCOMSEN bit to configure the output comparison shadow register; Set the CHxCOMCTL bit to Configure the output mode (set high/set low/invert); set the CHxP/CHxNP bits to select the polarity of the active level; set CHxEN to enable the output. */ pwm_initpara.outputstate = TIMER_CCX_ENABLE; pwm_initpara.ocpolarity = TIMER_OC_POLARITY_HIGH; //pwm_initpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW; timer_channel_output_config(TIMER1, TIMER_CH_1, &pwm_initpara); timer_channel_output_mode_config(TIMER1, TIME R_CH_1, TIMER_OC_MODE_PWM1); timer_channel_output_shadow_config(TIMER1, TIMER_CH_1, TIMER_OC_SHADOW_ENABLE); / * Step 4: Configure the output comparison time base through the TIMERx_CAR register and TIMERx_CHxCV register: CHxVAL can be changed at runtime according to the waveform you expect*/ timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_1, 1000); /* TIMER1 counter enable*/ timer_enable( TIMER1); }
复制代码
This post is from GD32 MCU
 
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list