Hello all. I am trying to run two steppers motors using an H-Bridge and a D-Type Flip Flop buffer to store the data in it and send it to the motors while the Arduino is doing another task. I attatch here my ciruit and the datasheet of the flip flop (I am using the 74LS373). The code I am currently using to test the flip flop is this one:
//H-Bridge pins and buffer
#define enablePin1 10 //Need to be PWM
#define in1Pin 9
#define in2Pin 8
#define enablePin2 6 //Need to be PWM
#define in3Pin 5
#define in4Pin 4
#define speed_motor 150 // Max speed=255
#define LE 7
void setup() {
//Declare pins
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(enablePin1, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
pinMode(enablePin2, OUTPUT);
//Motor speed
analogWrite(enablePin1, speed_motor);
analogWrite(enablePin2, speed_motor);
//Buffer in storing data mode
pinMode(LE, OUTPUT);
digitalWrite(LE,LOW);
Serial.begin(9600);
}
void loop() {
//Send data to buffer
Serial.println("Sending data to buffer to run");
runMotor(in1Pin, in2Pin, false,false);
runMotor(in3Pin, in4Pin, true,false);
//Wait some time
delay(7000);
//Running motor
Serial.println("Run Motor");
digitalWrite(LE,HIGH);
digitalWrite(LE,LOW);
delay(2000);
//Send data to buffer to stop motor
Serial.println("Sending data to buffer to stop");
runMotor(in1Pin, in2Pin, false,true);
runMotor(in3Pin, in4Pin, true,true);
delay(7000);
//Running motor
Serial.println("Stop Motor");
digitalWrite(LE,HIGH);
digitalWrite(LE,LOW);
}
void runMotor(int in1P, int in2P, boolean reverse,boolean stopmotor)
{
if (!stopmotor){
digitalWrite(in1P, ! reverse);
digitalWrite(in2P, reverse);
}
else{
digitalWrite(in1P, LOW);
digitalWrite(in2P, LOW);
}
}
I was wondering if it is possible to store the delays in the flip flop instead of making the Arduino to delay before activating the latch enable pin, and also the analog data about the speed motor.
I also have a problem with the current code since motors stop when the "Sending data to buffer to stop" message appears, while it should happen with the "Stop motor" message. All help is welcome. Thank you so much
sn74ls373_memory_buffer.pdf (1.56 MB)