Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 3 months ago.
up/down counter
you can add example for pulse up/down counter? (one signal for count and one for direction)
i try this options but not count!
TIM_COUNTERMODE_CENTERALIGNED3
as documentation:
Counter Modes: Center-Aligned Mode (Up/Down Counting) Counter counts from 0 to the auto-reload value (content of the TIMx_ARR register) – 1, generates a counter overflow event, then counts from the autoreload value down to 1 and generates a counter underflow event. Then it restarts counting from 0 Center-aligned mode is active when CMS bits in TIMx_CR1 register are not equal to '00'. The Output compare interrupt flag of channels configured in output is set when: the counter counts down (Center aligned mode 1, CMS = "01"), the counter counts up (Center aligned mode 2, CMS = "10") the counter counts up and down (Center aligned mode 3, CMS = "11") In this mode, the direction bit (DIR from TIMx_CR1 register) cannot be written
for counting pulse (only up for now) suggestion with this modify: 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; (or TIM_COUNTERMODE_CENTERALIGNED3) 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;
}
check this
https://developer.mbed.org/users/c128/code/Nucleo_Hello_counter/
posted by paolo della vedova 29 Sep 2015