Motor Controller Project

Have questions about the equipment used for macro- or micro- photography? Post those questions in this forum.

Moderators: rjlittlefield, ChrisR, Chris S., Pau

kaleun96
Posts: 273
Joined: Sat Oct 20, 2018 3:47 pm
Location: Stockholm, Sweden

Post by kaleun96 »

I was under the impression that Trinimac configuration removed the need for most libraries and was catered for by the chip itself?
You could do it all without any libraries but there are some useful ones. This one by teemuatlut allows you to modify the registry using some simple functions rather than having to write to the registry yourself:
https://github.com/teemuatlut/TMC2130Stepper

I believe they support the other Trinamic boards with this library, but it seems to have less functionality:
https://github.com/teemuatlut/TMCStepper

In their examples they use port manipulation to send STEP/DIR commands and this is super fast. But you'd have to write your own acceleration and deceleration profiles to work with this, as well as functions to keep track of position, speed, targets, distance travelled, etc.

Instead I use the AccelStepper library, which takes care of acceleration and deceleration:
https://www.airspayce.com/mikem/arduino/AccelStepper/

The down side is that it uses DigitalWrite for STEP/DIR and has some other overhead that reduces the maximum possible speed. Maybe one day I'll write my own library to take advantage of port manipulation but for now I'm satisfied.
I am only interested in single axis control but I can see why you looked at Marlin.
Marlin could be useful but it has a lot of clutter that we don't need. I actually just wanted a barebones library but a lot of projects and information about the TMC2130 is geared towards 3D printer users so I went through some of them to pick up bits and pieces that may be useful, particularly regarding StallGuard.

To prevent us hijacking this post too much, I'll PM you my barebones code for testing the driver parameters. It has some functions for homing the rail, using a joystick for manual control, triggering a flash etc. But it's pretty straight forward and you can remove the unnecessary parts. I'll post the full code for my project, most of which is related to the TFT screen, sometime this week!

mawyatt
Posts: 2497
Joined: Thu Aug 22, 2013 6:54 pm
Location: Clearwater, Florida

Re: Trinimac

Post by mawyatt »

cws1745 wrote:Just an update on my experience with the Trinimac / Raspberry Pi configuration as produced by Mike.

Stunned! .... and very annoyed that I spent sooo long designing my microcontroller based on the Arduino and BigEasyDriver (AD4988 chip).

Totally silent operation on my WeMacro rail, just beginning to get to grips with the literally hundreds of configuration commands but the prospect of 256 microsteps, silent operation, load sensing, auto torque etc etc etc make this a no-brainer for me. Cheap and cheerful Chinese drivers a thing of the past!

As for the Raspberry Pi - I'm reluctant to throw away all of my development effort on a stand-alone controller / TFT screen, Arduino and C# so I'm going to see if I can redesign my code to replace the BigEasyDriver with the Trinimac 5130. If there is anyone interested in this platform I'd welcome any collaboration.

Charles
Charles,

Glad you like the Raspberry Pi based Trinamic TMC5130 controller performance :D

It's hard to describe unless to can see and feel it live. If you hold the motors/rail in your hand you can hardly tell or hear they are moving :shock:

I'm looking into incorporating a touch screen on the RPi, but that's for a later project.

Best,
Research is like a treasure hunt, you don't know where to look or what you'll find!
~Mike

mawyatt
Posts: 2497
Joined: Thu Aug 22, 2013 6:54 pm
Location: Clearwater, Florida

Post by mawyatt »

kaleun96 wrote:
I was under the impression that Trinimac configuration removed the need for most libraries and was catered for by the chip itself?
You could do it all without any libraries but there are some useful ones. This one by teemuatlut allows you to modify the registry using some simple functions rather than having to write to the registry yourself:
https://github.com/teemuatlut/TMC2130Stepper

I believe they support the other Trinamic boards with this library, but it seems to have less functionality:
https://github.com/teemuatlut/TMCStepper

In their examples they use port manipulation to send STEP/DIR commands and this is super fast. But you'd have to write your own acceleration and deceleration profiles to work with this, as well as functions to keep track of position, speed, targets, distance travelled, etc.

