AnsweredAssumed Answered

Encoder Interface and Default_handler

Question asked by wolf_man on Nov 29, 2012
Latest reply on Dec 3, 2014 by Clive One
I'm trying  to read the tow signals from the encoder quadrature . I work with COIDE of coocox. but I don't know how i should write in the Default_handler (IRQ_TIM3).
I want read the both edges of the encoder signals,and know the value of my counter timer.
1) I ask if my configuration are OK ?
2) how i write in the IRQ of "startup_stm32f10x_md_vl.c"
in encoder.c I write :
#include "stm32f10x.h"
#include "encodeur.h"

void config(void){
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_ICInitTypeDef  TIM_ICInitStructure;
  GPIO_InitTypeDef GPIO_InitStructure_Encoder;

  /* Enable TIMER GPIO clocks */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);



  GPIO_InitStructure_Encoder.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure_Encoder.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure_Encoder.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB,&GPIO_InitStructure_Encoder);

      /* Timer configuration in Encoder mode */
  TIM_DeInit(ENCODER_TIM);

  TIM_TimeBaseStructure.TIM_Prescaler = 0;  // No prescaling
  TIM_TimeBaseStructure.TIM_Period = ENCODER_TIM_PERIOD-1;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(ENCODER_TIM, &TIM_TimeBaseStructure);


  TIM_EncoderInterfaceConfig(ENCODER_TIM, TIM_EncoderMode_TI12,TIM_ICPolarity_Rising, TIM_ICPolarity_Falling);
  TIM_ICStructInit(&TIM_ICInitStructure);

  TIM_ICInitStructure.TIM_ICFilter = ENC_FILTER;//ICx_FILTER;
  TIM_ICInit(ENCODER_TIM, &TIM_ICInitStructure);


  ENCODER_TIM->CNT = 0;
  TIM_Cmd(ENCODER_TIM, ENABLE);

}

int main(void){
    void config(void);
}

________________
in the "startup_stm32f10x_md_vl.c" i write
// configuration

static void Default_Handler(void)
{
  /* Go into an infinite loop. */
  while (1) {
   int curCount= ENCODER_TIM->CNT; // i juste added this line in this file

  }}

Outcomes