Notifications
Clear all

Large Stepper Code does not work

119 Posts
5 Users
10 Likes
8,044 Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@ralphxyz 

The values coming from the stepper is just the start. If you need a different range of possible values than 0,1,2,...199 then add some gears or a belt drive to transform the rotation to some convenient ratio.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@ralphxyz)
Member
Joined: 4 years ago
Posts: 61
Topic starter  

Thanks Will, that is a interesting thought. Of course I haven't the slightest idea how

to test it.

Ralph


   
ReplyQuote
(@ralphxyz)
Member
Joined: 4 years ago
Posts: 61
Topic starter  

Will, I am getting good results from your program. Except the Reverse does not latch with button push. Well sometimes it laches if I hold the button for 5 seconds or so. Also the speed does not increase like other programs.

Currently in my code I have:

pulseDelay = map(analogRead(spdPin),0,1023,5000,1);

I know a shortcoming of stepper motors is that they are noisy.

The motor at it's fastest speed is really noisy. I have other programs (my original code that worked) that do not make as much noise.

I need a good working RPM program to see the actual rpms.

Ralph


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@ralphxyz 

I replied a couple of pages back that you should NOT be using my sketch as your go-to version. It was merely intended as an intermediate form between two versions.

You should be using Bill's version as the "gold standard", not mine, as his version is intended for actual use.

There's no way that you'll be able to reach "1" in that map statement. The stepper probably cannot rotate at that step delay, especially if it's loaded. Also, any attempt to reverse the direction at high speed could potentially damage the stepper, your equipment or you. That stepper has a lot of inertia.

I believe that @davee explained that at higher speeds the stepping times need to be adjusted with the off period being up to three times as long as the on time (can't recall the exact source or rates).

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@ralphxyz)
Member
Joined: 4 years ago
Posts: 61
Topic starter  

Bill's and DaveE's code also do not rotate the motor as compared with the my original code

speed wise and are even noisier than your code.

This is the code that I am comparing: 

(The code tag is not working for me)

/* Example sketch to control a stepper motor with TB6600 stepper motor driver and Arduino
without a library: continuous rotation. More info:
https://www.makerguides.com
https://www.makerguides.com/tb6600-stepper-motor-driver-arduino-tutorial/
*/

// Define stepper motor connections:
#define dirPin 2
#define stepPin 7

void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);

// Set the spinning direction CW/CCW:
digitalWrite(dirPin, HIGH);
}

void loop() {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
//delayMicroseconds(500);
delayMicroseconds(20);
//delayMicroseconds(600);
//delayMicroseconds(700);
//delayMicroseconds(800);
//delayMicroseconds(1000);
//delayMicroseconds(1500);
//delayMicroseconds(2000);
//delayMicroseconds(2500);
//delayMicroseconds(3000);
//delayMicroseconds(5000);
//delayMicroseconds(7500);
//delayMicroseconds(10000);
//delayMicroseconds(15000);
digitalWrite(stepPin, LOW);
//delayMicroseconds(500);
delayMicroseconds(20);
//delayMicroseconds(600);
//delayMicroseconds(700);
//delayMicroseconds(800);
//delayMicroseconds(1000);
//delayMicroseconds(1500);
//delayMicroseconds(2000);
//delayMicroseconds(2500);
//delayMicroseconds(3000);
//delayMicroseconds(5000);
//delayMicroseconds(7500);
//delayMicroseconds(10000);
//delayMicroseconds(15000);
}

This code does not seem to distress the motor as Bill and DaveE's code seems to.

Your code has a lot of noise from the motor but it is a steady sound and does not sound distressed.

I like using the interrupt in your code also.

With delayMicroseconds(20); the motor is running quickly not as quick as other programs run and the motor does not sound stressed.

Ralph

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@ralphxyz FYI @davee

I'm surprised that it runs at all, 20 uSecs seems way too short.

If you write something like

int   stepDelay = 50;

void loop() {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(stepDelay);
}

