2016-09-02 03:41 AM
Hi all,
I want to count pulses from an input, using TIM5 channel 3, I have tried with channel 1 and it is working but I cannot make it works in channel 3 , can someone let me know what can be wrong.This is the code: GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* GPIOH clock enable */ RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOH, ENABLE); /* TIM5 clock enable */ RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM5, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOH, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOH, GPIO_PinSource12, GPIO_AF_TIM5); TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit (TIM5, &TIM_TimeBaseStructure); TIM_TIxExternalClockConfig (TIM5, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0); TIM_Cmd (TIM5, ENABLE);Thanks2016-09-02 05:04 AM
You can use Channel 1 (TI1) or Channel 2 (TI2)
Be sure to state the specific STM32 part being discussed.2017-01-06 03:25 AM
Hi Clive,
Thanks for the response, I stopped working on that and I started again now.
I can see on the datasheet pin PH12 use TIM5_CH3, need I change something to use channel 3 instead of channel 1 on TIM5?
Using PH10 (TIM5_CH1) works fine.
Thanks
2017-01-09 08:31 AM
I have try to do this:
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x00; TIM_ICInit( TIM5, &TIM_ICInitStructure );but still having problems to count the pulses.
I have checked the signal in the input PH12 and it is correct, I can see an square signal.
2017-01-09 02:14 PM
As Clive told you above,
You can use Channel 1 (TI1) or Channel 2 (TI2)
ie. you can't use CH3 or CH4 as an external source for counting.
JW
2017-01-09 07:56 PM
If it is too late to move to channel 1 or 2 (see timer block diagram in reference manual), I would use timer input capture interrupt to count events manually. Shall the frequency be too high, could use dma to backup input captures in a say 256 cyclic buffer which would prescale by 256... With dma interrupt and reading dma register, something could probably be cooked. Make sense?
2017-01-09 09:30 PM
DMA's NDTR itself can be used as a counter, too.
JW
2017-01-10 02:02 AM
Thanks for your response, I can't change the channels, I need to use those pins PH10(Channel 1) and PH12(Channel 3).
The frequency can be around 7 KHz. I will try your suggestions.
Thanks
2017-01-11 09:38 AM
Hi
Martinez_Pino.Jose_A
,What STM32 are you using? and do you have to use the Timer 5 in your application?
Since you are using channel1, as the other users have already told you, you can not use the channel3 as a pulse counter (even if you have thought about the XOR function).
If it is possible to change the timer, you can use TIM1,TIM2,TIM3,TIM4 or TIM8which have an ETR pin. Then you can configure this pin as an input for your pulse counter.
Khouloud.