cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103, Keil V5, Encoder, Interrupt

hackerli90
Associate II
Posted on November 12, 2015 at 14:16

Hi guys.

im working on a simple encoder project where id like to read the encoder lines A and B and set a counter.

although, the interruptflags on PC6 and PC7 are not beeing set and i cant see why. 

PC6 and 7 were tested with a oscilloscope and the signal from the encoder channels is correct. 

here some coding

int main(void)

{

/* SysTick end of count event each 1ms */

//  RCC_GetClocksFreq(&RCC_ClockFreq);

//  SysTick_Config(RCC_ClockFreq.HCLK_Frequency / 1000);

 

/* System initialization */

SysInit();

/* Endless loop */

while(1)

  {

/* check if flags are being set */

temp--;

temp = EXTI_GetFlagStatus(EXTI_Line6);

temp = EXTI_GetFlagStatus(EXTI_Line7);

  }

}

void EXTI_Configuration(void)

{

EXTI_InitTypeDef EXTI_InitStructure;

  /* Connect EXTI6-8 Line to PC6-8 pin */

  GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource6);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource7);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource8);

  /* Configure EXTI6-8 line */

  EXTI_InitStructure.EXTI_Line = EXTI_Line6 | EXTI_Line7 | EXTI_Line8;

  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;  

  EXTI_InitStructure.EXTI_LineCmd = ENABLE;

  EXTI_Init(&EXTI_InitStructure);

}

void GPIO_Configuration(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

/* Encoder: Configure PC6, PC7 and PC8 as input function (A,B,I) */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOC, &GPIO_InitStructure);

}

void RCC_Configuration(void)

{  

/* Enable clock on GPIO A,B,C */    

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

}

void NVIC_Configuration(void) 

{  

NVIC_InitTypeDef NVIC_InitStructure;

#ifdef  VECT_TAB_RAM  

  /* Set the Vector Table base location at 0x20000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); 

#else  /* VECT_TAB_FLASH  */

  /* Set the Vector Table base location at 0x08000000 */ 

  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   

#endif

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //misc.h: NVIC_Priority_Table 

  /* Enable and set EXTI0 Interrupt to the lowest priority */

  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  /* Enable the USART2 Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

}

void SysInit(void)

{

/* This function fills the RCC_ClockFreq structure with the current

frequencies of different on chip clocks (for debug purpose) */

RCC_GetClocksFreq(&RCC_ClockFreq);

/* Configure the system ticker to 1ms */

SYSTICK_Configuration(1000);

/* NVIC configuration */

NVIC_Configuration();

  /* System Clocks Configuration */

  RCC_Configuration();

      

  /* Configure the GPIO ports */

  GPIO_Configuration();

/* Configure the USART ports */

USART_Configuration();

/* Configure Timer as Counter */

//TIM_Configuration();

/* Configure Button Interupt */

EXTI_Configuration();

}

void EXTI9_5_IRQHandler(void)

{

//if(EXTI_GetITStatus(EXTI_Line6) != RESET)

  //{

    read_encoder();

manage_increments();

    /* Clear the EXTI line pending bit */

    EXTI_ClearITPendingBit(EXTI_Line6);

EXTI_ClearITPendingBit(EXTI_Line7);

EXTI_ClearITPendingBit(EXTI_Line8);

  //}

}
4 REPLIES 4
Posted on November 12, 2015 at 14:53

Bunch of missing code.

  /* Enable AFIO clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hackerli90
Associate II
Posted on November 12, 2015 at 15:01

hello clive

thanks, i look into it. 

bunch of missing code, what else then? cant be much code missing!?

Posted on November 12, 2015 at 15:17

bunch of missing code, what else then? cant be much code missing!?

It looks to be a selective cut-n-paste that won't compile. Code that does the encoder/decoder function isn't there, so hard to tell if/why that doesn't increment/decrement properly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hackerli90
Associate II
Posted on November 12, 2015 at 16:55

Well i did not paste all the coding. but thanks a lot, its working properly now.