AnsweredAssumed Answered

Setting up my STM32L031 for PWM input using TIM2

Question asked by Richard Cooke on Aug 30, 2017
Latest reply on Aug 30, 2017 by Richard Cooke

Hi Folks,


I think I've set up my TIM2 correctly using the CUBEMX but I'm new to the STM32 world and I'd like someone to take a look at this.  I'm going to be reading the output from a optocoupler connected to the 120VAC line and then through a buffer so the frequency will be 60Hz (here in the US).  I need to measure the pulse width to an accuracy of +/- 500 uS (1/2000 sec). I can then calculate the peak voltage and take action if it falls below a set value. I haven't been able to find a clear description on how to set up the TIM2 in CubeMX but here's what I've started with:

TIM2 pin setup

TIM2 config settings


Am I close to getting it correct?  My pulse generator decided that today was a good day to quit so I won't be able to test the code until Thursday when the new one shows up.


Any help will be greatly appreciated.