2014-03-25 04:32 PM
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
2014-03-25 05:15 PM
72-1 for 1 us from 72 MHz clock (Prescaler programs as N-1)
You don't need an EXTI interrupt, you should be able to use the CCx interrupts from the TIM. For timers that don't support the both edges mode, CH1 and CH2 can be programmed to trigger/latch on opposite phases of the CH1 (or CH2) signal.2014-03-25 06:01 PM
2014-03-25 06:20 PM
Interrupts should do what they need quickly and leave. You should avoid anything that's going to take a while, or uses spin-loops. Work that can be deferred should be posted to another task.