Uncategorized

esp32 mcpwm notes

tlfong01

tlfong01

Thu 16:16

Just now I checked the product sheet which says only 4.33A: item.taobao.com/…

So I made a big careless mistake. My apologies.

kyrpav

kyrpav

Thu 16:29

@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…

tlfong01

tlfong01

6932

Thu 18:26

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.

57bygh motor 2022feb1001

user image

Ah, locking down supper time. See you later.

2 hours later…

tlfong01

tlfong01

6932

Thu 20:40

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
electronics.stackexchange.com/…

(2) Motor Driver Fryinbg DC Gear Motor Problem (Appendix D – BTN7971B)- Viewed 200 times
electronics.stackexchange.com/…

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…

kyrpav

kyrpav

941

Fri 2:42

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

esp32.com/…

but noone seems to know anything

6 hours later…

tlfong01

tlfong01

6932

Fri 9:14

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
raspberrypi.stackexchange.com/…

(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
item.taobao.com/…

(b) ESP32 WIFI+BT 2 in 1 for IoT app – TaoBao
item.taobao.com/…

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.co…

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/…. 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
courses.ece.cornell.edu/…

6 hours later…

tlfong01

tlfong01

6932

Fri 15:56

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)

tmc2160 test 2022feb1101

The still pics below.

user image

user image

user image

tlfong01

tlfong01

6932

Fri 16:20

@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/…

4 hours later…

tlfong01

tlfong01

6932

Fri 19:55

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
makeradvisor.com/…

tlfong01

tlfong01

6932

Fri 20:23

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
item.taobao.com/…

I also found the tmc2225 module also good. So I will also place an order.

(2) TMC2225 42 stepper motor driver module – BigTreeTech ¥16
item.taobao.com/…

(3) tmc2225 (2A, 36V, uart interface, internal current sense resistor, 256 microsteps) Datasheet – Trinamic
trinamic.com/fileadmin/assets/…

tlfong01

tlfong01

6932

Fri 21:12

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…

kyrpav

kyrpav

941

yst 2:22

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

kyrpav

kyrpav

941

yst 2:38

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

8 hours later…

tlfong01

tlfong01

6932

yst 10:11

@kyrpav So I already placed my TaoBao order with the cheapy tmc2225 and esp32 CH9102X.

user image

tlfong01

tlfong01

6932

yst 10:21

@kyrpav esp32 devkitc also looks good.

ESP32-DevKitC WROOM-32D/U – TaoBao ¥21.75
item.taobao.com/…

I have not considered devkitc because it has something called “wroom” which I don’t know about and worry that it might make things too complicated.

@kyrpav ILI9xxx drivers are too hard and too tedious for me to follow. So I gave up for good. I forgot what is itlead screen and lvgl, but not urgent for me now. Perhaps I might comment later.

11 hours later…

tlfong01

tlfong01

6932

yst 21:08

The BigTree shop has already given my tmc2225 module to the SF Express. So my toy is on its way, should cross the border tomorrow, and arrive town tomorrow, or day after tomorrow. So I am now doing JIT (Just In Time) research to get ready rapid prototyping.

Now some references:

(1) TMC2225 Motor Driver Module V1.1 – Tinytronics €8.50
tinytronics.nl/shop/en/…

(2) TMC5161 Motor Driver Module V1.1 – Tinytronics €25
tinytronics.nl/shop/en/…

(3) TMC2225 Eval Board – Trinamic
trinamic.com/fileadmin/assets/…

(see full text)

And some wiring docs:

user image

user image

Ah, almost bed time. So see you tomorrow.

17 hours later…

tlfong01

tlfong01

6932

13:52

At the same time, I am learning how to use MicroPython for ESP32, and perhaps try to run your program to generate PWM signals. I am starting to read the following referenes:

(1) ESP32 – Getting started with MicroPython on the ESP32
docs.micropython.org/en/…

(2) ESP32 MicroPython Download (Also for RP2040, STM32 etc)
micropython.org/download/…

(3) espressif/esptool Public (pip install esptool)
github.com/espressif/esptool

I am using waiting for my new esp32 toys to arrive, hopefull sometime next week. In the mean time, I will try my luck on my old esp32 boards, which I bought some years ago, together with esp8266-12 boards. I only tried them to play with LUA, but found it very difficult to write the event driven LUA code. So I gave up. Below are the esp32 boards I found lying in my junk bin for 2 years, collecting dust:

user image

1 hour later…

tlfong01

