sábado, 30 de agosto de 2014

Control Stepper Motor Speed with Labview and Arduino

Control Stepper Motor Speed with Labview and Arduino

 

http://arduiny.com/control-stepper-motor-speed-with-labview-and-arduino/


By: Ahmed Abseed     For: arduiny.com
This Tutorial Is:
  • > Using Labview to interface Arduino to PC via USB port.
  • > Using Labview to send data that describes Motor Speed to Arduino without any toolkits.
  • > Solving the problem of Arduino serial port hanging.
  • > Using Arduino to generate Stepping pulses.
  • > Using Arduino Mega’s Serial port 1 to show stepper motors speed on a serial LCD.

                   The best way to interface Arduino to PC is via its USB port. Arduino uses virtual Serial COM port to interface its USB connector to PC. At the same time Arduino uses its USB to interface its own serial (USART) port…. Bravo Arduino!!!
                   To send data to Arduino from your computer just connect it to USB port and use a program that can deal with computers serial port. This program can be Aeduino Serial port monitor, MIKRO C Serial terminal tool, PIC MP-LAB, or a program you establish. The one you build on yourself can be made by using a programming language like C, C#, C++, Python, Basic, NI-LABVIEW… etc.
                    Your own program not only has the advantage of interfacing the port, but performing a specific mission you need in your project as well. And so I do down here.
1-    In Labview (any version) establish the following front panel.
control stepper motor speed with labview and arduino
2-    Establish the following block diagram. (click to enlarge)
control stepper motor speed with arduino and labview
And here is the another case of (if) statement.
control stepper motor speed
This virtual instrument:
  • > Starts communication with Arduino.
  • > Detects if there is a change in control knob value.
  • > If there is a change it sends the new value to Arduino.
  • > Else, it clears serial port Input/output register to avoid data overflow and serial port overloading.
  • > When pressing STOP, it sends “0” (brake or hold order) to Arduino.

3-  In Arduino software, type the following code.
//By: Ahmed Abseed For: arduiny.com
// This Sketch receives a byte from serial port represents the
//delay time value between stepping sequence pulses
// It still works till another byte is sent to arduino’s serial port.
// It also Calculates Motor speed and sends it to another Serial Port.
byte labview;
unsigned int wait;  
byte go;
void setup(){
Serial.begin(9600);
Serial1.begin(9600);
pinMode(7,OUTPUT); pinMode(8,OUTPUT);
pinMode(9,OUTPUT); pinMode(10,OUTPUT);}
void loop(){
start:
if (Serial.available()) { labview = Serial.read();
if(labview!=’0′) { wait = (labview-48); show();}
else {brake(); goto start;}}
else {
digitalWrite(7,HIGH); digitalWrite(8,LOW);
digitalWrite(9,LOW); digitalWrite(10,LOW);
delay(wait);
digitalWrite(7,LOW); digitalWrite(8,HIGH);
digitalWrite(9,LOW); digitalWrite(10,LOW);
delay(wait);
digitalWrite(7,LOW); digitalWrite(8,LOW);
digitalWrite(9,HIGH); digitalWrite(10,LOW);
delay(wait);
digitalWrite(7,LOW); digitalWrite(8,LOW);
digitalWrite(9,LOW); digitalWrite(10,HIGH);
delay(wait);}}
void show() {
Serial1.write(254); Serial1.write(1); delay(4);
Serial1.print(“Speed = “); Serial1.print(300/wait); Serial1.print(” rpm”);}
void brake() {
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
digitalWrite(10,LOW);}
This Arduino Sketch:
  • Checks if labview sent a new value.If there is a new value, it converts it into integer byte with the same value.This integer byte represents the delay interval used in stepping sequence. That, the greater the delay the lower the speed and vice versa.
  • Else, Arduino continue running the motor at current speed. This prevents the processor from overloading the serial port and pushes it to avoid Arduino Serial port hanging… Bravo Arduiny.com.
  • Calculates motor speed from its resolution and delay intervals between steps as following:
Rpm = (60 x 1000 x step angle) / (360 x (delay m.sec))
Rpm = (1000 x step angle) / (6 x (delay in msec))
 I used a 1.8 deg/step motor in this project and so:
Rpm = 300 / (delay in msec)
  • Sends the calculated motor speed to another Serial port of Arduino Mega to show if our code works.
4-    I simulated this tutorial with PROTEUS and worked perfectly.
5-    In real application, it controlled my stepper motor perfectly on the long run.
control stepper motor speed with arduino and labview

1 comentario:

  1. As you knowledge...
    When i copy and paste the code, appears a several error on compile.
    The solution is change the "" on serial1.print lines and ' in the if(labview!='0' line
    good luck

    ResponderEliminar