Instead I use the AccelStepper library, which takes care of acceleration and deceleration:
https://www.airspayce.com/mikem/arduino/AccelStepper/

The down side is that it uses DigitalWrite for STEP/DIR and has some other overhead that reduces the maximum possible speed. Maybe one day I'll write my own library to take advantage of port manipulation but for now I'm satisfied.
I am only interested in single axis control but I can see why you looked at Marlin.
Marlin could be useful but it has a lot of clutter that we don't need. I actually just wanted a barebones library but a lot of projects and information about the TMC2130 is geared towards 3D printer users so I went through some of them to pick up bits and pieces that may be useful, particularly regarding StallGuard.

To prevent us hijacking this post too much, I'll PM you my barebones code for testing the driver parameters. It has some functions for homing the rail, using a joystick for manual control, triggering a flash etc. But it's pretty straight forward and you can remove the unnecessary parts. I'll post the full code for my project, most of which is related to the TFT screen, sometime this week!
kaleun96,

Why would you use the Step and Dir inputs to the Trinamic TMC2130 with Arduino?

I haven't used the TMC2130, only the 5130, 5160, 5161 and 5072 but think the TMC2130 has some of the features of these other devices mentioned that have all the basic velocity and positioning details controlled within the internal mcirocontroller, same goes for using other libraries unless they are specific functions like homing.

Best,
Research is like a treasure hunt, you don't know where to look or what you'll find!
~Mike

kaleun96
Posts: 273
Joined: Sat Oct 20, 2018 3:47 pm
Location: Stockholm, Sweden

Post by kaleun96 »

mawyatt wrote: kaleun96,

Why would you use the Step and Dir inputs to the Trinamic TMC2130 with Arduino?

I haven't used the TMC2130, only the 5130, 5160, 5161 and 5072 but think the TMC2130 has some of the features of these other devices mentioned that have all the basic velocity and positioning details controlled within the internal mcirocontroller, same goes for using other libraries unless they are specific functions like homing.

Best,
I didn't come across a whole lot of information on driving the stepper via SPI, only for setting the parameters via SPI. All the libraries I found were using the STEP and DIR pins as well so I couldn't borrow from another's code. I guess you have to manipulate the current going to each coil via the registers to drive the stepping manually?

I'm just a hobbyist when it comes to this stuff so the Trinamic documentation was overwhelming enough as it is! I think if I was to make an improvement it would be for the port manipulation on the Arduino (still using the STEP/DIR pins) and that will definitely get me more than enough speed.

Without an oscilloscope I found I was a bit in the dark when it came to the tuning too. Just tweak this one thing, see how it works, tweak it the other way, no difference OK then try tweak this one etc.

I do need to add support for the LOST_STEPS functionality though. That would greatly help ensure that my setup is accurate and reliable.

mawyatt
Posts: 2497
Joined: Thu Aug 22, 2013 6:54 pm
Location: Clearwater, Florida

Post by mawyatt »

kaleun96 wrote:
mawyatt wrote: kaleun96,

Why would you use the Step and Dir inputs to the Trinamic TMC2130 with Arduino?

I haven't used the TMC2130, only the 5130, 5160, 5161 and 5072 but think the TMC2130 has some of the features of these other devices mentioned that have all the basic velocity and positioning details controlled within the internal mcirocontroller, same goes for using other libraries unless they are specific functions like homing.

Best,
I didn't come across a whole lot of information on driving the stepper via SPI, only for setting the parameters via SPI. All the libraries I found were using the STEP and DIR pins as well so I couldn't borrow from another's code. I guess you have to manipulate the current going to each coil via the registers to drive the stepping manually?

I'm just a hobbyist when it comes to this stuff so the Trinamic documentation was overwhelming enough as it is! I think if I was to make an improvement it would be for the port manipulation on the Arduino (still using the STEP/DIR pins) and that will definitely get me more than enough speed.

Without an oscilloscope I found I was a bit in the dark when it came to the tuning too. Just tweak this one thing, see how it works, tweak it the other way, no difference OK then try tweak this one etc.

