1

I am trying to measure PWM signal duty cycle. I strive to make all configurations in STM32CubeMX and also I am using STM32F407G-Disc1 discovery board.

I have configured one timer to generate PWM signal and another to capture it.

TIM2 below is used to generate PWM signal with cycle time (T) of 20ms and Ton = 1ms. TIM2 generating PWM signal

TIM3 is configured in PWM input capture mode. Currently I doubt proper configuration. Can you please verify that first?

Pin configuration of the TIM3 TIM3 PWM input capture mode

Then I have wire connected from PA0 (TIM2_CH1) to PA6 (TIM3_CH1), also there an LED connected to visually verify the signal. It was also checked with an oscilloscope - pwm is generated correctly.


Next step was to capture measured values with DMA requests.

autogenerated main.c

uint32_t pwm[1] = {0};
// ...
if(HAL_TIM_IC_Start_DMA(&htim3, TIM_CHANNEL_1, pwm, 1) != HAL_OK)
{
    _Error_Handler(__FILE__, __LINE__);
}

Debugging later shows contents of pwm[0] equal to 20000 which is correct.

How would I measure Ton (when signal is logical 1) of the cycle?

I have tried enabling DMA request for the channel 2 of TIM3 as well, but it ends up in _Error_Handler().


Thanks in advance!

hrust
  • 734
  • 1
  • 11
  • 34

0 Answers0