2013-08-21 03:06 AM
Hi guys,
I am having a big problem; I would like to count external pulses with 2 timers; TIM 2 and TIM5. The problem is, that I need to connect my two timers to the 2 I/O pins that are free. So that means I need to select a channel for each of them. And I just can't find any channel selection for counting external pulses. So I chose TIM2 ch4 on PB11 and TIM5 ch4 on PA3. I need to use 32bit counters. How do I enable any other channel that default channel, which is ch1? Many thanks guysvoid PulseCounter(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* GPIOx clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* TIM2,TIM5 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
/* GPIOA Configuration: TIM2 CH4 (PB11) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Input/Output controlled by peripheral
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Button to ground expectation
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* GPIOA Configuration: TIM5 CH4 (PA3) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Input/Output controlled by peripheral
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Button to ground expectation
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect TIM2 pins to AF */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_TIM2);
/* Connect TIM5 pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM5);
TIM_TimeBaseStructure.TIM_Period = 500000;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 500000;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
TIM_TIxExternalClockConfig(TIM2, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Falling, 0);
TIM_TIxExternalClockConfig(TIM5, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Falling, 0);
TIM_Cmd(TIM2, ENABLE);
TIM_Cmd(TIM5, ENABLE);
}
2013-08-21 04:56 AM
That'll be a problem as they don't route
* @param TIM_TIxExternalCLKSource: Trigger source. * This parameter can be one of the following values: * @arg TIM_TIxExternalCLK1Source_TI1ED: TI1 Edge Detector * @arg TIM_TIxExternalCLK1Source_TI1: Filtered Timer Input 1 * @arg TIM_TIxExternalCLK1Source_TI2: Filtered Timer Input 2 Also note Period = N - 12013-08-21 05:50 AM
So that means I can only use ch1? TIM5 ch1 pin is used for user button and TIM2 ch1 is also used for SCL/SPC and for other TIM5 ch1 says it's ETR. Does that means it's external trigger? I tryed and it didn't worked.
Thanks for fast reply2013-09-02 05:35 PM
Hi Clive, I have to read a sensor that work with pulse. I have to counter the Low Pulse Occupancy time for get the read . I attach a image cutted from datasheet.
Can you help me? I use a stm32f4 discovery device Thanks in advance2013-09-02 06:09 PM
That didn't work, try citing the part#, data sheet, and page.
From the sound of it you'd want to use input capture mode, have it latch a free running count in TIMx->CNT into TIMx->CCRx and interrupt on the edges, or perhaps PWM input mode.2013-09-02 06:19 PM
thanks clive for your fast response. I attached the a image . I have to count the low pulse width for a definite time as 30seconds. What solution do you suggest?
Mic ________________ Attachments : Img.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0mb&d=%2Fa%2F0X0000000bda%2FWb_xASb3Vo2cMcNMgrFP9ROf3L488poYfg.o5ah4cf0&asPdf=false2013-09-02 06:48 PM
So how does the 10-90 ms low pulse widths relate to 30 seconds? Do you want to know the pulse widths, or just integrate them over 30 seconds?
Input Capture? STM32F4xx_DSP_StdPeriph_Lib_V1.1.0\Project\STM32F4xx_StdPeriph_Examples\TIM\TIM_InputCapture#define TIM_ICPolarity_Rising ((uint16_t)0x0000)
#define TIM_ICPolarity_Falling ((uint16_t)0x0002)
#define TIM_ICPolarity_BothEdge ((uint16_t)0x000A)
2013-09-03 01:27 AM
Hi Clive, thanks a lot for you support. I'll know the low pulse widths duration and to do the sum of it. Sample for three pulse.... first 40ms is low, second 30ms is low and last 40ms is low.... 40+30+40 = 110 and apply the formula for gas concentration .
Can you write a sample of code? You are the best in the forum.. thanks you2014-04-24 06:37 AM
2014-04-24 06:49 AM
Well assuming you're using an F407 part, then that would be the Reference Manual, RM0090
The signal routing is limited, you cannot invent connectivity to suit. ''Does not route'' basically means the software/hardware to not provide a method to get from where you are, to where you want to go. This would be the salient diagram in the Reference Manual, that shows the non ETR/ITR sources for an external clock. This re-enforces the Firmware Library definitions I posted earlier.