I do need to add support for the LOST_STEPS functionality though. That would greatly help ensure that my setup is accurate and reliable.
I'm using the SPI to control the TMC5130 and other Trinamic devices under mode 3, so everything is controlled this way. The Trinamic control registers are configured as 5 byte, with 1 byte as address and 4 bytes as data. Details are in the data sheet, and it's not simple!! I used some code from pootle from GitHub and got things eventually working after some bugs got corrected.

I'm not a programmer, nor computer type, so similar "hobbyist" also! This was all new and daunting for me, but eventually got things working. The "built-in" features of these Trinamic devices are many, very powerful but highly complex. If you can get the SPI working on the Arduino I think you'll find accessing these features expands the performance and usage of these devices immensely, which make them standout over the other popular controllers.

Wish I could help with the Arduino but I know nothing about how to use these micro controllers. If you decide on the RPi, then I can provide some guidance and help with these.

Best,
Research is like a treasure hunt, you don't know where to look or what you'll find!
~Mike

Adalbert
Posts: 2465
Joined: Mon Nov 30, 2015 1:09 pm

Post by Adalbert »

Hi Mike,
TMC5130 Trinamic is really nice but expensive :-(
https://www.amazon.com/EVAL-BOARD-TMC51 ... way&sr=8-1

I use Arduino Uno + LCD shield + TB6560 + two relays + infrared diode + power supply.
Everything together for less than $20 :-)
Arduino can be programmed extremely easily by the usage of the C or C++.
OK, I cannot use 256 micro-steps but I don’t need that.
I would say that it is the simplest and cheapest way to assembly a DYI rail.

So, your solution allows many features but is not really cheap.

BR, ADi

kaleun96
Posts: 273
Joined: Sat Oct 20, 2018 3:47 pm
Location: Stockholm, Sweden

Post by kaleun96 »

Adalbert wrote: So, your solution allows many features but is not really cheap.
The TMC2130's are only 10 euro (Watterott.com) and you make that money back by not having to buy microswitches for endstop detection :wink:

Adalbert
Posts: 2465
Joined: Mon Nov 30, 2015 1:09 pm

Post by Adalbert »

Hi kaleun96,
microswitches for endstop detection
I don’t detect the range of the rail.
My THK KR2001A is long enough. The carriage is placed in the middle of the rail and my stacks are not longer than some millimeters.
BTW, I have already tested the crash-situation but absolutely nothing is happening except some noise :-)
BR, ADi

kaleun96
Posts: 273
Joined: Sat Oct 20, 2018 3:47 pm
Location: Stockholm, Sweden

Post by kaleun96 »

Adalbert wrote:Hi kaleun96,
microswitches for endstop detection
I don’t detect the range of the rail.
My THK KR2001A is long enough. The carriage is placed in the middle of the rail and my stacks are not longer than some millimeters.
BTW, I have already tested the crash-situation but absolutely nothing is happening except some noise :-)
BR, ADi
If you got the end and stall you would lose steps and throw of your positioning though right? You could just reset the position back to zero though.

It is unnecessary but there are many advantages to the TMC2130 at only a few more dollars than a A4988 or DRV8825 :)

mawyatt
Posts: 2497
Joined: Thu Aug 22, 2013 6:54 pm
Location: Clearwater, Florida

Post by mawyatt »

Adalbert wrote:Hi Mike,
TMC5130 Trinamic is really nice but expensive :-(
https://www.amazon.com/EVAL-BOARD-TMC51 ... way&sr=8-1

I use Arduino Uno + LCD shield + TB6560 + two relays + infrared diode + power supply.
Everything together for less than $20 :-)
Arduino can be programmed extremely easily by the usage of the C or C++.
OK, I cannot use 256 micro-steps but I don’t need that.
I would say that it is the simplest and cheapest way to assembly a DYI rail.

So, your solution allows many features but is not really cheap.

BR, ADi

Hi BR,

I've never used the Trinamic Development Eval Boards, only the BOB boards and created my own development system around that. The TMC5130 BOB from DigiKey is only ~$20!! They have a new smaller board out now that is based on the TMC5160 that is ~$14.

