hanna8754
Posts: 5
Joined: Tue Dec 31, 2019 5:17 pm

td6600 driver and nema 17 stepper RPM

Fri Jan 03, 2020 4:09 am

Hi all,
I’m looking for help with integrating a tb6600 stepper motor driver and a nema 17 stepper motor through a pi 4.

I know how to hook them up properly, but I was wondering if anyone had any examples or know how to set up python code to run a motor at a specified RPM. I have the controller set to 1/32 microsteps and I want to run between 5 and 50 rpm.

Thank you for any help in advance!

ghp
Posts: 1484
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: td6600 driver and nema 17 stepper RPM

Fri Jan 03, 2020 7:48 am

Hello, there are some discussions in other posts, e.g. https://www.raspberrypi.org/forums/view ... p?t=242928

If you drive the motor with 1/32 microsteps, and 50 RPM, 200 steps per revolution, then you need 32 * 50 * 200 pulses in 60 secs. Which is 5333Hz, quite fast for python code. If you use a 50% rect wave for clock, then the delay is really short with 94us. Almost impossible to have this short timings in a precise way in python and on a linux platform. If you need precision, then look for a microcontroller to drive the pulses.
You also might need to use a rampup to avoid missing steps when starting the motor at that speed. Which makes the code more complex and slower.

Code: Select all

# sample code from other post
	for i in range (5*200):
		GPIO.output(LinearActuatorStepPin, 1)
		time.sleep(LowSpeed)
		GPIO.output(LinearActuatorStepPin, 0)
		time.sleep(LowSpeed)
		# print ("Moving")
There are some remarks in the net that the TB6600 device uses different driver chips internally where microstepping 1/32 might work or not work. So start with 1/2 when running tests.

pootle
Posts: 374
Joined: Wed Sep 04, 2013 10:20 am
Location: Staffordshire
Contact: Website

Re: td6600 driver and nema 17 stepper RPM

Fri Jan 03, 2020 9:19 am

A td6600 controller is not a good choice for a pi as you will need to level convert the control signals, much better to use (for a basic stepper controller like this) one of the A4988 family which use the same logic levels as the pi, so can be driven directly from gpio pins. Also these controllers allow logic level control of the number of microsteps, rather than dip switches. generally you will need to reduce the number of microsteps as the overall motor speed increases. They also have much finer control of current limiting.

While python code cannot provide super accurate / reliable timing directly driving gpio pins, a package like pigpio can easily do this by using DMA to drive the pins, although this makes the software more complex.

If you want to use a microcontroller to offload the detailed work from the pi, then why not use a dedicated microcontroller based stepper driver like one of the tmc familly of chips?

A premounted chip on a development board (like this one) can interface directly to a raspberry pi and provides superb control of the stepper with ramp up / down, current limiting and even stall detection.

btw you might get on better posting these questions in the automation forum.

Also you can remove some of the variability of timing by checking the time in the loop like this:

Code: Select all

import pigpio
pio=pigpio.pi()
ticktime=.01 #for 100 per second
nexttickat =time.time()+ticktime
ticksleft=5000 # how many ticks to issue
overruncount=0
while ticksleft > 0:
    pio.gpio_trigger(pin, pulse, level) # pigpio can issue a pulse in a single call
    ticksleft -= 1
    sleeptime=nexttime-time.time()
    nexttickat+=ticktime
    if sleeptime > 0:
        time.sleep(sleeptime)

Return to “Python”