ivanseidel / ivanseidel/DueTimer

DueTimer and interrupt priority

Open
#79 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
217
Forks
87
PR merge metrics
No merged PRs in 30d

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(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;
}
}

```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the DueTimer timer interrupt setup and the Arduino Due interrupt handling relevant to Timer6 and USB communication. Determine whether per-timer interrupt priority can be exposed; done when Timer6 priority can be configured above the USB interrupt and the requested pulse-timing behavior is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.