The Toshiba TB6560 has nowhere near the overall capability of the Trinamic devices. Have you actually looked at the current waveforms from Toshiba controllers with a oscilloscope? In a private email a Pololu engineer informed me that they had discovered an unequal current step size around the zero crossings, you can feel it with your hand he said. That's why I developed the Hall Effect Motor Current Sensor/Probe, to verify the motor current behavior (BTW I just assembled the 1st PCB and it's works superbly, but that's for another discussion!!).

Don't forget you can get a RPi ZERO for $5 and a RPI ZERO W for $10 at Adafruit. These both are capable of operating the Trinamic controllers, and you have the features of a computer rather than a micro controller which can be programmed in C or Python if you desire. With the ZERO W you can operate with VNC remotely thru your WiFi router, so no need for a monitor, keyboard or mouse with the setup....really nice!!

I won't disagree your solution with the TB6560 & Arduino is the simplest and cheapest, but maybe not with the best performance!!!

Best,
Research is like a treasure hunt, you don't know where to look or what you'll find!
~Mike

mawyatt
Posts: 2497
Joined: Thu Aug 22, 2013 6:54 pm
Location: Clearwater, Florida

Post by mawyatt »

kaleun96 wrote:
Adalbert wrote: So, your solution allows many features but is not really cheap.
The TMC2130's are only 10 euro (Watterott.com) and you make that money back by not having to buy microswitches for endstop detection :wink:
Digi Key has the TMC5160-stepStick introduced in Feb this year for $14. This uses separate driver NMOS FETs and can handle 3A rms up to 36V.

I have already developed a board and the code around the TMC5160 BOB ($20) for higher current applications shown here. It works beautifully with the RPi!!

May develop another PCB around the TMC-5160 stepStick, but that's another project for later.

Image

Best,
Research is like a treasure hunt, you don't know where to look or what you'll find!
~Mike

Adalbert
Posts: 2465
Joined: Mon Nov 30, 2015 1:09 pm

Post by Adalbert »

Hello Mike,
If I wanted to assemble the controller based on Trinamic,
which components would I have to collect?
Or better what would you recommend?
But I don’t want to develop any boards.
e.g.
- RPi ZERO W
- TMC5130 BOB
- ?
Thank you in advance.
BR, ADi

mawyatt
Posts: 2497
Joined: Thu Aug 22, 2013 6:54 pm
Location: Clearwater, Florida

Post by mawyatt »

Hi BR,

You will need to connect the TMC5130 BOB or other BOB to the RPi. The RPi has a 40 pin connector that is the GPIO connector. Here's a Trinamic site that shows various ways to do this.

https://blog.trinamic.com

You need to connect the SPI (4 pins), Vcc_IO and the usual Motor VS and Motor coils. I also use the RPi internal clock since it's based on a crystal clock, and use a GPIO pin to Enable the Motor Drive.

Might want to use a couple of the GPIO pins for camera trigger and strobe trigger, better yet is drive a opto-isolator and LEDs as indicators like I've done.

You can make a dedicated hardwired prototype board for this, or a custom PCB (like I've done), or just use the plug in wires.

Anyway, lots of options, none of which are very expensive. I still have a few PCBs available for various Trinamic BOBs, when these run out don't think I'll reorder.

Best,
Research is like a treasure hunt, you don't know where to look or what you'll find!
~Mike

Adalbert
Posts: 2465
Joined: Mon Nov 30, 2015 1:09 pm

Post by Adalbert »

Hi Mike,
Many thanks for the info!
Actually I would like to test the controller based on the driver from Trinamic as follows:
https://www.photomacrography.net/forum/ ... c&start=15
This test shows the behavior of the rail.
BR, ADi

mawyatt
Posts: 2497
Joined: Thu Aug 22, 2013 6:54 pm
Location: Clearwater, Florida

Post by mawyatt »

Adalbert wrote:Hi Mike,
Many thanks for the info!
Actually I would like to test the controller based on the driver from Trinamic as follows:
https://www.photomacrography.net/forum/ ... c&start=15
This test shows the behavior of the rail.
BR, ADi
ADi,

That would be a very good test of the rail with the Trinamic controller. Looking forward to your findings on this test :D

Best,
Research is like a treasure hunt, you don't know where to look or what you'll find!
~Mike

Post Reply Previous topicNext topic