Notifications
Clear all

Large Stepper Code does not work

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

@ralphxyz 

You're going to have to work on that, accurate wiring isn't a luxury in electronics.

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


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

I checked it a dozen times.

Ralph


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

@ralphxyz 

And it was wrong 11 of them 🙂

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


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1608
 

Who knew, one has to have the wiring correct in order to see the correct results.

TaDah, it is working!!

Hi @@ralphxyz and @Will,

  That sounds like we are making steady progress.

  I hope that means you have the expected performance from the circuit and software I described. Of course, I understand why you might try alternates, but from my viewpoint, I can only usefully advise if I know exactly what hardware and software you are actually testing - hence I am being as specific as possible.

The next step for this test rig was to include the potentiometer to vary the speed. As a precursor, to updating the software, could I please ask you to test the wiring with your voltmeter.

That is, connect your voltmeter to the Arduino A0 pin and the Arduino Ground pin.

With the system powered as normal, (the motor should be steadily stepping at its fixed rate),  rotate the potentiometer from one end to the other ... you should see the voltage reading steadily change from 0V (when the slider is at the Gnd end) to 5V (when it is at 5V end).

Meanwhile, I'll start to look at the software changes ... it might be tomorrow before I get back to you... please let me know how you get on.

Best wishes, Dave


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

Yes, the pot reads correctly 0 - 5 volts.

Ralph


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1608
 

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

Well that was kinda scary! The code works.

You might want to turn your sound down.

https://photos.app.goo.gl/Nj4vsgXauoSTLqHt8

Ralph


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1608
 

Hi @ralphxyz (& @will),

   Congratulations ... you now appear to have a basic test setup to find out about your motor, controller, etc.

  I picked the max speed control limit based on a quick glance of the motor controller spec  .. I have no idea how that relates to what your motor follow, and may have even misread the controller spec ...

I suggest you keep a 'gold' copy of this version of the software as a hardware test, together with a note of your wiring (including a few photos?), in case something stops working in the future. - its always handy to be able to backtrack to something you know 'works'. Then, please feel free to modify a new copy to learn more about your setup.

---------

I just had a quick glance at the code Will published on page 2 of this thread - I haven't tested it - you might like to try it, after adjusting it for your new wiring. i.e. change to these values:

  • #define dirPin      6
  • #define stepPin   7
  •  
  • #define revPin     2

Notes:

  • Will has used a neat 'map' function instead of the calc function I wrote ... I suspect they have similar underlying maths, excepting mine is float, not long,  but map is provided, and should be quicker - I didn't know about map, and haven't tested it, but I would probably have used it!

 

  • Will's program used a neat interrupt to indicate the direction switch had been activated.
  • To keep my program simple, I avoided interrupts  ... Will's approach is better in a working system ... I prefer mine to initially show all the hardware, etc. is playing nicely ... or not! - When it is playing nicely, switch to Will's method.

 

  • Will's program reads the pot between each pulse ... according to the Arduino docs                                       ( https://www.arduino.cc/en/Reference.AnalogRead ),                 it takes about 100 microseconds. It is unclear if the UNO time is different, but based on this, the minimum total pulse time, (and hence determining the fastest step rate) will be more than
    • ((2 * pulseDelay) + 100) microseconds
    • if min pulseDelay is 50, minimum time of above is 200 microseconds
  • My test program only reads the pot once every 1000 pulses, and hence the AnalogRead  delay time only affects one pulse in a thousand - according to my scope, minimum pulse time was about 60 microseconds with my code

If you have a problem I can try testing Will's program if you let me know, but hopefully it will work fine!

Hope that helps .. and you can make progress.

Dave

 


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

@davee FYI @ralphxyz