Then you can vary the speed by just setting stepDelay to the number of uSecs you want. That way you won't have to keep duplicating the commands and commenting them back out all of the time.

What do you mean by "Bill's and DaveE's code also do not rotate the motor as compared with the my original code". Do they not change the motor speed ?

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@ralphxyz)
Member
Joined: 4 years ago
Posts: 61
Topic starter  

They do change the motor speed but erratically not smoothly, they will even go from running

fast to running slow back to running fast without my touching the Pot.

The motor stalls if I try delayMicroseconds(19);

I have thought of using an encoder to adjust delayMicroseconds().

You used: 

digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(pulseDelay);

In your code. 

Ralph

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@ralphxyz 

IIRC pulseDelay was set by the pot.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@ralphxyz 

To post code, you need to start off in the Arduino IDE and select the code you want. Then copy it as HTML in the Arduino IDE. Switch to the forum and select the post where you want to place the code. You should press the carriage return a couple of times to make a few blank lines in the forum post text.

Then click the "{;}" icon in the menu list across the top of the posting window. This will bring up the post in HTML format. You'll need to find the blank lines you entered, which will look like lines containing "<p></p>".

You need to position the cursor between these two lines and then paste the html Arduino text you copied.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@ralphxyz)
Member
Joined: 4 years ago
Posts: 61
Topic starter  

   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 
Posted by: @ralphxyz

Ok Will, I am using Bill's modified code from the  Big Stepper project.

Good.

The motor does not spin as fast as I have seen other programs (which I cannot find again).

Look, if speed is your main concern, then set up a belt and a couple of pulleys. Put the large diameter pulley on the stepper and the smaller diameter pulley on the lead screw. The lead screw will then rotate faster by the ratio of the pulley diameters.

For instance, if you put a 5" pulley on the stepper and a 1" pulley on the lead screw, then the lead screw will  turn 5 revolutions for each single turn of the stepper axle. Note, however, that this increase in speed comes at the cost of a proportional loss of torque.

Now I need to figure out how to count step pulses in order to enable some virtual limit switches.

Using real limit switches or manual positioning is mandatory. In case of loss of power while operating or belt slipping or stock  jamming or anything which can cause the the micro controller to lose track of where it is. You'll need some method for re-establishing a "base" position, even if you have to spin it by hand back to a scribed mark.

You thought 20 uSecs was slow, now I am using .05 uSecs and the motor runs fine

No, you think you're using .05; but if you check the map function, you'll find that it's expecting (and giving results as) integers.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@ralphxyz)
Member
Joined: 4 years ago
Posts: 61
Topic starter  

"expecting (and giving results as) integers." 

so what is .05 then?

so what is 20 then?

Remember I am as bad at math as I am at programming.

Ralph


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2504
 

@ralphxyz 

Integers are whole numbers with no decimal part, like 1,2,3, ... 99, ...

Real (aka floating point) numbers have a decimal part (which may be zero) like .05, 1., 1.3, ... pi, etc

The computer handles each of these differently, so it's important to choose the correct type of variable type.

For instance

n=3 and m=5

if n and m are both integers

     n/m = 3/5 = 0  because it's between 0 and 1 and too small to be 1

     m/n = 5/3 = 1  because it's between 1 and 2 and too small to be 2

if n and m are both floating point

     n/m = 3./5. = .6

     m/n = 5./3. = 1.666... (an exact value is not possible but the value will

                                       be approximated depending on the processor's design)

If EITHER n or m is declared as a floating point value, the computer will treat the equation as if BOTH were floating point. However, note that if you assign a floating point ro an integer, it will lose any decimal portion it may have had.

so   int q = 5.0/3.0 (will be calculated as 1.666667 and then chopped to 1 when converted to integer)

now q = 1 (because it lost the decimal part)

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@ralphxyz)
Member
Joined: 4 years ago
Posts: 61
Topic starter  

Thanks Will, deep in the back of my mind I thought duh integers are real numbers.

It is nice to have the refresher.

Ralph


   
ReplyQuote
Page 8 / 8