Hi All
My first post. I read some of the info on first posts but if I missed something happy to go back and fill it in.
This is my first Arduino project, although I have done a bit with the old BASIC Stamp and BASICMicro chips years ago. I am an old guy. ![]()
The project is to install a stepper motor as the power feed for a small milling machine, x-axis. The motor is a NEMA23. The controller is a TB6600, driven by a 24vdc supply. The Arduino clone is a Smraza UNO
I have it working well, I think, but wondering how to calculate or get the RPM of the stepper, if possible. I have noticed that the speed of the motor is affected by how much info I print to the LCD since I put that in the middle of the loop, so, perhaps I came about that the wrong way? That was not a surprise to me when I did it but not sure how else to do it more efficiently.
I would like to be able to know the RPM so that I can calculate and display the feed speed of the table. (.100" per revolution of the motor). I have read a bit about the interrupts so I think it is something to do with that, but at my current level, a little above my head. If that is where I need to look, happy to go research more if you can tell me I am in the right area. I had it running ok, although the control made the speed a bit jumpy at places in the rotation of the pot. I blamed it on the potentiometer but then I installed the stepper library and it seems better. However, reading through some of the documentation, it seems that library is designed for 4 wire control, not a stepper controller so I am confused a bit as to whether or not it actually smoothed out my motor control. I don't think it should have made a difference in the stepper motor. I did not use any of the library commands. One other thing I have noticed is that the motor is smoother at higher pulse settings on the controller but also slower top speed. I am hoping that by making the program more efficient, I can utilize the higher pulse settings, although for my application, 800 is good. The only reason for higher speeds is to "jog" the table to one end or the other for setup. You would not machine at that speed.
Thanks for reading the backstory.
I would appreciate it if you can lead me in the right direction to...
Display the data on the LCD so as not to affect my motor speed
Retrieve data to be able to calculate RPM or (pulses in a time frame)?
General input on my programming is welcome (if you are gentle
) I am sure it is "clunky" and or inefficient but I am happy the motor is spinning with all of the controls working as expected.
Thank you
#include <LiquidCrystal.h>
#include <Stepper.h>
/*
LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11
LCD D4 pin to digital pin 4
LCD D5 pin to digital pin 5
LCD D6 pin to digital pin 6
LCD D7 pin to digital pin 7
LCD R/W pin to ground
10K resistor:
ends to +5V and ground
wiper to LCD VO pin (pin 3 on display!)
v 6600 motor controller set to 800
*/
int dirpinout = 3; //direction pin out to controller
const int dir_in = A2; //direction control pin in from switch
int dir = 1; // sets table direction initially CW is table left
int enablepin = 9; //enable pin out to controller
int enableout = 1; //sets motor off to start
int pulse = 2; // pulse out pin to controller
const int potin = A0; //speed pot connected to pin A0
int speedpulse = 500; // pulse delay for speed management
int runpin = A1; //run button enables or disables motor
int runn = 0; //sets runn to state of runpin (low to run)
int jogin = A3; //jog switch in
int jogout = 0; //jog out
const int limitpin = A4; //limit switch input
const int limitled = 13; // limit indicator connected to pin A5** may not be connected
int limit = 0; //limit switch state
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
//Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(limitpin, INPUT_PULLUP);
pinMode (dir_in, INPUT); // switch takes pin low, otherwise, pin is high due to pullup
pinMode (limitled, OUTPUT);
pinMode (enablepin, OUTPUT); //high to enable
pinMode (pulse, OUTPUT);
pinMode(dirpinout, OUTPUT); //high for clockwise ****check this
pinMode(runpin, INPUT); //Run button enables motor to run
pinMode(jogin, INPUT); //Jog button in
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}
void loop() {
limit = digitalRead(limitpin); //one to run, zero if at limit
digitalWrite(limitled, limit); //lights indicator
runn = digitalRead(runpin); //zero to run, one to not run
jogout = digitalRead(jogin);
dir = digitalRead(dir_in); //sets motor direction according to switch
digitalWrite(dirpinout,dir);
lcd.print("Speed___");
lcd.print(15000-speedpulse);
lcd.clear();
if (limit + runn == 2) // if run on and limit not reached, enable controller
{
digitalWrite(enablepin, LOW);
}
else if (limit + jogout == 2)
{
digitalWrite(enablepin, LOW); //if jog on and limit not reached, enable controller
}
else {
digitalWrite(enablepin, HIGH); //disable controller
}
speedpulse = analogRead (potin); //reads speed pot
speedpulse = map (speedpulse, 0, 1023, 0, 15000); //converts pot to speed delays
digitalWrite (pulse, HIGH); //pulses motor
delayMicroseconds(speedpulse); //delay
digitalWrite (pulse, LOW); //pulses motor off
delayMicroseconds(speedpulse); //delay
//Notes count pulse. 400 pulses = 1 revolution
//count time elapsed since start of counting and convert to seconds for rpm calculation
//calculate feed speed at 0.100"/revolution
}