I don't think you should use my code as the ultimate since it was intended to bridge the gap between Bill's code (which wasn't working) and the other example (which did work).

Bill's original used an interrupt to reset direction, that is the correct setup because ut won't interfere with the motor speed. My intermediate version was intended to try to implement the button without interrupts, so it couldn't be implemented very time through the loop.

The map function is built-in and very useful for many things. However, it doesn't check boundaries nor enforce limits. Also, as DaveE pointed out, it's integer only.

If everything is working satisfactorily, I suggest that you aim to duplicating Bill's code as the "gold standard" and not my intermediate sketch.

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 and DaveE. You have been so helpful.

I sure wish I knew why the original code did not work.

I will run Wll's code again.

With DaveE's code the motor does not turn very fast and is rather erratic.

I need to figure out the speed range that I will need.

This should be a new thread.

I have a 8 TPI (Threads Per Inch) leadscrew on the Z axis of my lathe.

There is a 10 TPI leadscrew on my X axis.

I am going to try to match SFM (Surface Feet per Minute) to the chart on this page.

Or other similar pages on the web.

Of course for the X axis ounce I get to threading and turning I will only be moving the leadscrew

.001" - .005". so the motor will not even make a full revolution.

Math is probable my worse thing so I will be looking for help.

For Z I will be using AtomicELS but there is no X, so I will be doing my second worse thing

programming to add X.

 

Ralph

 


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1608
 

Hi @will, and @ralphxyz

  Thanks Will for your input ... I didn't look closely at Bill's code, just initially avoiding it because it used interrupts which can be harder to debug. I originally matched the the hardware to Bill's configuration as a 'tested' starting point, but also knew it would be easy to try his code at a convenient moment. I agree with Will, this looks like a good time.

Good luck.

Dave


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

Will, your code runs the motor and the pot adjust the speed.

The DIR button is not working.

With DaveE's first code version the reverse button worked.

I am not sure with the second version as there is a big delay with pushing the button and the motor reversing. The motor will occasionally reverse without the button being pushed.

So I do not know what caused the reverse.

Ralph

 


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

@ralphxyz FYI @davee

The sketches I wrote are no longer relevant as pins have been switched and they have outlived their intended purpose as a transition between Bill's code and your (working) example.

You should continue using Dave's code with a view towards re-integrating the reverse switch as an interrupt.

In Dave's last posted code there will be apparent delays because each time through the loop the speed and possibly direction will change. Then, the motor will be sent 1000 steps. So, if the speed is set slow, there'll be longer pauses between loops than if the speed is set fast.

Also, you must be pressing the reverse switch while the sketch is "listening" to it. While the motor is running, most of the time it will not notice the reverse switch, it will only sense the switch if you're holding it down after each 1000 step loop. Also, if you've set the speed to fast, you may trigger the switch a second time because the stepping has completed before you expect it. This could cause what appears to be an unexpected reverse.

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


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

I much prefer your speed control over DaveD's, it is much smoother.

I can get slow speeds and fast speeds.

I will "try" to integrate DaveE's button routine from his first code.

Ralph


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1608
 

Hi @will & @ralphxyz,

  As Will says, my simple code will only check the switch and the pot once per 1000 pulses, then the 1000 following pulses will be the same speed and direction .. this means it will only change about once per 6 seconds at the slowest speed ... not great for responsive operation but the code was only meant to check things out, not a final system.

As for maximum speed, I used the simple TB6600 data sheet speed of 20,000 pulses per second ... as I mentioned it is a bit slower ... probably around 17,000 pulses per second. However, what I didn't notice is the table below stated the high/low ratio needs to be 25/75 for 20,000, the maximum is 13,000 with 50/50 ratio, so it probably not work properly at the highest speeds without changing the pulse timing --- the rest of the range should be ok, bearing in mind there will be a slight 'cog' once per 1000 steps.

As for overall rotational speed, it clearly depends on the microstep setting .. you may want to change the setting to reduce the number of steps required to make each revolution.

Also, try using Bill's code ... your hardware should also match it now and it should have a more responsive control.

Best wishes, Dave


   
ReplyQuote
Page 5 / 8