AnsweredAssumed Answered

EXTI signal capture speed limitation

Question asked by van_wyk.herman on Jan 18, 2013
Latest reply on Mar 14, 2013 by Clive One
Hi all,

I am using a DiscoreryF4 board to develop a small application that counts pulses entering a specific pin. This is required to read the pulses from a field instrument that generates the pulses as some processes within the instrument occurs. Thus it is never a fixed number of pulses or a fixed frequency. All I need to do is count the number of pulses within a second in order to provide the results of the process within the instrument.
I am using a signal generator so simulate the instrument that generates the pulses. Although it is a fixed frequency, it serves as a good enough simulation tool.
The problem I experience is that I can only accurately count the pulses up to a frequency of 1.3MHz. At higher frequencies the values counted initially halves and then the processor halts. When decreasing the frequency after a halt occurred, the processor continues to operate again.
Is there a maximum limit to the input frequencies that can be handled?
Possibly the error occurs due to noise generated as part of this high input frequency that is affecting the processor or other components. 
I am posting the code used. Please comment if anyone spots mistakes that might be the cause of my problem.

01.static void init_exti_capture(void)
02.{
03.  GPIO_InitTypeDef GPIO_InitStructure;
04.  NVIC_InitTypeDef NVIC_InitStructure;
05.  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
06.  TIM_OCInitTypeDef TIM_OCInitStructure;
07.  EXTI_InitTypeDef EXTI_InitStructure;
08. 
09.  __disable_irq();
10. 
11.  /* SYSCFG clock enable */
12.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
13. 
14. 
15.  /* GPIOC clock enable */
16.  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
17. 
18. 
19.  /* TIM8 clock enable */
20.  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
21. 
22. 
23.  /* EXTI1 line 0 : pin (PA.01) configuration */
24.  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_1;
25.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
26.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
27.  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
28.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
29.  GPIO_Init(GPIOA, &GPIO_InitStructure);
30. 
31.  /* Connect EXTI Line1 to PA1 pin */
32.  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
33. 
34.  /* Configure EXTI Line1 */
35.  EXTI_InitStructure.EXTI_Line = EXTI_Line1;
36.  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
37.  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
38.  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
39.  EXTI_Init(&EXTI_InitStructure);
40. 
41. 
42.  /* Enable and set EXTI Line1 Interrupt to the lowest priority */
43.  NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
44.  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
45.  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
46.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
47.  NVIC_Init(&NVIC_InitStructure);
48. 
49. 
50.  /* Enable the TIM8 global Interrupt */
51.  NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;
52.  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5;
53.  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
54.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
55.  NVIC_Init(&NVIC_InitStructure);
56. 
57.  /* configure timebase for 1s */
58.  TIM_TimeBaseStructure.TIM_Prescaler = (168 * 10) - 1;
59.  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
60.  TIM_TimeBaseStructure.TIM_Period = 10 - 1;
61.  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
62.  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
63. 
64.  TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
65. 
66.  /* Channel 1 Configuration in Timing mode */
67.  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
68.  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
69.  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
70.  TIM_OCInitStructure.TIM_Pulse = 0x0;
71. 
72.  TIM_OC1Init(TIM8, &TIM_OCInitStructure);
73. 
74.  /* Enable the TIM8 Update Interrupt */
75.  TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE);
76. 
77.  TIM_Cmd(TIM8, ENABLE);
78. 
79.  __enable_irq();
80. 
81.  return;
82.}

01.void EXTI1_IRQHandler(void)
02.{
03. 
04.  if (EXTI_GetITStatus(EXTI_Line1) == SET)
05.  {
06.    /* increment as pulse detected */
07.    EXTI_Capture_Rising_Cnt++;
08. 
09.    EXTI_ClearITPendingBit(EXTI_Line1);
10.  /* end "if (EXTI_GetITStatus(EXTI_Line1) == SET)" */
11. 
12.  return;
13.}

The value of EXTI_Capture_Rising_Cnt is printed and cleared every 1 second as part of the main loop. 

Also see attached system_stm32f4xx.c file for clock and PLL configuration.

Thanks guys,

H

Attachments

Outcomes