
Counter using TIM2
Fork of Nucleo_Hello_counter by
Encoder/CounterInit.cpp@2:70f92ce7d983, 2015-09-29 (annotated)
- Committer:
- c128
- Date:
- Tue Sep 29 06:50:08 2015 +0000
- Revision:
- 2:70f92ce7d983
- Parent:
- 1:3d2fffa6e19f
UPDATE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
c128 | 1:3d2fffa6e19f | 1 | #include "mbed.h" |
c128 | 1:3d2fffa6e19f | 2 | |
c128 | 1:3d2fffa6e19f | 3 | void CounterInit(TIM_IC_InitTypeDef counterSet, TIM_HandleTypeDef timer, TIM_TypeDef *TIMx, uint32_t maxcount) |
c128 | 1:3d2fffa6e19f | 4 | { |
c128 | 1:3d2fffa6e19f | 5 | timer.Instance = TIMx; |
c128 | 1:3d2fffa6e19f | 6 | timer.Init.Period = maxcount; |
c128 | 2:70f92ce7d983 | 7 | timer.Init.CounterMode = TIM_COUNTERMODE_UP; //TIM_COUNTERMODE_CENTERALIGNED3 for up/down ... |
c128 | 1:3d2fffa6e19f | 8 | timer.Init.Prescaler = 0; |
c128 | 1:3d2fffa6e19f | 9 | timer.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
c128 | 1:3d2fffa6e19f | 10 | timer.Init.RepetitionCounter = 0; |
c128 | 1:3d2fffa6e19f | 11 | |
c128 | 1:3d2fffa6e19f | 12 | counterSet.ICFilter = 0; |
c128 | 1:3d2fffa6e19f | 13 | counterSet.ICPolarity = TIM_ICPOLARITY_RISING; |
c128 | 1:3d2fffa6e19f | 14 | counterSet.ICPrescaler = TIM_ICPSC_DIV1; |
c128 | 1:3d2fffa6e19f | 15 | counterSet.ICSelection = TIM_ICSELECTION_DIRECTTI; |
c128 | 1:3d2fffa6e19f | 16 | |
c128 | 1:3d2fffa6e19f | 17 | } |
c128 | 1:3d2fffa6e19f | 18 |