Digital pin difference between Teensy and Arduino?

Status
Not open for further replies.

stysis

New member
Hi
I've used Teensys for several project but this is my first time in the forum. Hope I can get an answer to this problem which has me stumped.
I'm trying to run a stepper motor using AccelStepper and a DIV268N driver and have it happily running as it should through an Arduino but not with a Teensy 3.1.

I am running a modification the ConstantSpeed example sketch.
Code:
// ConstantSpeed.pde
// -*- mode: C++ -*-
//
// Shows how to run AccelStepper in the simplest,
// fixed speed mode with no accelerations
/// \author  Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2009 Mike McCauley
// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// HY-DIV268N-5A driver
AccelStepper stepper(1,13,12);

void setup()
{  
   stepper.setMaxSpeed(1000);
   // 7.5 degree steppper motor = 48 steps/turn,
   // driver set to 1/8 step so should turn 1 rev/second
   stepper.setSpeed(48*8);	
   // Increase pulse width
   stepper.setMinPulseWidth(100);
   // Set another pin high to see if it can move the motor
   pinMode(11,OUTPUT);
   digitalWrite(11,HIGH);
}

void loop()
{  
   stepper.runSpeed();
}

This code does what it should when run on an Arduino Uno, rotating the motor at 60 rpm. But when run on the Teensy 3.1 I get no movement.

Here's the wiring setup:
PULSE+ from Driver --> Pin 13, DIR+ --> Pin 12, PULSE- and DIR- --> GND. All other pins are not connected.

I have confirmed that pin 13 isn't dead and have tried other pins anyway.
If I touch the PULSE+ wire to the 3.3V Teensy pin I can get the motor to move erratically as expected. Same if I touch to 3.3V or 5V from my breadboard power supply.
But when I touch the PULSE+ wire to pin 11 which I have set to HIGH I get no movement with the Teensy but it moves with the Arduino.

My thinking is that perhaps the current from the Teensy digital pins is inadequate to trigger the 4N25 optocouplers in the driver. I had a look at the datasheet for these but my electronics knowledge isn't up to working out what it all means!

Any thoughts on what the problem might be would be appreciated.
Thanks.
 
The Teensy pins do have a power drive current than a classic Arduino, both because of the lower voltage and the smaller driver transistors. The normal current limit is ~20mA and the data sheet seems to indicate a design current of 50 so this may have something to do with it.

Suggestion is to use a multimeter (or failing that a LED+resistor) to check the pins are still capable of toggling, which I think you have already done, than try and measure the voltage on the pin with the stepper driver connected. Suspect the voltage is drooping enough that the current falls to something the Teensy can handle without failing but also not enough to get the stepper to step.

If that's the case then the right answer is a transistor + resistor setup, but depends a bit on the setup on the driver board for how that should be wired.
 
If your device is like
http://wiki.kreitek.org/_media/proyectos:cnc:div268n-5a-datasheet.pdf
Then it looks like it's intended for 5V operation with page 4 giving resistors for 12 or 24 V.
So the basic way to do it is wire for 5V operation using transistors to turn 3.3V into 5V pretty much as shown on the diagram, though since it's a true isolator you could make it a bit simpler and put the transistors on the low side where it's easier to drive them from a 3.3V output.

That said the drawing show a 270 ohm resistor in series with the opto for 5V operation. Page two of the data sheet for the opto specs a 1.3V voltage drop (probably an IR diode) for the diode itself. 5V-1.3V = 3.7V on the resistor. Ohms law gives 3.7V/270 ohms = 0.0137A or 13.7 mA actual current (not the 50mA in the data sheets). Which is within spec for the Teensy if you are careful. So an option is to swap out that resistor inside the driver module.

3.3V-1.3V = 2V across new resistor. target Current is 0.0137 so 2V/0.0137= 145ohm resistor. So using a 150 ohm standard resistor should give you almost the same current (and therefore brightness) as the original 270ohm on 5V while not pushing the teensy past it's limits. Note you can also hit the max current Per teensy IC as well if you try and drive to many pins at close to their max rating so this only works if the plan has one or two drivers wired.

In this case it suggests that the original problem is that the opto is just barely triggering on true 3.3V, but the slightly lower pin voltage is not getting enough current to reliably turn on the opto. Note the above surgery voids all warranties and shouldn't be undertaken unless you understand what you are doing and have double checked the numbers above against what is actually in front of you. Reality trumps theory from some random guy on the internet every time.
 
Hi GremlinWrangler.
Thanks for your insights.
My driver is exactly the one you indicated but I didn't replace the 270 Ohm resistor (which is an SMD) but rather put a 330 Ohm resistor in parallel with it giving me close to 150 Ohm.
It is now working beautifully with the Teensy!
Reality has shown that this random guy from the internet had the right theory.
Cheers.
 
Glad to hear you got it working, and succeeded in hacking a SMD design to your bidding. Always a little bit exciting when you dive into things at that scale.
 
Here's my hack. Not pretty soldering but very effective. Thanks again.

Stepper driver hack.jpg
 
Status
Not open for further replies.
Back
Top