cancel
Showing results for 
Search instead for 
Did you mean: 

EXTI interference problem stm32f4

haythem
Associate II
Posted on April 03, 2015 at 21:22

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. NVIC_InitTypeDef   NVIC_InitStructure;
  3.  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  4.  GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1;
  5.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  6.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  7.     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  8.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  9.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  10. /*******EXTI INPUT PA0*********/
  11. SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
  12. EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  13.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  14.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  15.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  16.   EXTI_Init(&EXTI_InitStructure);
  17.   /* Enable and set EXTI Line0 Interrupt to the lowest priority */
  18.   NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
  19.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  20.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  21.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  22.   NVIC_Init(&NVIC_InitStructure);
  23. /*******EXTI INPUT PA1*********/
  24. SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
  25.  EXTI_InitStructure.EXTI_Line = EXTI_Line1;
  26.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  27.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
  28.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  29.   EXTI_Init(&EXTI_InitStructure);
  30.   /* Enable and set EXTI Line0 Interrupt to the lowest priority */
  31.   NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
  32.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  33.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  34.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  35.   NVIC_Init(&NVIC_InitStructure);

it file

  1. void EXTI0_IRQHandler(void)
  2. {
  3. EXTI_ClearITPendingBit(EXTI_Line0);
  4.   if(EXTI_GetITStatus(EXTI_Line0) != RESET) // If i have inpulse
  5.   {
  6. i++;
  7. EXTI_ClearITPendingBit(EXTI_Line0);
  8. }
  9. void EXTI1_IRQHandler(void)
  10. {
  11. EXTI_ClearITPendingBit(EXTI_Line1);
  12.   if(EXTI_GetITStatus(EXTI_Line1) != RESET) // If i have inpulse
  13.   {
  14. j++;
  15. EXTI_ClearITPendingBit(EXTI_Line1);
  16. }
0 REPLIES 0