Accelstepper not moving closed loop stepper

Status
Not open for further replies.

jackson

Member
I am trying to control a closed loop stepper and driver with a teensy 4.0. I would like to use the accelstepper library, but thus far I can't get it to move the motor. When I run the first sketch below, the motor turns with speed controlled by the delay. When I try running the example accelstepper constant speed sketch nothing happens. I have also tried sourcing 5v and dropping the voltage before it gets back to the 3v tolerant pins, but no dice. Any ideas what could be causing the issue? Thanks.

Code:
#include <Arduino.h>

const int pulPin = 6;  // PUL
const int dirPin = 7; // DIR

void setup() {
  pinMode(pulPin,OUTPUT);
  pinMode(dirPin,OUTPUT);

  digitalWrite(dirPin,HIGH);
  delayMicroseconds(5);
}
void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(pulPin,HIGH);
  delayMicroseconds(200);
  digitalWrite(pulPin,LOW);
  delayMicroseconds(200);
}

Accelstepper example:
Code:
// ConstantSpeed.pde
#include <Arduino.h>
#include <AccelStepper.h>
AccelStepper stepper(1,6,7);
void setup()
{  
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(50);        
}
void loop()
{  
   stepper.runSpeed();
}

Picture of my wiring:

bGMpvSB.png

Link to driver manual:
https://drive.google.com/file/d/1MvoFV1bskU-Ns0xVLWQ15e_bsfoLMbrN/view
 
AccelStepper was written for slow microcontrollers and doesn't have enough delay for the
pulse generation.

Try
Code:
void setup()
{  
   stepper.setMinPulseWidth(15);
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(50);        
}
The library uses a default of 5µs, expecting the overheads to stretch this to at least 10µs required by most optocouplers.
The T4's overheads are a few tens of nanoseconds so this doesn't work.
 
Wow... one line fixed days of headache. Next time I'll start on this forum. Maybe the accelstepper page on the pjrc site should be updated with this bit of information? I didn't see any mention of it. Thanks!!
 
Status
Not open for further replies.
Back
Top