AnsweredAssumed Answered

Manchester Decode with EXTI interrupt and Timer count

Question asked by mubin.icyer on Mar 26, 2014
Latest reply on Mar 26, 2014 by Clive One
Hello,
I want to decode manchester code sent by RFID chip EM4095. I set up a timer as counter without interrupt and EXTI line with interrupt. I am getting an interrupt on every rising and falling edge of the PC.6. So far so good. In the IRQ handler I record the actual timer value by calling TIM_GetCounter and subtract the old value with new value, but I get always the same result. The result shall be sometimes x sometimes 2x. 

01.void EXTI9_5_IRQHandler(void)
02.{
03.    static uint16_t value=0, old_val = 0, diff=0;
04. 
05.    if(EXTI_GetFlagStatus(EXTI_Line6) == SET) {
06.            EXTI_ClearITPendingBit(EXTI_Line6);
07.            value = TIM_GetCounter(TIM3);
08. 
09.            diff = value - old_val;
10.            old_val = value;
11. 
12.            UART_Send_Numeric(USART3, diff);
13.            UART_Send(USART3, (const unsigned char *)"\r\n");
14. 
15.            //TIM_SetCounter(TIM3, 0);
16.    }
17.}

I tested with the line TIM_SetCounter(TIM3, 0); but then I get always 1, 0, 0, 65525 or so.

And timer initialization for 1µs tick ( The cpu clock is 72MHz):

01.TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure;
02. 
03.TIM_TimeBase_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
04.TIM_TimeBase_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
05.TIM_TimeBase_InitStructure.TIM_Period = 65535;
06.TIM_TimeBase_InitStructure.TIM_Prescaler = 72;
07.TIM_TimeBaseInit(TIM3, &TIM_TimeBase_InitStructure);
08. 
09. 
10.TIM_Cmd(TIM3, ENABLE);


What am I doing wrong? 
Thank you.



Edit: The time between rising and falling edge is 256µs  ±15µs or 512µs  ±15µs

Outcomes