AnsweredAssumed Answered

EXTI interference problem stm32f4

Question asked by claude.antoine on Apr 3, 2015

Hi,

I have a problem with my stm32f4 (I work with keil)…I was configured tow DC motos with PWM with TIM3 connected to PA7 PA6 , PB0 , and PB1 pins. To know the motors rotation I was use tow simple optical encoder that return numeric value 0V and 5V. I read the impulsion returned by encoder with EXTI (PA0 , PA1) . In the early when I turn the motors manually, everything works perfectly. But when they turn with PWM, one motor I that the tow encoder return values. I think there is some interference between PWM and EXT. Please so one could give me an idea to solve my problem. Thank you in advance.

main file
       
  1.      EXTI_InitTypeDef   EXTI_InitStructure;
  2.    
  3.      NVIC_InitTypeDef   NVIC_InitStructure;
  4.    
  5.      
  6.    
  7.        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  8.    
  9.        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1;
  10.    
  11.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  12.    
  13.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  14.    
  15.     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  16.    
  17.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  18.    
  19.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  20.    
  21.      
  22.    
  23.      /*******EXTI INPUT PA0*********/
  24.    
  25.      SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
  26.    
  27.      
  28.    
  29.      EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  30.    
  31.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  32.    
  33.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  34.    
  35.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  36.    
  37.   EXTI_Init(&EXTI_InitStructure);
  38.    
  39.    
  40.    
  41.   /* Enable and set EXTI Line0 Interrupt to the lowest priority */
  42.    
  43.   NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  44.    
  45.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  46.    
  47.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  48.    
  49.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  50.    
  51.   NVIC_Init(&NVIC_InitStructure);
  52.    
  53.      
  54.    
  55.           /*******EXTI INPUT PA1*********/
  56.    
  57.      SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
  58.    
  59.      
  60.    
  61.             EXTI_InitStructure.EXTI_Line = EXTI_Line1;
  62.    
  63.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  64.    
  65.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  66.    
  67.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  68.    
  69.   EXTI_Init(&EXTI_InitStructure);
  70.    
  71.    
  72.    
  73.   /* Enable and set EXTI Line0 Interrupt to the lowest priority */
  74.    
  75.   NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
  76.    
  77.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  78.    
  79.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  80.    
  81.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  82.    
  83.   NVIC_Init(&NVIC_InitStructure);
it file
       
  1. void EXTI0_IRQHandler(void)
  2.    
  3. {
  4.    
  5. EXTI_ClearITPendingBit(EXTI_Line0);
  6.    
  7.   if(EXTI_GetITStatus(EXTI_Line0) != RESET) // If i have inpulse
  8.    
  9.   {
  10.    
  11. i++;
  12.    
  13. EXTI_ClearITPendingBit(EXTI_Line0);
  14.    
  15. }
  16.    
  17.    
  18.    
  19. void EXTI1_IRQHandler(void)
  20.    
  21. {
  22.    
  23. EXTI_ClearITPendingBit(EXTI_Line1);
  24.    
  25.   if(EXTI_GetITStatus(EXTI_Line1) != RESET) // If i have inpulse
  26.    
  27.   {
  28.    
  29. j++;
  30.    
  31. EXTI_ClearITPendingBit(EXTI_Line1);
  32.    
  33. }

Outcomes