4701 views|4 replies

2865

Posts

4

Resources
The OP
 

There is a problem with the output level maintenance of GD32 pins after PWM output stops. Friends who are familiar with GD32, please come and have a look! [Copy link]

I use the GD32F103Cxx microcontroller. I turned on the PWM function provided by the microcontroller. After initialization, the output can be output normally, but there is a problem that cannot be solved:

That is, when timer_disable(TIMER2); is executed, the state of PWM output will be maintained. If it is high, it will be maintained high, and if it is low, it will be maintained low. No matter whether the pin is set to GPIO_MODE_AF_PP or GPIO_MODE_AF_OD, there is no way to fix it to a certain state. I hope that after PWM stops, it will stay in a fixed state, no matter what the output state is when it stops. Or is it possible to detect whether PWM outputs a complete cycle before stopping.

My initialization code:


void pwm2_ch1(void)
{

    /* TIMER3 configuration: generate PWM signals with different duty cycles:
       TIMER3CLK = SystemCoreClock / 108 = 1MHz */
    timer_oc_parameter_struct timer_ocintpara;
    timer_parameter_struct timer_initpara;

    rcu_periph_clock_enable(RCU_TIMER2);
    timer_deinit(TIMER2);

    /* TIMER3 configuration */
    timer_initpara.prescaler         = 14400-1;
    timer_initpara.alignedmode       = TIMER_COUNTER_EDGE;
    timer_initpara.counterdirection  = TIMER_COUNTER_UP;
    timer_initpara.period            = 5000 -1;
    timer_initpara.clockdivision     = TIMER_CKDIV_DIV4;
    timer_initpara.repetitioncounter = 0;
    timer_init(TIMER2,&timer_initpara);

     /* CH0 configuration in PWM mode */
    timer_ocintpara.outputstate  = TIMER_CCX_ENABLE;
    timer_ocintpara.outputnstate = TIMER_CCXN_DISABLE;
    timer_ocintpara.ocpolarity   = TIMER_OC_POLARITY_HIGH;
    timer_ocintpara.ocnpolarity  = TIMER_OCN_POLARITY_HIGH;
    timer_ocintpara.ocidlestate  = TIMER_OC_IDLE_STATE_LOW;
    timer_ocintpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
    timer_channel_output_config(TIMER2,TIMER_CH_1,&timer_ocintpara);

    timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_1,2500);
    timer_channel_output_mode_config(TIMER2,TIMER_CH_1,TIMER_OC_MODE_PWM0);
    timer_channel_output_shadow_config(TIMER2,TIMER_CH_1,TIMER_OC_SHADOW_DISABLE);

    timer_primary_output_config(TIMER2,ENABLE);
    /* auto-reload preload enable */
    timer_auto_reload_shadow_enable(TIMER2);
    //timer_enable(TIMER2);
		

}


	gpio_pin_remap_config(GPIO_TIMER2_PARTIAL_REMAP, ENABLE);
	gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_5);

STM32 has a corresponding function, but TIM_ForcedOC3Config is not found in the GD32 library. I am currently using the HAL library and I looked at the stop code as follows:

/**
  * [url=home.php?mod=space&uid=159083]@brief[/url] Stops the PWM signal generation on the complementary output.
  * @param  htim TIM handle
  * @param  Channel TIM Channel to be disabled
  *          This parameter can be one of the following values:
  *            [url=home.php?mod=space&uid=1238002]@arg[/url] TIM_CHANNEL_1: TIM Channel 1 selected
  *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
  *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
{
  /* Check the parameters */
  assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));

  /* Disable the complementary PWM output  */
  TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);

  /* Disable the Main Output */
  __HAL_TIM_MOE_DISABLE(htim);

  /* Disable the Peripheral */
  __HAL_TIM_DISABLE(htim);

  /* Set the TIM complementary channel state */
  TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);

  /* Return function status */
  return HAL_OK;
}

If there are friends in the forum who are familiar with GD32, come and have a look

This post is from GD32 MCU

Latest reply

It's good as long as it can solve the problem. We try the development board to raise questions and solve them. It's not about who is right or wrong. The ultimate goal is to solve the problem. I hope everyone will not take detours.   Details Published on 2022-4-28 20:09
 

6818

Posts

11

Resources
2
 
After PWM is finished, unless it is 100, it will still be low. I don't know if I understand it correctly?
This post is from GD32 MCU

Comments

Have you used an oscilloscope to look at the waveform? It is recommended to use an oscilloscope or a logic analyzer to capture the timing. First check for yourself whether the phenomenon you described is the problem you raised. Put the waveform in the post. This way, everyone can help you analyze it.  Details Published on 2022-4-28 16:07
 
 
 

6818

Posts

11

Resources
3
 
lugl4313820 posted on 2022-4-28 16:05 After PWM ends, unless it is 100, it will still be low. I don’t know if I understand it correctly?

Have you used an oscilloscope to look at the waveform? It is recommended to use an oscilloscope or a logic analyzer to capture the timing. First check for yourself whether the phenomenon you described is the problem you raised. Put the waveform in the post. This way, everyone can help you analyze it.

This post is from GD32 MCU

Comments

The problem I described is not a problem, because my PWM output is very slow, which can be found by observation. At present, the problem seems to be solved, using timer_channel_output_mode_config(TIMER2,TIMER_CH_1,TIMER_OC_MODE_LOW); However, I still don't know if this is  Details Published on 2022-4-28 17:54
 
 
 

2865

Posts

4

Resources
4
 
lugl4313820 posted on 2022-4-28 16:07 Have you used an oscilloscope to see the waveform? It is recommended to use an oscilloscope or a logic analyzer to capture the timing. First check for yourself whether the phenomenon you described is what you...

The problem I described is not a problem, because my PWM output is very slow, which can be discovered through observation.

The problem seems to be solved now, use timer_channel_output_mode_config(TIMER2,TIMER_CH_1,TIMER_OC_MODE_LOW);

But I still don't know if this is the right way.

This post is from GD32 MCU
 
 
 

6818

Posts

11

Resources
5
 

It's good as long as it can solve the problem. We try the development board to raise questions and solve them. It's not about who is right or wrong. The ultimate goal is to solve the problem. I hope everyone will not take detours.

This post is from GD32 MCU
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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