управление движками ч/з сдвиговый регистр 74НС595
- Войдите на сайт для отправки комментариев
Пт, 13/01/2017 - 14:49
интересует возможность управления 8-ми двигателями в одном напралении и с одной скоростью с помощью Motor shield L293D.код взят от сюда...http://playground.arduino.cc/Main/AdafruitMotorShield перепахан и все равно не работает.Пхните ногой куда копать з сдвиговіми регистрами пока играюсь.спасибо!!
#include <AFMotor.h> // Arduino pins for the shift register #define MOTORLATCH 12 #define MOTORCLK 4 #define MOTORENABLE 7 #define MOTORDATA 8 // 8-bit bus after the 74HC595 shift register // (not Arduino pins) // These are used to set the direction of the bridge driver. #define MOTOR1_A 2 #define MOTOR1_B 3 #define MOTOR2_A 1 #define MOTOR2_B 4 #define MOTOR3_A 5 #define MOTOR3_B 7 #define MOTOR4_A 0 #define MOTOR4_B 6 // Arduino pins for the PWM signals. #define MOTOR1_PWM 11 #define MOTOR2_PWM 3 #define MOTOR3_PWM 6 #define MOTOR4_PWM 5 // Codes for the motor function. #define FORWARD 1 #define RELEASE 2 void setup() { Serial.begin(9600); Serial.println(" Motor Shield Go!!"); } void motor(int nMotor, int command, int speed) { int motorA, motorB; if (nMotor >= 1 && nMotor <= 4) { switch (nMotor) { case 1: motorA = MOTOR1_A; motorB = MOTOR1_B; break; case 2: motorA = MOTOR2_A; motorB = MOTOR2_B; break; case 3: motorA = MOTOR3_A; motorB = MOTOR3_B; break; case 4: motorA = MOTOR4_A; motorB = MOTOR4_B; break; default: break; } switch (command) { case FORWARD: motor_output (motorA, HIGH, speed); motor_output (motorB, LOW, -1); // -1: no PWM set break; case RELEASE: motor_output (motorA, LOW, 0); // 0: output floating. motor_output (motorB, LOW, -1); // -1: no PWM set break; default: break; } } } void motor_output (int output, int high_low, int speed) { int motorPWM; switch (output) { case MOTOR1_A: case MOTOR1_B: motorPWM = MOTOR1_PWM; break; case MOTOR2_A: case MOTOR2_B: motorPWM = MOTOR2_PWM; break; case MOTOR3_A: case MOTOR3_B: motorPWM = MOTOR3_PWM; break; case MOTOR4_A: case MOTOR4_B: motorPWM = MOTOR4_PWM; break; default: // Use speed as error flag, -3333 = invalid output. speed = -3333; break; } if (speed != -3333) { // Set the direction with the shift register // on the MotorShield, even if the speed = -1. // In that case the direction will be set, but // not the PWM. shiftWrite(output, high_low); // set PWM only if it is valid if (speed >= 0 && speed <= 255) { analogWrite(motorPWM, speed); } } } // --------------------------------- // shiftWrite // // The parameters are just like digitalWrite(). // // The output is the pin 0...7 (the pin behind // the shift register). // The second parameter is HIGH or LOW. void shiftWrite(int output, int high_low) { static int latch_copy; static int shift_register_initialized = false; if (!shift_register_initialized) { // Set pins for shift register to output pinMode(MOTORLATCH, OUTPUT); pinMode(MOTORENABLE, OUTPUT); pinMode(MOTORDATA, OUTPUT); pinMode(MOTORCLK, OUTPUT); // Set pins for shift register to default value (low); digitalWrite(MOTORDATA, LOW); digitalWrite(MOTORLATCH, LOW); digitalWrite(MOTORCLK, LOW); // Enable the shift register, set Enable pin Low. digitalWrite(MOTORENABLE, LOW); // start with all outputs (of the shift register) low latch_copy = 0; shift_register_initialized = true; } // The defines HIGH and LOW are 1 and 0. // So this is valid. bitWrite(latch_copy, output, high_low); digitalWrite(MOTORLATCH, LOW); shiftOut(MOTORDATA, MOTORCLK, MSBFIRST, latch_copy); digitalWrite(MOTORLATCH, HIGH); } void loop(){ }
Копать в луп. Он пуст и это плохо.
Разобрался сам,кому интересно то пишите ))
Мне интересно, чего вышло то?
А вышло управление 8-ми двигателями отдельно,управление ч/з терминал или ком порт.всё работает,всё крутится.кстати можно сделать схему и без шилда,просто для эксперемента попробывал шилд.