Question
Manchester Decode with EXTI interrupt and Timer count
Posted on March 26, 2014 at 00:32
Hello,
I want to decode manchester code sent by RFID chip EM4 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.
void EXTI9_5_IRQHandler(void)
{
static uint16_t value=0, old_val = 0, diff=0;
if(EXTI_GetFlagStatus(EXTI_Line6) == SET) {
EXTI_ClearITPendingBit(EXTI_Line6);
value = TIM_GetCounter(TIM3);
diff = value - old_val;
old_val = value;
UART_Send_Numeric(USART3, diff);
UART_Send(USART3, (const unsigned char *)''\r\n'');
//TIM_SetCounter(TIM3, 0);
}
}
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):
TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure;
TIM_TimeBase_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBase_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBase_InitStructure.TIM_Period = 65535;
TIM_TimeBase_InitStructure.TIM_Prescaler = 72;
TIM_TimeBaseInit(TIM3, &TIM_TimeBase_InitStructure);
TIM_Cmd(TIM3, ENABLE);
What am I doing wrong?
Thank you.
Edit: The time between rising and falling edge is 256µs ±15µsor 512µs±15µs
#timer #exti #manchester