Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 16 of 16

Thread: Teensy 4.0 strange "resets/reboots" driving a Pololu DRV8825

  1. #1
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    85

    Teensy 4.0 strange "resets/reboots" driving a Pololu DRV8825

    Hi,

    i have a Teensy 4.0 attached to a DRV8825 Stepper Driver using the minimal wiring diagram from here:

    https://www.pololu.com/product/2133

    The driver is connected to the Teensy using the pins 3V/GND/5/6.

    Motor is a SM-42BYG011-25 (SparkFun / others) 12V/0.33A using it's own wall plug psu.

    This basically works ok, but after running a test program for some minutes, the motor starts erratic behaviour and the Teensy seems to reboot / reflash itself. Sometimes this happens in short intervals. Even sometimes the Teensy "flasher" shows "Error" or some Bootloader warning. Connections between Teensy and the DRV8825 are soldered so it's no breadboard installation. Teensy is powered using USB, behaviour also happens if an additional 3.7 V Accu is attached via Teensy Feather adapter. During the "reboots" it also seems to disconnect from the USB. Serial device is gone and OSX mentiones disconnect/connect of USB device.

    What's going on here? What could cause this "reboots"? How can i debug this?

    Using platformio and this packages:
    PACKAGES:
    - framework-arduinoteensy 1.152.0 (1.52)
    - toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)

    Code below.

    Best regards,

    Michael


    Code:
    /*
     Example sketch to control a stepper motor with A4988/DRV8825 stepper motor driver 
     and Arduino without a library. More info: https://www.makerguides.com 
     */
    #include <Arduino.h>
    
    // Define stepper motor connections and steps per revolution:
    #define dirPin 5
    #define stepPin 6
    #define stepsPerRevolution 200
    
    void setup() {
      Serial.begin(115200);
      // Declare pins as output:
      pinMode(stepPin, OUTPUT);
      pinMode(dirPin, OUTPUT);
      Serial.println("===============================================================");
      Serial.println("Setup done.");
      Serial.println("===============================================================");  
    }
    
    void step() {
      int d = 900; // 800 - 1000 is best
      
      digitalWriteFast(stepPin, HIGH);
      delayMicroseconds(d);
      digitalWriteFast(stepPin, LOW);
      delayMicroseconds(d);
    
    }
    
    void stepn(int n) {
      Serial.printf("Step n: %d ", n);
      uint32_t t1 = millis();
      for (int i = 0; i < n; i++) {
        step();
      }
      uint32_t elapsed = millis() - t1;
      Serial.printf("%dms\r\n", elapsed);
    }
    
    void loop() {
      Serial.println("Loop");
      // Set the spinning direction clockwise:
      Serial.println("Spin clockwise.");
      digitalWrite(dirPin, HIGH);
      stepn(stepsPerRevolution);
      Serial.println("Wait 1s...");
      delay(1000);
      yield();
      // Set the spinning direction counterclockwise:
      Serial.println("Spin counterclockwise.");
      digitalWrite(dirPin, LOW);
      stepn(stepsPerRevolution);
      Serial.println("Wait 1s...");
      delay(1000);
      yield();
      Serial.println("Ten rotations.");
      digitalWrite(dirPin, HIGH);
      stepn(stepsPerRevolution * 10);
      digitalWrite(dirPin, LOW);
      digitalWrite(stepPin, LOW);
      Serial.println("Wait 10s...");
      delay(10000);
      yield();
    }

  2. #2
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    85
    Further debugging with Serial4 and debugPrint revealed that in fact the Teensy is just rebooting. (Without any "error" message before). Unsure why it gets into that flash loop sometimes if a simple restart would do.

    Root cause i think might be a bad GND. Currently i'm unsure if i should use a common ground on the DRV8825 which basically means connect the motor GND to the logic GND. Is this a good idea or should i already order a new Teensy4. (Because common ground will kill it?)

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,943
    If TeensyLoader is Active and set to AUTO it will reprogram. That won't solve the problem - but Teensyloader will not interfere if closed or if the AUTO is disabled. Then it will either do a simple restart or hang in the bootloader RAWHid mode awaiting attention.

    If there is not an electrical issue just forcing a Teensy restart - there is a GDB debugger thread just started. It is easy enough to use from the IDE - not sure about PIO. Has an install that works well on MAC and Linux - nto sure about Windows - but I have a working solution to minimize hassle on Windows with IDE and TeensyDuino install- noted on that thread - but it could be all new for a PIO user.

  4. #4
    Senior Member
    Join Date
    Feb 2015
    Location
    Finland
    Posts
    215
    Ground potential difference (and thus a ground loop) is a likely culprit.

    A simple fix is to get yourself a cheap ADuM3160-based USB isolator between Teensy and the host computer. It will limit the USB communications to max 12 Mbit/s (about a megabyte per second in practice), but that should not be an issue. (They typically have a small DIP switch to select between 1 Mbit/s and 12 Mbit/s.) I have tested a Teensy 4.0 with cheap eBay clones and they work fine, because they're basically all just copies of the ADuM3160 reference implementation. The only component that varies is the DC-DC converter on them: typically, they don't provide more than about 200mA reliably.

    I do recommend the Olimex USB-ISO version, though: it has a separate +8 - +15 V DC jack, that can be used to supply up to 750mA at 5V to the USB device. This DC jack is connected to the USB device VCC and GND, but is isolated from the host computer. It can also provide about 200mA via an isolated DC-DC converter from the USB host computer when the DC jack is not used, which makes this one much more versatile than the typical ADuM3160 isolators.




    The reason I believe it is a ground potential issue, is that I've seen it crop up in similar situations for years. None of the motor controller boards use a motor ground isolated from the digital ground, which means that when connected via USB, there is a risk of a potential difference between USB ground and the motor power supply ground. (It tends to not be an issue with European style two-pronged, un-grounded supplies; but is an issue with properly grounded power supplies, I guess due to noise suppression X2 capacitors between proper ground and the 0V, which means that the host computer 0V and the power supply 0V may not be the same electrical potential at all.)

    This problem is common with CNC and 3D printer controller boards (including SmoothieBoards), if USB is used.

    Ethernet connectors include galvanic isolation (see e.g. MagJacks), and tend to not suffer from this at all.

    Another option is to isolate the step/direction lines optically or via digital isolators, so that USB ground and motor ground are kept separate.

  5. #5
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    990
    Without seeing your actual setup it is quite difficult to give advice. Here some general remarks.

    1. There is no need to connect motor ground and logical ground (don't do it, you'll catch a lot of motor noise which you don't really want)
    2. I had similar rebooting issues with a T4 when drawing too much current from the 5V pin for some attached things. Worked perfectly with a T3.2. Seems like the T4s are a bit picky on that. If you have additional stuff attached to the 5V output try to supply it externally.


    Not related to your reboot problems but the motor you chose is of the voltage controlled type. They are operated by applying a constant voltage (here 12V) to the coils. However, practically all modern stepper drivers are made to regulate current To get this motor working acceptably with a current controller like the DRV8825 you need to supply the driver with as much voltage as possible. IIRC the DRV8825 can be driven up to some 40V. Here https://luni64.github.io/TeensyStep/...cal-parameters some info on how to choose a stepper motor and how to interpret the datasheet parameters.
    Last edited by luni; 06-28-2020 at 08:52 AM.

  6. #6
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    85
    Thanks, very good hints. I think some GND potential issue causes the Teensy to brownout / reboot.

    @luni:

    I did not connect Motor GND to Digital GND but according to https://forum.pololu.com/t/drv8825-ground-pins/7785
    they are connected internally.

    Is there a better motor you could recommend for the drv8825?

    The actual setup is, like i mentioned above, the minimal wiring diagram from https://www.pololu.com/product/2133.

    The Teensy is connected via USB to a Macbook, Motor PSU is some 12V wall plug. Teensy GND is connected to the driver Digital GND and 3.3V is connected to RESET and SLEEP. DIR pin is Teensy 5, STEP pin is Teensy 6.

  7. #7
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    990
    Is there a better motor you could recommend for the drv8825?
    This obviously depends on your requirements. If I assume that you need something in the 0.2Nm range and you want a NEMA17 sized motor I'd have a look at something like

    17HS13-1334S 1.3A 22Ncm, 2.5mH, 2.8V
    17HS08-1004S, 1A, 16Ncm, 4.5mH, 3.5V

    Both should run nicely from a 12V powered DRV8825. For high speed applications you'd go for a 24V supply.

    For testing, connect DIR to GND, leave EN and the Mx pins unconnected and use a simple sketch like

    Code:
    void setup()
    {
        pinMode(0,OUTPUT);
    }
    
    void loop()
    {
        digitalWriteFast(0, HIGH);
        delayMicroseconds(10);
        digitalWriteFast(0, LOW);
        delay(10); 
    }
    BTW: The rated current is the max current. For testing the motor will run nicely and stay cool with much less current.

    Regarding your reboot issue: If you have a T3.2 available I'd give it a quick try.

  8. #8
    Senior Member
    Join Date
    Feb 2015
    Location
    Finland
    Posts
    215
    Quote Originally Posted by luni View Post
    There is no need to connect motor ground and logical ground (don't do it, you'll catch a lot of motor noise which you don't really want)
    Unfortunately, like I already mentioned most of the motor controller drivers (including DRV8825) and even CNC/3D printer boards like SmoothieBoard use a common ground for motors and logic.

    The only way you can avoid that is by using an isolator between Teensy and the motor controller.

  9. #9
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    990
    Very true of course

  10. #10
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    85
    Thanks for all for the help. I'm thinking about ordering some cheap optocouplers and experiment with these.
    Unfortunately i have no T 3.2 at hand but don't mind ordering one for experimentation.

    I will have a look at the two motors.

  11. #11
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    990
    Just for fun I did a quick test with a T4.0 and the code from #7. Used a DRV8825 and this carrier: https://github.com/luni64/DRV8825x3. 12V supply for the motors, Teensy is powered from USB. Runs as expected. No peculiarities. So, seems to be something wrong with your setup.


  12. #12
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    85
    Thanks for testing. Interesting fact is, i switched the Teensy with an ESP32 and it works without issues so far.

    Click image for larger version. 

Name:	IMG_4852.JPG 
Views:	6 
Size:	132.4 KB 
ID:	20779

  13. #13
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    990
    Weird. One addition, I powered the DRV8825 from the 5V from the Teensy not from 3.3V. Don't now which one you used.

  14. #14
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    85
    What do you mean with "powered the DRV8825"? You connected Teensys VIN to RESET and SLEEP of the DRV?
    I'm just wondering because in the polulu's diagram i used there is no VDD to the DRV8825. Just RESET/SLEEP.

    Did i miss something here?

  15. #15
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    990
    Ups, you are absolutely right. I'm so used to this carrier board (which uses VDD only for the mode_n jumpers) that I falsely assumed the driver actually needs it. So, forget #13. Sorry for the noise.

  16. #16
    Member
    Join Date
    Apr 2020
    Location
    Germany, NRW
    Posts
    85
    No issue, i'm thankful for the hints and tips and someone actually trying it out. Appreciate that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •