-
Notifications
You must be signed in to change notification settings - Fork 87
Description
Hi,
How am I able to set the interrupt priority for a timer above the USB-communication timer. I'm just asking because I have a very simple program which uses the DueTimer with timer6 to set an puls interval time around 1msec. Within this interval I create pulses with a width of 50usec. Tried it with two interrupt, but the ISR code made it almost impossible to get the accuracy of 1usec. So just a 'wait until ready' is now used within the DueTimer callback function to set/clear the puls itself.
This is very great and works like a charm!
But just now and then I get some puls shift in time because the ISR-callback is delayed and I'm guessing, but it must be the USB interrupt, because I'm not utilizing any other ISR.
It would be great if the DueTimer library was able to set the priority for every timer!
#define CycleTimer_s Timer6
void setup()
{
// Some other init stuff
// Setup puls timer:
CycleTimer_s.attachInterrupt(CycleHandler);
CycleTimer_s.start(static_cast<WDouble64>(m_PulsConfig_s.Cycle_u32));//DEFAULT_PULS_CYCLE_TIME) );
}
void CycleHandler(void)
{
WU16 Cntr_u16 = 0;
if (m_MainStatus_e == MAIN_TEST_ACTIVE)
{
if (PulsActive_b)
{
FastDigWriteOn(OUT_HS_Plus);
FastDigWriteOff(OUT_HS_Min);
FastDigWriteOn(OUT_LS_Plus);
FastDigWriteOff(OUT_LS_Min);
do
{
// __asm__("nop");
__asm__("nop");
__asm__("nop");
__asm__("nop");
} while (++Cntr_u16 < 3);
}
else
{
FastDigWriteOff(OUT_HS_Plus);
FastDigWriteOn(OUT_HS_Min);
FastDigWriteOff(OUT_LS_Plus);
FastDigWriteOn(OUT_LS_Min);
}
// No delays: 2,543 usec!
// 2,616 usec: cntr = 6; nops 1
// 3,068 usec: cntr = 6; nops 2
// 2,599 usec: cntr = 5; nops 1
// 2,979 usec: cntr = 5; nops 2
// 2,599 usec: cntr = 1; nops 2 -> loop = 50nsec
// 2,737 usec: cntr = 3; nops 3 -> loop = 200 nsec
// 2.676 usec: cntr = 4; nops 2 -> loop = 140 nsec
// 3,011 usec: cntr = 4; nops 3 -> loop = 500 nsec
// 3,060 usec: cntr = 4; nops 4 -> loop = 550 nsec
// 3,391 usec: cntr = 8; nops 4 -> loop = 850 nsec
do
{
// __asm__("nop");
__asm__("nop");
__asm__("nop");
__asm__("nop");
} while (++Cntr_u16 < 4);
delayMicroseconds((m_PulsConfig_s.CompWidth_u16)); // - 3 to compensate for cpu execution times!
// Start puls timer to stop puls again!
FastDigWriteOff(OUT_HS_Plus);
FastDigWriteOff(OUT_HS_Min);
FastDigWriteOff(OUT_LS_Plus);
FastDigWriteOff(OUT_LS_Min);
PulsActive_b = !PulsActive_b;
// Increase peak counter
PeakCntr_u16 += 1;
}
}