Question
Change Polarity of PWM with DMA in circular mode
Hello Experts ,
I am generating a two-Channel PWM with complementary channels also
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)sin_table, 20);//low
HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, (uint32_t *)sin_table, 20); //high
HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_2);
I am using DMA in circular mode .
I require when the total complete transfer occur the Polarity of the above channel ie Channel 1 and channel should or change .
void PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
{ if (htim->hdma[TIM_DMA_ID_CC1] != NULL && htim->hdma[TIM_DMA_ID_CC1] == &hdma_tim1_ch1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)
{
HAL_TIM_PWM_Stop_DMA(&htim1, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_1);
// Stop PWM on CH2 and CH2N before toggling polarity
HAL_TIM_PWM_Stop_DMA(&htim1, TIM_CHANNEL_2);
HAL_TIMEx_PWMN_Stop(&htim1, TIM_CHANNEL_2);
// Toggle the polarity bits for CH1 and CH1N
htim1.Instance->CCER ^= (TIM_CCER_CC1P | TIM_CCER_CC1NP);
// Toggle the polarity bits for CH2 and CH2N
htim1.Instance->CCER ^= (TIM_CCER_CC2P | TIM_CCER_CC2NP);
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_1, (uint32_t *)sin_table, 200);
HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start_DMA(&htim1, TIM_CHANNEL_2, (uint32_t *)sin_table, 200);
HAL_TIMEx_PWMN_Start_IT(&htim1, TIM_CHANNEL_2);
I tried the following way , After trigger the callback it stops the PWM and not start again ?
How can obtain it ?
