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

Thread: Teensy 4.0 two pins at the same time

  1. #1
    Junior Member
    Join Date
    Sep 2019
    Posts
    8

    Teensy 4.0 two pins at the same time

    Hey everyone,
    Iím trying to drive two steppers at the same time in a CoreXY system using a Teensy 4.0. As you might know the steppers need to move at the same time to go straight and I was wondering if using digitalWriteFast() will be enough. If not how can I do port manipulation with 4.0. Iím sorry if thereís an obvious way for this but I have not done it before and donít know where to start .
    Last edited by BlueTurtle; 10-04-2019 at 02:37 AM.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,913
    See if this leads to the right place : pjrc.com/threads/57717-port-and-toggle-question-T4

    Seems there was another thread - but found that first - it shows toggle - but might get to where the port write thread was.

    A pair of digitalWriteFast might generally get out on the same bus cycle.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,674
    digitalWriteFast() should be plenty fast enough. Even the slower digitalWrite() is probably fine.

    To keep a little perspective, consider the motor windings are basically inductors. The force applied to the rotor depends on the current. The current in an inductor is 1/L times the integral of the applied voltage. When you apply a fixed voltage, that means the current is a linear ramp with a slope of the voltage divided by the inductance. The key concept of this math is the current (and mechanical force) in the motor increases as a linear ramp.

    The delay of only nanoseconds between the 2 pins changing is tiny compared to the time that linear ramp takes to get the current up to the steady state.

    Of course, you can drive stepper motors in more exotic ways, where a much higher voltage is initially applied. Some very high performance drivers apply 50 volts or more to get the current up quickly, and then back off to a much lower voltage to maintain the desired current. If you're using a circuit like that with a pretty high voltage, I still would be skeptical that several nanoseconds would matter, but it would be worth investigating carefully.

    For ordinary fixed voltage driving on the coils, the current just can't change on a fast time scale anywhere near the time digitalWriteFast() takes.

  4. #4
    Junior Member
    Join Date
    Sep 2019
    Posts
    8
    Thank you both for your responses. Itís working very well with digitalWriteFast()

  5. #5
    Senior Member
    Join Date
    Oct 2012
    Location
    Portland OR
    Posts
    677
    I think T4 GPIO pins are on a 150 MHz clock, meaning sequential writes might be 6.67 nanoseconds apart.
    Choosing a random NEMA17 stepper, I find coil R,L specs at R=1.1 ohm and L=2.6 mH. The time constant of that motor coil is L/R = 2.4 msec, so if a drive signal is delayed by one T4 peripheral bus clock period (6.67 ns), that is three millionths of one coil time constant. Therefore, to make that delay significant, the inductance and resistance in your two motors must to be stable and matched at the 3 parts per million level, and I am pretty confident that is not the case.
    Just for reference, copper resistance goes up with temperature, and the resistance tempco of copper near room temp. is +0.393 percent per degree C. So if your motors have a temperature difference of *one* degree C, the relative time response has already changed about 1400 times more than the effect of one clock tick on the T4 GPIO bus.

  6. #6
    Junior Member
    Join Date
    Sep 2019
    Posts
    8
    Ahahahah I love this response. Thank you very much for your concise and meaningful response.

Posting Permissions

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