Jitter Issues :(

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

Jitter Issues :(

2,607 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ub3r on Mon Feb 27 15:58:16 MST 2012
Hi Guys,

I have 2 interrupts. One on a GPIO, and another timer Match interrupt.

The GPIO interrupt measures the pulse length (Servo Signal), by reading the timer counter at the rising, then the falling edges.

The Timer Match interrupt takes and ADC reading when its triggered.

The issue is, ive noticed jitter occuring on the pulse length value. When i disable the ADC, everything is fine. I suspect the GPIO interrupts cant occur whilst we are still in the Match interrupt taking an ADC reading??

Any work arounds for this issue?? If i use the input capture to read the RX pulse, will this work?

cheers
0 Kudos
Reply
12 Replies

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Wed Feb 29 11:51:54 MST 2012
If you need to call functions inside an ISR make them inline or macros to avoid call/return overhead.
I would use the ADC ISR to do some of the math instead of polling inside the match ISR.

The Timer Match hardware can automatically start an ADC conversion which will help with the jitter.
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ub3r on Wed Feb 29 08:21:37 MST 2012
If i use the capture input can i dodge re-writing my match ISR???
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Wed Feb 29 06:54:04 MST 2012
So, you don't mind bad code causing the jitter, but you do mind the jitter. Unfortunately the jitter is due to bad code which you don't mind.

1. Write the right code.
2. Use capture.
3. If you don't use capture input, set the interrupt priorities correctly. I guess that "correctly" means lower priority for timer, higher for input change.
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ub3r on Wed Feb 29 05:15:05 MST 2012

Quote: gbm
Hope you don't wait for ADC conversion to complete inside your interrupt routine!...

Post the code if you want some real help.



Yes i am.
I know its bad code. I dont mind the little wait, just hate the jitter its causing on my other interrupt.

Code below. You can see im calling a routine with 2 x ADC conversion and waiting for them to finish.
I dont mind that the routine takes a little while to finish, its just causing a bit of jitter on the RX signal input.
If i use the capture input with this resolve the jitter???


void TIMER16_1_IRQHandler(void)
{
if (LPC_TMR16B1->IR & (1<<1))      //detect interrupt MR1
{
LPC_TMR16B1->IR = (1<<1);      //clear interrupt

LPC_TMR16B1->MR1 = LPC_TMR16B1->MR1+ZC_SAMPLE_FACTOR;
if(LPC_TMR16B1->MR1 > 100){LPC_TMR16B1->MR1 = 5;}
seekZeroCrossTime();
}

if (LPC_TMR16B1->IR & (1<<3))      //detect interrupt MR3
{
LPC_TMR16B1->IR = (1<<3);      //clear interrupt
faultDetection();
}
}



void seekZeroCrossTime(void)
{
if(!COMM_SEEK_DELAY && !COMM_TIME_FOUND && DUTY_CYCLE < 10)   // Uses the ADC when under 10% Duty
{
//LED_ON;
MOTOR_NEUTRAL_VOLTAGE = ADCRead(3);// Motor Virtual Neutral Point
PHASE_VOLTAGE = ADCRead(ADCTable[COMMSTEP]);

switch(COMMSTEP)
{
case 0:
case 2:
case 4:
if(PHASE_VOLTAGE > MOTOR_NEUTRAL_VOLTAGE)
{
setCommTime();
}
break;
case 1:
case 3:
case 5:
if(PHASE_VOLTAGE < MOTOR_NEUTRAL_VOLTAGE)
{
setCommTime();
}
break;
}
}
}


Below is where i time the pulse length. The timer is set to 1uS. Will the capture be more accurate??

void PIOINT2_IRQHandler(void)
{
GPIOIntClear( PORT2, 1 ); // Clear Interrupt

PINSTATE = LPC_GPIO2->MASKED_ACCESS[1<<1] & (1<<1); // Read Pin 1 on Port 2. :D
if(PINSTATE)
{
timeAtRise = timer32_0_counter;
}

if(!PINSTATE)
{
timeAtFall = timer32_0_counter;
pulseLength = timeAtFall - timeAtRise;

if(pulseLength>MAXPL && pulseLength<2100)
{
MAXPL = pulseLength;
}

if(pulseLength<MINPL && pulseLength>1000)
{
MINPL = pulseLength;
}
}

calcPOSITION();

return;
}
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Wed Feb 29 04:28:36 MST 2012
Hope you don't wait for ADC conversion to complete inside your interrupt routine!...

Post the code if you want some real help.
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ub3r on Tue Feb 28 23:44:13 MST 2012
Yea im waiting for the ADC to complete. its in single shot mode running at 10Bit @ 4.5Mhz Clock.


Quote: atomicdog
The capture hardware is designed for things like this so I would assume you could get a decent performance improvement (especially when/if the code starts to become more complex).

Are you polling/waiting, in the match ISR, for the 2 ADC conversions to complete?

0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Tue Feb 28 23:32:42 MST 2012
The capture hardware is designed for things like this so I would assume you could get a decent performance improvement (especially when/if the code starts to become more complex).

Are you polling/waiting, in the match ISR, for the 2 ADC conversions to complete?
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ub3r on Tue Feb 28 22:18:38 MST 2012
Hi Rob, thanks for your thoughts.

I have thought about using the input capture, however im currently using a GPIO interrupt, and recording the timer value at the rising and falling edges.

Is the capture option much quicker?

cheers
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Tue Feb 28 11:40:34 MST 2012
How much jitter?
You will always see some jitter due to the fact that it takes some time for the interrupt service routine to start and depending on the other (ADC) interrupt.

One thing you could do is to use a capture pin of the timer + interrupt: first capture a rising edge (the event will capture the timer value) and the reprogram the capture for a falling edge and do the same. Now you can calculate the pulse length. This is always fast enough and very accurate.

The servo signal has a pulse with from 0.5 to 2.5 msec (with a 20 msec period) and with an 8 bit signal resolution (which is what most digital servos use) there is a 7.8 usec resolution. On a 12 MHz CPU clock this is 93 clock cycles.
I think this should just be OK but you have to look at your ADC interrupt to see if this indeed is the case.

Rob
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Tue Feb 28 00:52:09 MST 2012
And why don't you read the section of manual describing interrupts in Cortex core, containing the detailed information on priorities, preempting etc.?
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ub3r on Mon Feb 27 22:09:08 MST 2012
There are 2 ADC conversions, and assigning the values to some variables with a tiny bit of math in the match interrupt.
Yes ive set the priorities. The GPIO interrupt for capture is 0 level, the Match interrupt is 1.

If an interrupt with a higher priority is triggered whilst the cpu is running another interrupt, does it wait until it finishes that last interrupt? or does it execute whilst still running the lower priority interrupt??

Great chip im loving it so far, but still not fully familiar with the hardware.
0 Kudos
Reply

2,566 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Mon Feb 27 20:07:15 MST 2012

Quote: ub3r
Hi Guys,

I have 2 interrupts. One on a GPIO, and another timer Match interrupt.

The GPIO interrupt measures the pulse length (Servo Signal), by reading the timer counter at the rising, then the falling edges.

The Timer Match interrupt takes and ADC reading when its triggered.

The issue is, ive noticed jitter occuring on the pulse length value. When i disable the ADC, everything is fine. I suspect the GPIO interrupts cant occur whilst we are still in the Match interrupt taking an ADC reading??

Any work arounds for this issue?? If i use the input capture to read the RX pulse, will this work?

cheers


How much code is in the interrupt routines? Have you setup the interrupt priority levels?
0 Kudos
Reply