cancel
Showing results for 
Search instead for 
Did you mean: 

A bug on pwm complementary output of cubemx32

dengrui dengrui
Associate
Posted on June 25, 2017 at 13:07

When i want to produce a pwm complementary output ,the chip is stm32f103c8, only main connel have output and auxiliary have no output . I track program to file stm32f1xx_hal_tim.c on funtion : TIM_OC1_SetConfig and find line:

tmpccer &= ~TIM_CCER_CC1NE;

This line is wrong and shoud be change to :

tmpccer |= TIM_CCER_CC1NE;

Other fucntion as to TIM_OC2_SetConfig

TIM_OC3_SetConfig

 ,have same error.
2 REPLIES 2
Dave McCoy
Associate II
Posted on November 24, 2017 at 21:35

This did solve my problem but I think there is a little more to this.

After reading your post I looked at theTIM_OC_InitTypeDef structure within stm32f4xx_hal_tim.h and found the declaration:

typedef struct
{
 uint32_t OCMode; /*!< Specifies the TIM mode.
 This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. 
 This parameter can be a number between Min_Data = 0x0000U and Max_Data = 0xFFFFU */
uint32_t OCPolarity; /*!< Specifies the output polarity.
 This parameter can be a value of @ref TIM_Output_Compare_Polarity */
uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
 This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
 @note This parameter is valid only for TIM1 and TIM8. */
 
 uint32_t OCFastMode; /*!< Specifies the Fast mode state.
 This parameter can be a value of @ref TIM_Output_Fast_State
 @note This parameter is valid only in PWM1 and PWM2 mode. */
 uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
 This parameter can be a value of @ref TIM_Output_Compare_Idle_State
 @note This parameter is valid only for TIM1 and TIM8. */
uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
 This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
 @note This parameter is valid only for TIM1 and TIM8. */
} TIM_OC_InitTypeDef;�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

It looks fine but when I looked at older version of similar code I found that the

TIM_OCInitTypeDef, which is the predecessor of

TIM_OC_InitTypeDef, it used to have these two members:

TIM_OutputState

TIM_OutputNState

These two members configured the output state. The line you are referring to inside the

stm32f1xx_hal_tim.c (in my case stm32f4xx_hal_tim.c) follows a similar pattern to how the timer is initialized. First, the configuration bit in question is clearedand then configured with the appropriate using a member of the

TIM_OC_InitTypeDef structure

. Unfortunately, this 'output state' was not included in the new version of the structure and that bit was never enabled.

I do agree with you that there is no way, that I see, that the complementaryPWM output bit can be enabled. with the code the way it is.

https://community.st.com/people/dengrui.dengrui

Serious kudos to you, thanks for the catch! I've spent more than 4 hours wondering what was wrong with my code and test equipment.

Dave

Dave McCoy
Associate II
Posted on November 26, 2017 at 18:54

Okay, I was wrong, I found there is a function called HAL_TIMEx_PWM_Start_IT Will do the same things as both dengrui dengrui and I did.

As an example, in order to start the complementary channel on channel 1 of timer 1 then the call looks like this:

HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_1);�?�?�?�?�?�?

Dave