luni64 / TeensyStep4

MIT License
17 stars 15 forks source link

Jitter while using vjmuzik/NativeEthernet #20

Open 22chrs opened 4 weeks ago

22chrs commented 4 weeks ago

Maybe you can help me giving a hint where to start finding and solving my problem. When using [NativeEthernet](https://github.com/vjmuzik/NativeEthernet -> this has as dependency: https://github.com/vjmuzik/FNET) for a websocket (via arduinoWebsocket lib) connection I get jitter when a stepper moves. Maybe a timer is used twice? The jitter is coming from the NativeEthernet I think.

after this is done once, we have the jitter in the system :(

teensyMAC(mac);  // Set the MAC address.

while (!Ethernet.begin(mac)) {
    Serial.println("Ethernet failed to initialize. Retrying in .5 seconds...");
    delay(500);  // Delay to allow time for the router or network to become available
}
22chrs commented 4 weeks ago

Done on a teensy 4.1

22chrs commented 3 weeks ago

Update. Same jitter also when using ssilverman/QNEthernet@^0.29.1 lib for ethernet. 😭

luni64 commented 3 weeks ago

Not very likely that the timer is used twice since this whould mess up TeensyStep completely. However, they might use another timer running at the same interrupt priority. Thus, the TeensyStep timer would be blocked while they serve their interrupt routine.

You can try to increase the priority of the TeensyStep timer in its constructor (file: Teensy4/TMR/TMR.h , starting at line 184). Add the priority line as shown below. Smaller numbers (multiples of 16) increase priorty, default is 128.

 //---------------------------------------------------------------------------
    template <unsigned moduleNr>
    TMRModule<moduleNr>::TMRModule()
    {
        //Serial.printf("TMRModule cstr %p %d\n", this, moduleNr);

        attachInterruptVector(tmrIRQs[moduleNr], ISR);
        NVIC_ENABLE_IRQ(tmrIRQs[moduleNr]);
        NVIC_SET_PRIORITY(tmrIRQs[moduleNr], 32);  //<- set timer priority
    };

    //---------------------------------------------------------------------------
22chrs commented 3 weeks ago

Thank you! I will try and report. 🙏

22chrs commented 3 weeks ago

10/10. Runs without any special incidents. Have you ever considered feeding an AI with your knowledge? 😬