cancel
Showing results for 
Search instead for 
Did you mean: 

Timing a button press on STM8S001J3

jlc3
Associate

I'm trying to measure the duration of a button press using TIM2 as a counter.

I have one of the buttons triggering an interrupt which enables the timer on the positive edge, and then calls TIM2_GetCounter() on the negative edge.

I'll save you all a bunch of reading my failures (trust me, it wasn't helpful, you're not missing anything) and just post my working TIM2 setup code:

void TIM2_setup()
{
  TIM2_DeInit();
  TIM2_TimeBaseInit(TIM2_PRESCALER_16, 65535);
  TIM2_PrescalerConfig(TIM2_PRESCALER_16, TIM2_PSCRELOADMODE_IMMEDIATE);  
}

0 REPLIES 0