Hi i am trying to use MCPWM to move a nema 17 motor with esp32. I am using a TB6560 stepper motor driver and it setup is limmiting current to 1.5A and i am using 1/8 Microsteps. Motors is classic one 1.8degrees per step and 200steps per revolution. I am using the mcpwm_unit_0 and timer_0 and at m…
(1) I usually start with 1kHz and increase to 10kHz. 5kHz moves the motor smoothly. (2) You don’t need any PID controller, which is for another purpose. (3) You might consider higher microstepping resolution for smooth movement. (4) Let me know you config setting. (5) Are you using this kind of cheap AliEx module with a huge heat sink? TB6560 3A Stepper Motor Driver Module – US$6. fr.aliexpress.com/item/…
(5) Are you reading this app note? TB6560AHQ 2-phase stepping motor driver App Note- Toshiba toshiba.semicon-storage.com/info/…. (6) And have you read the friendly datasheet at least 3 times? TB6560AHQ 2-phase stepping motor driver App Note- Toshiba toshiba.semicon-storage.com/info/…
TB6560AHQ 3.5A 40V 2-phase stepping motor driver Datasheet – Toshiba toshiba.semicon-storage.com/info/…
What do you mean by “temperature not too much higher than normally should”? Usually it is OK to heat up to 80C. Datasheet says, temperature shutdown is 170C.
By MCPWM, do you mean this?docs.espressif.com/projects/esp-idf/en/latest/esp32/…
i have edited the post to add the code for the config. I will go with 1/16 then microsteps. Yes the module is this with the juge heat sink. Yes the component of esp32 is this what you send. About the temp is about the motor temp. It is not 80C i suppose it is around 35 cause it is touchable. What should i check in the documents that you have send to me.
i want to attach a cable on the motor and measure the tension on it. So i was going to use a pid controller in order to achieve tension. I was going to control frequency somehow.
(6) I don’t understand what you meant by “to attach a cable on the motor and measure the tension on it” Do you mean you want to measure the “torque”? (7) BAD NEWS and WARNING – I have the feeling that you are a stepper motor newbie and you have chosen a bad driver TB6560 to start learning. For newbies I usually recommend to start with A4988 or DRV8833. Your might to search this or other forums on how to use A4988 or DRV8833***
References: (1) A4988 Stepper Motor Driver – MakerFabs makerfabs.com/a4988-stepper-motor-driver.html (2) DRV8833 2 Channel DC Motor Driver Module – MakerFebs makerfabs.com/dvr8833-2-channel-dc-motor-driver-module.html
start learning , newbie or not i am sorry but i can not go in that type of discussion it is really bad thing for anyone to think that he is helping starting with this type of phrases. It is better not to try to help at all cause this answer give nothing. For A4988 you still need one pin for pulse and one for direction so i do not see any change in the problem , i see the same questions apply with this driver which means that your attack was completely useless.
If you know how to help please do so, if not you do not need to go in a newbie discussion to escape cause noone forced you to help. I am appreciating your comments at the beginning about how you control your system. Usually before i do a scale up on any machine i am trying the proof of concept. When i was talking about a cable i and tension i was really talking about this. A cable/rope will be attach and the motor will stretch the cable. Then with a tension module i will measure the tension of the rope.
(1) My apologies for wrongly though that you are a stepper newbie and my advice to stepper newbies. (2) Thank you for clarifying your objective of measuring the “tension of the rope attached to the stepper motor. I did once use a mini string balance to measure the motor torques. I might show you my tools used later. (3) I am also trying to measure the torque or a DRV8801 stepper motor. Perhaps I can give you the link of the chat about it.
(4) I agree that to prove a concept, any stepper would do.
2 hours later…
There you are – my stepper motor torque measurement setup.
3 hours later…
I am sorry to have misled you that A4988 and DRV8833 are for newbies only. Actually they are also popular among 3D printer / CNC pros. It is true that heavy duty machines use DM5xx stepper modules. I do also use DM542, but I found it tricky to do the config and testing. Let me show you my DM540/TB6600 stepper module like your TB6560. I don mind to to discuss using your prototyping modules.
References: How to use MCU (.. Rpi4B, Rpi Pico) and DM542 microstep driver to control NEMA 17 … stepper motors?
3 hours later…
Hi no worries about the comments. Before 2 years i started working in a cnc project which i stop cause of space but i managed to have 3 nema 42 motors used with dm542 i think and i used linux cnc to control them. This project worked smoothly and the usually setup was the common cathode. The speed of the motor was completely controlled from the LinuxCNC not from the cause this was a completely project. I did not have to go to low level things
Now i want to do some small machine that i can check with a tension module the tension of a rope. For this i have to stretch the rope. And it is the first time that i am doing it with esp32. So i tried to use the component which is more for dc motors using the pwm to control the dc applied on motor
In some example they are doing stepper control using the the set duty in microseconds
which is more about positioning if you have a stepper motor of 180degrees movement and you want to set it there. I want to use the stepper to control it with a pid controller to control the tension.
So i understand that in order to make the step motor to go faster or slower i have to change the pwm frequency. I am worried if this could bring problem on motor about heating. From what you said i am worried that you refer to temperature of the chip of the driver but i am worried about the temp of the motor
I assume that my previous test was a little more problematic on the code cause i tried to change the duty and i forgot that this is only for the dc motor. So i may have send more current that i should have done in the motor which means that i have to try again and see.
Thank you for your clarification. (1) I am setting up a test jig to measure the parameters of a motor coil, motor voltage, current, PWM frequency, duty cycle, speed, torque, … (2) This is a manual test version of my software test version which based on Rpi Pico MicroPython, … (3) The end of this video is on DMX540 using the
MKS testing tool (more about this later) https://youtu.be/jQFnPwpVREQ.
Ah, locking down supper time. See you later.
This tutorial says motor temperature of 80C is not big deal: machinedesign.com/motors-drives/article/21835161/…
I have changed my solution to use probably static frequency using 5000Hz as you proposed. Then i will go in the higher microstep resolution that i can with this driver which will give 200*16=3200steps/revolution. which probably mean that i could use 3200Hz also for the motor.
After this i am thinking of using one other time with doubled the frequency of the motor and sample from the tension module and just change directions or stop.
i just wanted to use pid for this also the the manual experience but if i use 1000-10000Kz then i probably need to put on pid range of -10000 – 10000 and somewho also map values between -1000-> -1 and 1->1000 in order always to use -1000 or 1000 for the frequency
fantastic video setup 🙂
3 hours later…
I still don’t appreciate why you are using PID. Me once used PID because I, say, want to move my robot car to a particular point (one step before falling down the cliff) ASAP without any overshoot. So I accelerate to the max speed, then move to say, 10 feet before falling over, then decellerate while travelling the last mile, and arrive target with zero velocity.
Perhaps you might like to let make me how you are using PID.
I searched my junk bin for the mks stepper motor test board,
and set up the DMX board to test
Ah, locking down bed time. See you tomorrow.
1 hour later…
I want to use pid in order exactly as you described to control the tension lets say smoothly not completely in linear way but i assume it the sampling rate of the tension is 2 or more times bigger than the movement of the motor this should be ok and i will not have any case that motor never meets the target but it is always either more or less than the proper value. Thank you see you tomorrow
next day →last day (31 days later) »
You might like to skim my old post on tmc2209 where I use a stepper motor with speed encoder: raspberrypi.stackexchange.com/questions/135191/….
The stepper motor tester with sig gen is handy to find the optimum frequency.
(1) Controlling a stepper motor through a signal generator 64,143 viewsMay 16, 2015
this chip is very very very interesting and with uart you can get all info? even with uart you can control the frequency?
i tried to read a few things in the datasheet
can it work with bigger motors cause i saw it is up to 2A
though i suppose you propose to use it to find the best frequency using the jig and reading from uart and the put the proper pwm. but what if i want a non static frequency
i mean there is now a limit on min freq i can use before motor goes to stop moving without a stop signal. this does not allow me if i do not do some software mapping function to give the value to a pid controller.
is this chip able to handle it cause from pinout i see the same setup like all others
this module is yours? you are selling it? can i find it in europe?
1 hour later…
@kyrpav Do you mean tmc2209 using uart interface, or tmc2160. max 10A using spi?
@kyrpav I forgot the max current for tmc2209. For 2160, it is 10A.
@kyrpav Well, my current test jig for MX540/TB6560/TB6600 is only for newbies. The MKS OSC stepper motor driver tester uses the stupid 555 timer is not flexible at all. In my other testers, I use XY-LPWM which is very precise, and UART controlled.
@kyrpav Well, the current test jig is manual, push button operation, is stupid, and only for CNC guys who does not know software at all. I am going to try 42VDC motor power, and I worry that I will fry more drivers, so it is sort of safe tester.
@kyrpav Yes, as you all drivers have the basic signals, enable, direction, steps. But for tmc2209/2160, all the driver config and diagonstics are done in software uart or spi.
@kyrpav Yes, all modules on photo are mine, some are lying in the junk bin, collecting dust for years. The tmc2209/2160 are designed by the German guys, manufactured in ShenZhun, not too far away from my city, just across the boarder.
Now let me show you my test results:
The above is the big picture of step pulse, motor encoder output, and current sense resistor output, not all in sync, therefore display messy. I have written Pico Micropython functions to do the signals separately, step pulse, speed function, and current measurement.
2 hours later…
I got my tmc2160 from TaoBao. Perhaps you can find it in Amazon/AliExpress UK/Europe.
Makerbase MKS TMC2160-OC Motor Driver for 3D Printer – ¥77
AliEx got it: aliexpress.com/w/wholesale-tmc2160.html
BigTreeTech also has a US$20 version with metal case for strong anti EMI.
TMC2160 Stepper Motor Driver for 3d Printer CNC Machine – BigTreeTech US$20
I recommend the MKS tmc2160 version because it has the SPI and DIAG jumper for flexible config and diagnostics.
you almost convinced me. so mks tmc2160 where the same question applies what do you propose to use in order to slow down the speed and not make the motor stall and get heated?
and the diag is in order to put some manual control to the motor? i am not sure how that works i never used it. And that means that this version does not give you serial port isn’t it?
do you know any that gives you. I am not sure what is easier for esp32 to use spi or uart since i am not using arduino interface i am using the esp-idf framework
2 hours later…
Ah, mks2160 video again.
@kyrpav Well, I am thinking of using both uart tmc2219 and spi tmc2160, for my future projects. I started with uart 2209 because I just learned how to use Pico uart and found it easy. But then Pcio has only two uarts, not enough to go around for my many more projects. So I thought perhaps I can then use spi tmc2216 at the same time. Pico can entertain many more spi devices. I found both devices have similar config registers.
So learning one device is actually two devices together, as long as you are comfortable playing with uart and spi.
Another reason for playing with both is that when I searched for tmc2160 and tmc2209, I found almost all question is SE forums are one tmc2130 and tmc2208 which is a bit out of date. As I am just learning, so no harm but actually wise to learn new things.
me either used the DIAG thing. I guess it is for diagnostic or warning over current which means motor should be over heated. About optimum frequency, I just found out that, when playing with the mks motor driver testing tool, that even for a working frequency range, there are unique frequencies that the motor starts to tremble.
I read that there are some thing called “resonant” frequencies that the motor would oscillate. So the mks testier is handy to scan for such trouble making frequencies.
Next step is to use the mks tester to locate the trouble making frequencies and use a scope to check out if there are oscillations in the frequency range. I also need to look at closely the relations between current, voltage, motor current, and frequencies and duty cycles etc. I am a newbie in using “chopping mode” driving, so I need to spend some time building up knowledge in this area.
Ah almost bed time. So see you tomorrow.
7 hours later…
Ah, my apologies. Perhaps I missed sending you the relevant chats. They are:
(1) https://chat.stackexchange.com/rooms/133950/discussion-between-tlfong01-and-kyrpav (started with tb6560)
(2) https://chat.stackexchange.com/rooms/133829/discussion-between-tlfong01-and-sandro (started with drv88091)
(3) https://chat.stackexchange.com/rooms/133206/discussion-between-john-and-tlfong01 (started with tmc2130)
(4) tmc5160 (can do both SPI and UART)
To summarize, tmc2130/60 can do spi, tmc2208/2209 can do uart, tmc5160 can do both.
(5) TMC5160 V1.2 SPI Stepper Motor Driver S5160 High Power Stepstick Mute Driver For 57 Stepper Motor F6 SKR V1.3 Board VS TMC2130
Or I should not refer you the chats, but the real answers:
(8) Rpi Pico MicroPythpn Controlling TMC2208 / TMC2209 Stepper Motor Driver Problem – Asked 1 month ago, Viewed 466 times
(9) tmc2209 driving stepper motor demo
In Refs 8 and 9, I played with 2209, using pico to generate steps. I could send a number of steps, instead of non stop PWM signals, to move the motor for a specified distance. See ref 9 and relevant demo code for detials.
2 hours later…
Now I have done the following:
1. Replaced the DMX542 driver module by tmc2160 module,
2. Replaced the mks osc stepper motor testing board by the XY-LPWM3 sig gen module. I don’t like the mks tester because (a) it has three oscillators with overlapping ranges of signal frequencies, so it is awkward to switch frequency ranges (b) there is no display of the frequency, and and need to use the scope or a frequency counter. So the XY-LPWM sig gen is handy.
I reconfirmed that 5kHz is a generally good centre frequency to do experiments.
I tested the frequency range from 1kHz to 6kHz. 5kHz is still annoyingly noisy. Below 3k the motor trembles. So I need to do some fine tuning.
So I have manually tested the tmc2160 stepping motor driver board using the following hardware: (1) 12VDC PSU, with current sensing resistor 0.5 Ohm, (2) tmc2160 stepping motor driver module, (3) NEMA17 stepping motor with speed encoder, (4) XY-PWM3 PWM sig gen (to generate the step pulses to input to tmc2160). So far so good.
Now I am coming back to your question, and suggesting an answer.
Let me summarize your question below. Please feel free to comment or make comments, clarification, suggestions to edit/update your question.
How to use ESP32 to talk to the TB6560 stepping motor driver, to control a classic NEMA17 stepper motor, of 1.8 degrees per step, 200 steps per revolution, in microstepping mode of 1/8 resolution.
2 hours later…
From what i see you deep in all these tmc chips
can we some summerize
From what i understood : TMC2209 –>1.2A, or 2A from what i saw
TMC2160–> 4.8A (though you where saing it is 10A but in any board you send i saw 4.8 or something close to 5)
TMC5xxx –> from what i remember is around 3A but it needs external mosfet (i did not get why is needed)
also the majority of these chips gives you possibility to go with spi if you remove the 0ohms resistor somewhere in the chip.
it seems the 2160 is the best choice. but which version and module can you send a link?
For the program there is no clear solution if i understand well if we go in same low or hight frequencies yes first you have resonance issue and then motor stops
so you can not go all the way down with frequencies until you stop the motor.
So what did you do on you robot to move with pid did you use same gate logic in order to stop frequency falling down from some limit?
which i suppose you found the limit with manual tests?
@kyrpav Just a quick reply. TMC2160 datasheet says motor coil current is up to 20A (with external mosfets). I need to check if my module has any ext mosfet.
Just now I checked the product sheet which says only 4.33A: item.taobao.com/…
So I made a big careless mistake. My apologies.
@tlfong01 since i am not so in to this if you can send me picture with this or with where and how to set the mosfet it would have been great. or if there is a module that already has this on.
2 hours later…
No problem. I am a N-channel power MOSFET H-bridge ninja. But there are other alternatives of adding an external bridge. The first thing that come to my mind is using the BTN7971B, you might like to skim the datasheet to get a rough idea how large current it can take.
For my application of Lunar Java Tube Exploration MPV, there is no need to drive fast, so I am thinking of using a bigger 57BYJ stepper, with an additional big gear ratio box, so it can easily pull up any heavy thing accidentally fallen into the Java cave. Let me show you the look of the heavy duty 57BYG stepper with the 2GN3K gear head.
Ah, locking down supper time. See you later.
2 hours later…
I would suggest you to read the following two posts to get a rough idea of the use of DC Motor Driver, and BTN7971B.
(1) How to use motor drivers with H-bridge and PWM input, to control direction and speed of DC motors? – Asked 2020jul16, Viewed 2k times
(2) Motor Driver Fryinbg DC Gear Motor Problem (Appendix D – BTN7971B)- Viewed 200 times
Now something important to clarify.
1. How A full H-bridge DC Motor Drive uses PWM frequency and duty cycle control the speed of a DC motor.
2. Does a step motor driver uses duty cycle (other than frequency) to control the speed of a step motor?
The answer to the second question is NO. Can you explain why?
6 hours later…
i have worked again with dc motor and L298N i have build a pcb to use 2 dc motors , i know how to use them and with the pwm to control the voltage send to the motor and with this the speed. with the nema i had only worked with linuxcnc so i did not maid other solution
i will continue my tests and program with the tb6560 until the tmc2160 arrives and then i will switch
I want to ask you also do you have any experience with ILI9481 lcd? and touch screen with esp32.
i bought something for this project in order to show the set points of the tension and also to control the program from this but i cound not find the proper way to make it run at all.
i have opened an issue on espo community
Quick replies: (1) My ILI9xxx TFT LCD out of date: Rpi3B/Rpi4B ILI9341 / XPT2046 SPI 2.8″ Touch TFT LCD Connection / Driver Problem – 2019may13, Viewed 8k times
(2) l298N is good for newbies to learn
Last msg too old to edit, this is an update: (2) l298N is good for newbies to learn DC Motor Drivers. You can search Rpi SE many of my post on this subject. (3) You can also consider using L298N as the external H-bridge for tmc2160. (4) If you use MicroPython to prototype your projects, I can mirror your experiments in my Rpi Pico MicroPython Thonny
(5) If you ask about ESP32 in this EESE forum, perhaps more users might come to help.
(6) I have 2 esp32 board in hand: (a) D1 LOLIN32 V1.0.0 ESP32 wifi and BT CP2104 – TaoBao
(b) ESP32 WIFI+BT 2 in 1 for IoT app – TaoBao
I use to play with esp8266-12, using LUA, but find it hard to use event driven programming. Now I am using Rpi Pico MicroPython. I know esp32 can also do MicroPython, so can do MicroPython programming with Pico on my side, and MicroProgramming ESP32 on your side, sort of pairing programming/development on your side.
The TaoBao shop selling me esp32 stuff 2 years ago has many up of date goodies. Perhaps I would buy some new ones to update my knowledge and skills: shop468430569.world.taobao.com/…
Is your esp32 in that shops’s list of products? Perhaps I can buy that to join your esp32 projects.
I don’t understand what do you mean by “set points of the tension”. Is your project a College/Uni EE final year individual/group project, or just a hobbyist project, like mine?
I have been watching Cornell U Rpi Projects, to learn what those college guys are doing: skovira.ece.cornell.edu/ece5725-spring-2021-projects. Is your project like them?
And this Cornell U’s Robot Car project is what I am interested about: Robot Navigation ECE 5725 A Project By George and Nei-Chun
6 hours later…
Now I am testing tmc2160 another time, using NEMA17 motor (NEMA23 is too heavy, too awkard to handle!). I am using the scope to take a close look of the signal waveforms: PWM (5kHz, 50% duty cycle), motor encoder signal (speed), and motor coil current (total PSU current, using Rsense, current sensing resistor 0.5 Ohm)
The still pics below.
@kyrpav You LCD with a 40 pin connector is hard for newbies to handle. You might have read my answer to a similar question of ILI9xxx. It took me perhaps 48 hours to understand the details, and how to use the driver. If your vendor gives you the driver for ESP8266/ESP32, then it might be easy, if there are no SPI conflicts.
As mentioned in this post on ILI9341, you might like to search for the driver for esp32, but the chances of finding one is slim: raspberrypi.stackexchange.com/questions/98549/…
4 hours later…
Now I am reading a esp32 board review, before I make up my mind which esp32 board to order from TaoBao.
ESP32 Development Boards Review and Comparison – Sara Santos, MakerAdvisor, 2021may31
I found the following EPS32 board (ESP32 CH9102X WIFI BT) most newbie friendly. So I will place my order now.
(1) New Version ESP32 CH9102X WIFI BleuTooth Dev Board – ¥21
I also found the tmc2225 module also good. So I will also place an order.
(2) TMC2225 42 stepper motor driver module – BigTreeTech ¥16
(3) tmc2225 (2A, 36V, uart interface, internal current sense resistor, 256 microsteps) Datasheet – Trinamic
Now I am looking the tms2160 test results: pwm vs motor speed vs motor coil current. Now I think that the current hardware setup can be used to test DC motors (say, testing two DC motors, each with one coil, vs testing two coils of one stepper motor.
I am not taking any measurements (frequency, speed, current) now, because the scope displays only give a rough picture of the magnitudes of this manual testing. It is only when I use software setting (individual/separate step pulses vs continuous PWM waveform, using interrupt input functions to measure speed encoder events, (current mirror + ADC to measure motor current values).
Also the current current sense resistor of 0.5 Ohm is ugly looking and imprecise. I will wait for the tmc2225 with internal current sense resistance to more accurately measure the coil current. And if I use chopping mode operation, it is not useful to measure the realtime current using repeatedly ADC measurements and taking average etc.
5 hours later…
i am not into micropython. my projects are personal.
not school or university. my university time passed years ago.
i can propose the devkitc
for the esp
either way my decision is to buy the tmc 2225 and 2160 and play also with them but i will probably finish the program with the tb6560 until that time.
I will also check your link for the ili and i will have to read the datasheet and implement a driver i suppose
except if i buy a itead screen and your their programs
i will also try to dig more into lvgl