A newbie question.
I am writing a basic routine to control a stepper driver chip using my Teensy 2.0.
I have several outputs which I want to initialize to a specific value (High or Low)
just once at the beginning of my routine. I don't want to write the values each time I go through the main loop.
It's not clear to me how best to do this.
Is there a way to do this in the setup section?
Below is my sketch so far.
For example, I want to set MS1, MS2 outputs to be Low, Low for starters.
Can I insert digitalWrite() commands in the setup() section to do this? I am not sure if this is allowed.
Thx.
I am writing a basic routine to control a stepper driver chip using my Teensy 2.0.
I have several outputs which I want to initialize to a specific value (High or Low)
just once at the beginning of my routine. I don't want to write the values each time I go through the main loop.
It's not clear to me how best to do this.
Is there a way to do this in the setup section?
Below is my sketch so far.
For example, I want to set MS1, MS2 outputs to be Low, Low for starters.
Can I insert digitalWrite() commands in the setup() section to do this? I am not sure if this is allowed.
Thx.
Code:
// RA stepper drive for Vixen GP mount
// Uses MP6500 stepper driver chip to drive the Vixen MT-1 motors
// in bipolar mode.
// Desired step period is 103.8822 ms (103882 usec) for full step
//
// Inputs needed:
//
// Outputs needed:
// MS1,MS2 Micro-stepping control (full, half, quarter, eighth)
// STEP Pulse to step the driver, 1usec min time
// DIR Direction of rotation
//***********************************************************************
// Pin assignments for Teensy 2.0:
//
int STEPpin = 13; // pin 13 for STEP pulse to stepper driver
int LEDpin = 11; // pin 11 used for LED drive
int DIR = 16; // pin 16 for DIR output
int MS2 = 14; // pin 14 for MS2 output
int MS1 = 15; // pin 15 for MS1 output
int PADdly = 782; // Pad delay in usec to loop to make Sidereal rate. This may be tweaked later.
//
void setup()
{
pinMode(LEDpin, OUTPUT); // LED drive. Not sure I will use LED.
pinMode(STEPpin, OUTPUT); // STEP output signal
pinMode(MS2, OUTPUT);
pinMode(MS1, OUTPUT);
pinMode(DIR, OUTPUT);
}
void loop()
{
digitalWrite(STEPpin, HIGH); // 100 usec STEP pulse
delayMicroseconds(100);
digitalWrite(STEPpin, LOW);
delay(103); // 103 ms delay
delayMicroseconds(PADdly); // delay pad to make 103882 usec loop period
}
Last edited: