NativeEthernet Interrupts TeensyStep4

colin_m

Member
Hi,

I've made a PCB with a Teensy 4.1 that I want to use to control 10 stepper motors. The motors need to move fast and synchronized, so I am hoping to be able to use the TeensyStep4 library (even though I know it isn't fully supported for the Teensy 4.1 yet). The Teensy 4.1 also needs to communicate with a PLC over Ethernet (I want to use Modbus TCP). I have written code to test the operation of the TeensyStep4 library with a group of 10 stepper motors and it works fantastically well. However, as soon as I initiate the Ethernet object to create an Ethernet link (line 105 in the code), the movement of the stepper motors is affected. It seems like there are interruptions in the pulse trains and this causes the stepper motors to stutter in their movements. If I just comment out this single line, then the stepper motors work perfectly again, so I am pretty sure that the problem lies somewhere there, but I don't really have an idea where to start looking. If someone could point me in the right direction, I would really appreciate it.

I am using PlatformIO on Windows 10 to develop the code for the Teensy 4.1.

My test code is attached.

Thanks very much.
 

Attachments

  • Stepper Test.txt
    7.8 KB · Views: 30
No, I don't know. And I don't really know where to start looking either. I've had a look at some of the NativeEthernet files and there is an IntervalTimer that gets used for polling, but that's all that I could see. Is it possible to change which interrupts TeensyStep4 uses? Perhaps I could try that?
 
No, I don't know. And I don't really know where to start looking either. I've had a look at some of the NativeEthernet files and there is an IntervalTimer that gets used for polling, but that's all that I could see. Is it possible to change which interrupts TeensyStep4 uses? Perhaps I could try that?

I'll have a look. Your test program works without something connected to the ethernet port, right?
 
I'll have a look. Your test program works without something connected to the ethernet port, right?

I have just always had an Ethernet cable plugged in, so I wasn't sure. I unplugged it now and restarted the program and it does hang until the Ethernet cable is plugged in again.
 
Just a suggestion, but rather than debug with NativeEthernet, try with QNEthernet, which is now better supported, and go from there.
 
Ok, looks like I can reproduce that.

Screenshot 2022-10-15 191848.jpg

Every couple of 100ms something blocks for about 13ms. The sequence at 0.85s is the normal deceleration /acceleration. I'll have a closer look but it may take until tomorrow.
 
Last edited:
Can you try to add the NVIC_SET_PRIORITY line in teensystep4.cpp as shown below?

Code:
#pragma push_macro("abs")
#undef abs

#include "teensystep4.h"
#include "timers/timerfactory.h"
#include "timers/interfaces.h"
#include "timers/Teensy4/TMR/TMR.h"


namespace TS4
{
    void begin(bool useDefaultModule)
    {
        if(useDefaultModule)
        {
            TimerFactory::attachModule(new TMRModule<3>());
            NVIC_SET_PRIORITY(IRQ_QTIMER4, 16);
        }
    }
}
#pragma pop_macro("abs")

This makes things work on the stepper side. But I don't know if it will confuse the Ethernet lib. I agree with joepasquariello, QNEthernet might be a better solution. Let me know if it works for you.
 
Thanks very much for your quick reply, luni. Adding that line of code to teensystep4.cpp definitely solved the problem. I feel much better now that I have a working solution, but I will take a look at the QNEthernet library now too.
 
Back
Top