LPC5410x quadrature signal decoder Timer32

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC5410x quadrature signal decoder Timer32

1,731 Views
svensavic
Contributor III

I have some problems with configuring Timer0 to decode signals from Quadrature encoder.

For lower frequency it kind of works, although count is off by 4 ? Is that because of PLL ?

Lets say I have 100Hz signal, I would get 24-26 interrupts ? 

On frequencies above 2-3kHz, I dont get a single interrupt call. Why would that happen ?

My setup function looks like:

LPC_SYSCON->ASYNCAPBCTRL = 1;
LPC_ASYNC_SYSCON->ASYNCAPBCLKCTRLSET = _BV(13);
LPC_ASYNC_SYSCON->ASYNCPRESETCTRLCLR = _BV(13);

IOMux io_chnA (0, 26, FuncEnum::B0_CAP3); io_chnA.setI2CMode(false);
IOMux io_chnB (0, 25, FuncEnum::B0_CAP2); io_chnB.setI2CMode(false);


LPC_TIMER0->CCR |= _BV(9) | _BV(10) | _BV(11); //capture 0.3 raising edge, falling edge, interrupt
LPC_TIMER0->TCR = 1;

NVIC_EnableIRQ (CT32B0_IRQn);
NVIC_SetPendingIRQ (CT32B0_IRQn);

Interrupt function like:

extern "C" void CT32B0_IRQHandler ()
{
if (IS_BIT_ENABLED(LPC_TIMER0->IR, TIMER_IR_CR3)){ //chnA interrupt
    LPC_TIMER0->IR |= _BV(TIMER_IR_CR3);
    LPC_TIMER0->TCR |= _BV(1);

    }

LPC_TIMER0->TCR &= ~_BV(1);

}

My microcontroller is running at 96Mhz PLL. No prescale on Timer. 

Why is capture not triggered on >3kHz ?

Labels (2)
0 Kudos
6 Replies

1,497 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Sven,

Frankly speaking, I do not think that the CTimer of LPC541xx can run in quadrature mode. Generally, the Encoder can generate PhsaeA and PhaseB signals in incremental mode, the PhaseA/PhaseB signals are phase shifting with 90 degree, the counter should count both rising/falling edges of both PhaseA and PhaseB signals, of course, the LPC5410x Standard counter/timers do not support the quadrature mode.

I suggest you use for example Kinetis KV family for example KV11.

This is KV family link:

Kinetis® V Series: Real-time Motor Control & Power Conversion MCUs based on Arm® Cortex®-M0+/M4/M7 |... 

If you use capture mode of the Ctimer, each edge of PhaseA or PhaseB will generate capture interrupt, the cpu load is heavy.

Hope it can help you

BR

Xiangjun Rong

pastedImage_2.png

0 Kudos

1,497 Views
svensavic
Contributor III

Thanks for your suggestion. I don’t really need to capture both phases, because of the nature of the signal I need to capture raising and falling edge of one phase and just read the status of the other phase to determine direction CW or CCW. As you said both phases are in sync with phase shift. 

Also I already have system in place and cant really change the mcu, so I am stuck with either Timer32 of SCT. 

This thing was working fine on Cortex M3 timer32, but for some reason LPC54102 is not triggering on higher frequencies, which is very strange. Probably missing some setting somewhere..

0 Kudos

1,497 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Sven,

I suppose that you can enter capture interrupt ISR when the capture signal frequency is low. When the capture signal frequency is high, can you enter capture ISR? or you miss some capture interrupt event. If you miss some capture interrupt event, I think the cpu workload is high, in the case, you need simplify the ISR, as a test, you can clear the capture interrupt flag in IR reg and toggle a GPIO in capture ISR.

Hope it can help you

BR

XiangJun Rong

0 Kudos

1,497 Views
svensavic
Contributor III

Hi XiangJun, 

Thing is that when frequency is high I dont get a single interrupt. Its like signal is filtered/averaged and mcu doesnt see the transitions anymore. 

I was first testing this with the quadrature encoder from the motor while spinning the motor. Around 1000RPM (I didnt measure, so this is more a guesstimate) it stops getting a any interrupt. Slowing down the motor I start getting interrupts consistently. 

Then I thought it might be the issue with the signal itself, so I connected function generator and oscilloscope to see what is the signal in. I was able to catch all interrupts up to 1kHZ. At 2kHz I dont receive a single interrupt.

That is why I wouldnt say its problem with the speed of microcontroller. My interrupt routine is very simple. I just count pulses depending on interrupt type and checking the status of the GPIO (raw read of memory location). No other functions are called or calculations are done at that point. I believe my interrupt routine is bellow 30 cpu cycles.

I would expect at least occasional interrupt call, but I dont get a single one above certain frequency.

0 Kudos

1,497 Views
svensavic
Contributor III

As Pin 0.26 and 0.27 are muxed with I2C I wanted to test something else. So I hooked up signal generator on other port that is "normal" GPIO based.

So, on Pin 1.7 and 1.8 (CT32B1_CAP2/3) I dont seem to have any issue up to 5kHz. Above that the mcu speed seems to be the bottleneck. But I still receive interrupts. 

To conclude this, seems like I2C muxed pins have problems with input capture. Am I missing some setting on the pins that would affect such behaviour ? I am using i2c0 for connecting to some peripherals, but not i2c1, so I dont think there should be any issues with pins..

0 Kudos

1,497 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,Sven,

I think there are two possibilities that the capture signal is limited to 5KHz: One is the pin response  limitation, another is cpu may be overloaded.

For the pin response  limitation, I think you can input the capture signal from another pin and have a try.

For the cpu overloaded test, you can toggle a GPIO pin in the main loop, test the GPIO pin with oscilloscope, you can know if the cpu is overloaded.

Hope it can help you

BR

XiangJun Rong

0 Kudos