- Sat Apr 29, 2017 4:51 am
#194596
Hi,
I still have a bunch of the old AutoDriver Board (v10) left and I really would like to use them as long as possible.
In the new software library it states that the new software can be used with the old board.
I have daisy chained 3 AutoDriver Boards (v10) connected to an Arduino Mega.
But whatever I do, I can only control the first AutoDriver in the chain, the other two boards remain a misery to get moving.
I can only suppose that there is something wrong with the initialization of the boards or the pinning definition.
Any help/suggestion would really be appreciated.
I still have a bunch of the old AutoDriver Board (v10) left and I really would like to use them as long as possible.
In the new software library it states that the new software can be used with the old board.
I have daisy chained 3 AutoDriver Boards (v10) connected to an Arduino Mega.
But whatever I do, I can only control the first AutoDriver in the chain, the other two boards remain a misery to get moving.
I can only suppose that there is something wrong with the initialization of the boards or the pinning definition.
Any help/suggestion would really be appreciated.
Code: Select all
#include <SparkFunAutoDriver.h> // using v.13 of the library
#define SERIAL_BAUD_RATE 115200
#define MOTOR_A_REFERENCE_SENSOR_PIN 2 // first motor driver
#define MOTOR_B_REFERENCE_SENSOR_PIN 3 // second motor driver
#define MOTOR_C_REFERENCE_SENSOR_PIN 4 // third motor driver
// UNO SPI: 12 (MISO), 11 (MOSI), 13 (SCK), 10 (SS)
// MEGA SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS)
#define SLAVE_SELECT_PIN 53 // Wire this to the CSN (SS) pin
#define MOSI 51 // Wire this to the SDI pin
#define MISO 50 // Wire this to the SDO pin
#define SCK 52 // Wire this to the SCK pin
#define RST 49
AutoDriver motor_a_driver(2, 53, RST); // first board in the chain, Position, CSN (SS) pin, and reset pin
AutoDriver motor_b_driver(1, 48, RST); // second board
AutoDriver motor_c_driver(0, 47, RST); // third board
const int MOTOR_CALIBRATION_STEPS_PER_SEC = 5;
const int MOTOR_RUNNING_STEPS_PER_SEC = 450; //450 ok @220KVAL - 350 ok - 300 ok @170KVAL - 200 160 150 140 70 @70KVAL @128FS
const int MOTOR_STEP_FS = STEP_FS_16;
const uint32_t NUM_STEPS_FOR_ONE_MOVEMENT = 10000; // this can be maximum 22bit
const uint32_t SAFETY_DISTANCE_STOP_BEFORE_COMPLETION = 600;
const int MOTOR_CALIBRATE_DIR = REV;
const int MOTOR_OPEN_DIR = FWD;
const int MOTOR_CLOSE_DIR = REV;
// ************************************ SETUP ***************************************** //
void setup() {
Serial.begin(SERIAL_BAUD_RATE);
Serial.println("INFO: Setup started...");
pinMode(SLAVE_SELECT_PIN, OUTPUT);
digitalWrite(SLAVE_SELECT_PIN, HIGH);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SCK, OUTPUT);
pinMode(RST, OUTPUT);
digitalWrite(RST, HIGH);
digitalWrite(RST, LOW);
digitalWrite(RST, HIGH);
// initialize SPI for the dSPIN chip's needs:
// most significant bit first,
// SPI clock not to exceed 5MHz,
// SPI_MODE3 (clock idle high, latch data on rising edge of clock)
SPI.begin();
//SPI.setBitOrder(MSBFIRST);
//SPI.setClockDivider(SPI_CLOCK_DIV16); // or 2, 8, 16, 32, 64
SPI.setDataMode(SPI_MODE3);
pinMode(48, OUTPUT);
pinMode(47, OUTPUT);
// Sensors
pinMode(MOTOR_A_REFERENCE_SENSOR_PIN, INPUT_PULLUP);
pinMode(MOTOR_B_REFERENCE_SENSOR_PIN, INPUT_PULLUP);
pinMode(MOTOR_C_REFERENCE_SENSOR_PIN, INPUT_PULLUP);
// Calibration
configureStepMotorBoards();
Serial.print("Motor Driver A status: 0x"); Serial.println(motor_a_driver.getStatus(), HEX);
Serial.print("Motor Driver B status: 0x"); Serial.println(motor_b_driver.getStatus(), HEX);
Serial.print("Motor Driver C status: 0x"); Serial.println(motor_c_driver.getStatus(), HEX);
calibrateStepMotors(MOTOR_CALIBRATION_STEPS_PER_SEC);
Serial.println("INFO: Setup completed");
}
void calibrateStepMotors(int stepPerSecSpeed) {
Serial.println("INFO: Motor Driver A, calibration started...");
if ( !isSwitchActivated(MOTOR_A_REFERENCE_SENSOR_PIN) ) {
motor_a_driver.goUntil(RESET_ABSPOS, MOTOR_CALIBRATE_DIR, stepPerSecSpeed); // Motion operation
while( !isSwitchActivated(MOTOR_A_REFERENCE_SENSOR_PIN) );
}
else {
Serial.println("INFO: Motor Driver A, no need to calibrate");
}
motor_a_driver.hardStop();
motor_a_driver.resetPos();
Serial.println("INFO: Motor Driver A, calibration completed");
delay(2000);
Serial.println("INFO: Motor Driver B, calibration started...");
if ( !isSwitchActivated(MOTOR_B_REFERENCE_SENSOR_PIN) ) {
motor_b_driver.goUntil(RESET_ABSPOS, MOTOR_CALIBRATE_DIR, stepPerSecSpeed);
while( !isSwitchActivated(MOTOR_B_REFERENCE_SENSOR_PIN) );
}
else {
Serial.println("INFO: Motor Driver B, no need to calibrate");
}
motor_b_driver.hardStop();
motor_b_driver.resetPos();
Serial.println("INFO: Motor Driver B, calibration completed");
delay(2000);
Serial.println("INFO: Motor Driver C, calibration started...");
if ( !isSwitchActivated(MOTOR_C_REFERENCE_SENSOR_PIN) ) {
motor_c_driver.goUntil(RESET_ABSPOS, MOTOR_CALIBRATE_DIR, stepPerSecSpeed);
while( !isSwitchActivated(MOTOR_C_REFERENCE_SENSOR_PIN) );
}
else {
Serial.println("INFO: Motor Driver C, no need to calibrate");
}
motor_c_driver.hardStop();
motor_c_driver.resetPos();
Serial.println("INFO: Motor Driver C, calibration completed");
delay(2000);
}
/* Go number of steps and then very slowly until sensor is hit */
void openMotors() {
motor_a_driver.move(MOTOR_OPEN_DIR, NUM_STEPS_FOR_ONE_MOVEMENT);
while (motor_a_driver.busyCheck());
}
void closeMotors() {
motor_a_driver.move(MOTOR_CLOSE_DIR, NUM_STEPS_FOR_ONE_MOVEMENT - SAFETY_DISTANCE_STOP_BEFORE_COMPLETION);
while (motor_a_driver.busyCheck());
}
void configureStepMotorBoards(void) {
//motor_a_driver.SPIPortConnect(&SPI); // Before doing anything else, we need to
//motor_b_driver.SPIPortConnect(&SPI); // tell the objects which SPI port to use.
//motor_c_driver.SPIPortConnect(&SPI); // tell the objects which SPI port to use.
motor_a_driver.configSyncPin(BUSY_PIN, 0);
motor_a_driver.configStepMode(MOTOR_STEP_FS); // STEP_FS = 0 microsteps per step STEP_FS_X, X can be 2, 4, 8, 16, 32, 64, or 128.
motor_a_driver.setMaxSpeed(MOTOR_RUNNING_STEPS_PER_SEC); // 10000 steps/sec max
motor_a_driver.setFullSpeed(MOTOR_RUNNING_STEPS_PER_SEC); // microstep below 10000 steps/s (not used if microstepping disabled)
motor_a_driver.setAcc(MOTOR_RUNNING_STEPS_PER_SEC); // accelerate at 10000 steps/s/s
motor_a_driver.setDec(MOTOR_RUNNING_STEPS_PER_SEC);
motor_a_driver.setSlewRate(SR_530V_us); // Upping the edge speed increases torque.
motor_a_driver.setOCThreshold(OC_6000mA); // OC threshold 750mA
motor_a_driver.setPWMFreq(PWM_DIV_2, PWM_MUL_2); // 31.25kHz PWM freq
motor_a_driver.setOCShutdown(OC_SD_DISABLE); // don't shutdown on OC. OC_SD_DISABLE and OC_SD_ENABLE
motor_a_driver.setVoltageComp(VS_COMP_ENABLE); // don't compensate for motor V
motor_a_driver.setSwitchMode(SW_USER); // Switch is not hard stop
motor_a_driver.setOscMode(INT_16MHZ_OSCOUT_16MHZ);
// When a KVAL setting is N, the current for that mode of operation (run, hold, accel or decel) will be effectively
// (N/255) * V / R, where V is the supply voltage and R is the motor winding resistance.
motor_a_driver.setAccKVAL(220); // We'll tinker with these later, if needed.
motor_a_driver.setDecKVAL(220);
motor_a_driver.setRunKVAL(220);
motor_a_driver.setHoldKVAL(50); // This controls the holding current; keep it low.
Serial.println("INFO: Motor Driver A, configuration completed");
motor_b_driver.configSyncPin(BUSY_PIN, 0);
motor_b_driver.configStepMode(MOTOR_STEP_FS);
motor_b_driver.setMaxSpeed(MOTOR_RUNNING_STEPS_PER_SEC);
motor_b_driver.setFullSpeed(MOTOR_RUNNING_STEPS_PER_SEC);
motor_b_driver.setAcc(MOTOR_RUNNING_STEPS_PER_SEC);
motor_b_driver.setDec(MOTOR_RUNNING_STEPS_PER_SEC);
motor_b_driver.setSlewRate(SR_530V_us);
motor_b_driver.setOCThreshold(OC_6000mA);
motor_b_driver.setPWMFreq(PWM_DIV_2, PWM_MUL_2);
motor_b_driver.setOCShutdown(OC_SD_DISABLE);
motor_b_driver.setVoltageComp(VS_COMP_ENABLE);
motor_b_driver.setSwitchMode(SW_USER);
motor_b_driver.setOscMode(EXT_16MHZ_OSCOUT_INVERT);
motor_b_driver.setAccKVAL(220);
motor_b_driver.setDecKVAL(220);
motor_b_driver.setRunKVAL(220);
motor_b_driver.setHoldKVAL(50);
Serial.println("INFO: Motor Driver B, configuration completed");
motor_c_driver.configSyncPin(BUSY_PIN, 0);
motor_c_driver.configStepMode(MOTOR_STEP_FS);
motor_c_driver.setMaxSpeed(MOTOR_RUNNING_STEPS_PER_SEC);
motor_c_driver.setFullSpeed(MOTOR_RUNNING_STEPS_PER_SEC);
motor_c_driver.setAcc(MOTOR_RUNNING_STEPS_PER_SEC);
motor_c_driver.setDec(MOTOR_RUNNING_STEPS_PER_SEC);
motor_c_driver.setSlewRate(SR_530V_us);
motor_c_driver.setOCThreshold(OC_6000mA);
motor_c_driver.setPWMFreq(PWM_DIV_2, PWM_MUL_2);
motor_c_driver.setOCShutdown(OC_SD_DISABLE);
motor_c_driver.setVoltageComp(VS_COMP_ENABLE);
motor_c_driver.setSwitchMode(SW_USER);
motor_c_driver.setOscMode(EXT_16MHZ_OSCOUT_INVERT);
motor_c_driver.setAccKVAL(220);
motor_c_driver.setDecKVAL(220);
motor_c_driver.setRunKVAL(220);
motor_c_driver.setHoldKVAL(50);
Serial.println("INFO: Motor Driver C, configuration completed");
}
// ************************************ LOOP ***************************************** //
void loop () {
}
void serialEvent() {
while(Serial.available()) {
unsigned char data = Serial.read();
if ( data == 'O' ) {
openMotors();
}
else if ( data == 'C' ) {
closeMotors();
}
else {
Serial.print("ERROR: Received corrupt data: ");
Serial.println(data);
}
}
}
/* 0V at switchPin indicates that it has been activated.
Remember to set pinMode(buttonPin, INPUT_PULLUP); for those pins */
boolean isSwitchActivated(int switchPin) {
if ( digitalRead(switchPin) == LOW ) {
return true;
} else {
return false;
}
}