Counter using TIM2

Dependencies:   mbed

Fork of Nucleo_Hello_counter by paolo della vedova

Encoder/CounterInit.cpp

Committer:
c128
Date:
2015-09-29
Revision:
2:70f92ce7d983
Parent:
1:3d2fffa6e19f

File content as of revision 2:70f92ce7d983:

#include "mbed.h"

void CounterInit(TIM_IC_InitTypeDef counterSet, TIM_HandleTypeDef timer, TIM_TypeDef *TIMx, uint32_t maxcount)
{
    timer.Instance = TIMx;
    timer.Init.Period = maxcount;
    timer.Init.CounterMode = TIM_COUNTERMODE_UP; //TIM_COUNTERMODE_CENTERALIGNED3 for up/down ...
    timer.Init.Prescaler = 0;
    timer.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    timer.Init.RepetitionCounter = 0;

    counterSet.ICFilter = 0;
    counterSet.ICPolarity = TIM_ICPOLARITY_RISING;
    counterSet.ICPrescaler = TIM_ICPSC_DIV1;
    counterSet.ICSelection = TIM_ICSELECTION_DIRECTTI;

}