tlfong01

6932

15:07

But then SFexpress says my new toy esp32Ch9102x has already come to town. So I changed my mind and played with my new toy first.

(removed)

user image

So now I know BigTreeTech Official Shop ShenZhen takes less than 2 working days (Sat 0900 ~ Sun 2400) to delivery my tmc2225 toy.

tlfong01

tlfong01

6932

15:37

Now I am going to write a esp32 micropython program to do the following:

tmc2160Send16kStepsAt1Kz() # send 16,000 step pulses of PWM frequency 1 kHz, ie, each step pulse width is 0.001s or 1ms. So the 1.8 degree/step, 200 steps per revolution, motor should move 16000 steps, or 16000 / 200 = 80 revolutions. The time taken should be (16000 steps) / 1 ms/step = 16 seconds.

Note: The OP’s program creates a PWM signal frequency, eg, 1kHz, while my program creates individual steps pulses with pulse width 1ms. In other words, the OP can specify to move the motor for a period of time, say 1 second (resulting 1,000 step pulses), while I need to specify 1000 steps, (resulting 1 second).

This is a complete listing of my Rpi Pico MicroPython Program of sending 16,000 step pulses to the tmc2225 (tested on tmc2160).

penzu.com/p/2a7cf34d

tlfong01

tlfong01

6932

16:18

I found that my new esp32 new toy is devkit tvi.

So I guess it should be compatible or newer than you devkit c. So it should be easy for us to compare and contrast our programming code.

user image

tlfong01

tlfong01

6932

16:49

I googled further and learned more about esp32, such as devKit C, devKit v1, Wroom, esp32 Adruino IDE etc. I have not googled much about MicroPython, my feeling is that it is not that mature. So I might goto Arduino first.

(1) esp32 Wikipedia
en.wikipedia.org/wiki/ESP32

(2) esp32 devKitC
espressif.com/en/products/…

(3) esp32 devKitC Boards
espressif.com/en/products/…

(4) Insight Into ESP32 Features & Using It With Arduino IDE – LastMinuteEngineers
lastminuteengineers.com/…

(5) esp32 devKit V1
blog.scottchayaa.com/post/…

After skimming the above googled references, I have the first impression is that esp32 is much more powerful than Rpi Pico MicroPython, though not so powerful as stm32. But for my humble IoT applications, esp32 with Arduino IED C++ is just optimum. (The OP’s choice of Espressif’s IDF is too pro for me hobbyists).

Ah, almost locking down supper time. So call it a day. Would carry on tomorrow.

(6) Carry On – youtube.com/…

(7) Day is done – youtube.com/…

3 hours later…

tlfong01

tlfong01

6932

19:49

Ah, when I made the earlier comments, it was a gloomy Sunday afternoon, so I wrongly though thought that it was time to get to bed. Actually it was only 4pm. So after a short nap I didn’t found sleep and could play for a couple of hours more. 🙂

So I carried on my studies and made the following summary pictures.

user image

user image

I surprisingly found out that esp32 is strong in handling PWM stuff, and that what esp32 says “MCPWM” is actually “Motor Control PWM” and should be handy to do motor PWM.

So I think I must google in this mcpwm to be able to understand and debug the OP’s code on PWM. Now more references I googled:

(8) In-depth ESP32 PWM Tutorial | How to use PWM in ESP32? – Ravi Teja, 2021mar12
electronicshub.org/…

(9) ESP32 MCPWM
docs.espressif.com/projects/…

(10) esp32 and pico DIY PROJECTS – Electronics Hub
electronicshub.org/…

tlfong01

tlfong01

6932

20:15

I skimmed Ref 9 and found it surprisingly complicated, because of its very lower level API and macros. An example is that it have macros to configure the deadtime of switching two half H-bridges, and also inputting motor speed by Hall sensors, and syncing two PWM operators for fault.

But I found two reasons that I should be use esp32’s mcpwm: (1) They are too lowlevel, so may be good one is developing DC/BLDC motor drivers using two barebone half H-bridges, or power MSOFET current switches.

(2) The whole mcpwm is designed for BLDC/DC motors, nothing is considered with stepper motor in mind. In short, esp32 is “useless” for stepper motors. (3) And if we are using stepper motor drivers such as tmc2130/2160/2208/2209/2225, all the esp32 mspcm tricks are actually handled in hardware/firmware, so should be more time/compute efficient.

Conclusion, I will forget esp32 mcpwm and go direct use tmc2225 as planned.

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.