Posted on April 03, 2015 at 21:22Hi,
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
- EXTI_InitTypeDef EXTI_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /*******EXTI INPUT PA0*********/
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
- EXTI_InitStructure.EXTI_Line = EXTI_Line0;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- /* Enable and set EXTI Line0 Interrupt to the lowest priority */
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /*******EXTI INPUT PA1*********/
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
- EXTI_InitStructure.EXTI_Line = EXTI_Line1;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- /* Enable and set EXTI Line0 Interrupt to the lowest priority */
- NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
it file
- void EXTI0_IRQHandler(void)
- {
- EXTI_ClearITPendingBit(EXTI_Line0);
- if(EXTI_GetITStatus(EXTI_Line0) != RESET) // If i have inpulse
- {
- i++;
- EXTI_ClearITPendingBit(EXTI_Line0);
- }
- void EXTI1_IRQHandler(void)
- {
- EXTI_ClearITPendingBit(EXTI_Line1);
- if(EXTI_GetITStatus(EXTI_Line1) != RESET) // If i have inpulse
- {
- j++;
- EXTI_ClearITPendingBit(EXTI_Line1);
- }