cancel
Showing results for 
Search instead for 
Did you mean: 

Manchester Decode with EXTI interrupt and Timer count

mubinicyer
Associate II
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
3 REPLIES 3
Posted on March 26, 2014 at 01:15

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mubinicyer
Associate II
Posted on March 26, 2014 at 02:01

Thank you very much.

I found another mistake. USART is very slow as well (I set it up for 9600 baud), therefore I get always different values. It is not a good idea to use USART and LCD routiens in a IRQ handler. I removed USART functions and added USART functions in another EXTI line IRQ for button. When I press the button I get the correct values :)

I will try it now with CC as you suggested.

Thanks again. Have a nice day.

Posted on March 26, 2014 at 02:20

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..