Interrupt Jitter

Status
Not open for further replies.

Xenoamor

Well-known member
I'm attempting to make a digital oscilloscope but the 70ns jitter I'm getting on my interrupts are heavily limiting.

I've tried both the following with only minor gains:
Code:
void setup() {
	pinMode(15, OUTPUT);  // #0
	pinMode(22, OUTPUT);  // #1
	pinMode(23, OUTPUT);  // #2
	pinMode(9,  OUTPUT);  // #3
	pinMode(10, OUTPUT);  // #4
	pinMode(13, OUTPUT);  // #5
	pinMode(11, OUTPUT);  // #6
	pinMode(12, OUTPUT);  // #7

	pinMode(4, INPUT);
	// put your setup code here, to run once:
	SCB_SHPR3 = 0x20200000;  // Systick = priority 32 (defaults to zero)
	NVIC_SET_PRIORITY(IRQ_PORTA, 0);
	attachInterrupt(4, pushData, FALLING);
}

void loop() {
	// put your main code here, to run repeatedly:
	while(1) {asm("NOP");}
	
}

FASTRUN static void pushData(void) {
	static uint32_t toggle = GPIOD_PDOR;
	toggle ^= 0xFFFFFFFF;
	GPIOC_PDOR = toggle;
}

ml3xgi.jpg

The top signal is the GPIOC_PDOR output
The bottom signal is the interrupt trigger (Pin 4)
 
I don't think you can avoid some interrupt latency variation ... they will most always be some code that disables some or all interrupts briefly for various justified or for lazy-code reasons.
If you can measure it, you'll probably find a far less frequent but much greater latency occurrence from things that happen on systick cycles or I/O complete servicing.

If you can do A/D sampling (if the 'scope is analog), or GPIO input bit if digital, and use DMA, perhaps most such issue can be reduced or eliminated. But this needs buffer-chaining and the like, in DMA hardware and drivers and some microprocessors don't have that. I'm not sure about the T3 or LC.
 
Last edited:
Thanks for the input Stevech!

I'm going to try using DMA to toggle the pin and see if that is any more linear. I have my doubts but it's worth a shot.

On a side note I tried disabling Cache prefetching and I've managed to reduce the jitter by 20ns
Code:
FMC_PFAPR |= 0x00FF0000;
 
Is there a way to disable all interrupts except the one's I want?

Either that or can anyone tell me which interrupts are active by default?
 
If you have no I/O devices in use that interrupt, then the 1KHz systick interrupt is likely the only interrupt source.
If you have USB/Serial in use, that's a consideration for sure.

Use of DMA to input data, if done right, and with buffer chaining, can avoid impact of interrupt latency (excluding badly written I/O drivers that you can avoid).
 
Is there a way to disable all interrupts except the one's I want?

Either that or can anyone tell me which interrupts are active by default?


You don't need to disable other interrupts if the one you use is the one with the highest priority. That's the theory :)
Perhaps it would help to choose a CPU-Speed with faster F_BUS ?
 
Thanks for the feedback guys. I've tried a magnitude of things and other than disabling cache prefetching no improvements could be made.

However! I've used the following code as a test bed for DMA:
Code:
#include "DMAChannel.h"

DMAChannel dmachannel0;

uint32_t toggleData = 0xFFFFFFFF;

void setup() {
	FMC_PFAPR |= 0x00FF0000; // Disable prefetching
	
	pinMode(15, OUTPUT);  // #0
	pinMode(22, OUTPUT);  // #1
	pinMode(23, OUTPUT);  // #2
	pinMode(9,  OUTPUT);  // #3
	pinMode(10, OUTPUT);  // #4
	pinMode(13, OUTPUT);  // #5
	pinMode(11, OUTPUT);  // #6
	pinMode(12, OUTPUT);  // #7

	pinMode(4, INPUT);
	// put your setup code here, to run once:
	SCB_SHPR3 = 0x20200000;  // Systick = priority 32 (defaults to zero)
	//NVIC_SET_PRIORITY(IRQ_PORTA, 0);
	
	PORTA_PCR13 |= PORT_PCR_IRQC(2); // Trigger DMA request on falling edge
	
	dmachannel0.source(toggleData);
	dmachannel0.destination(GPIOC_PTOR);
	
	dmachannel0.transferSize(4);
	dmachannel0.transferCount(1);
	
	dmachannel0.triggerAtHardwareEvent(DMAMUX_SOURCE_PORTA);
	dmachannel0.enable();
	
	noInterrupts();
	
}

void loop() {
	// put your main code here, to run repeatedly:
	while(1) {asm("NOP");}
	
}

This gives me an incredible 20ns jitter! Thanks for all your input guys
 
Status
Not open for further replies.
Back
Top