Welcome! Log In Create A New Profile

Advanced

ESP32 Printer Board

Posted by CthulhuLabs 
Re: ESP32 Printer Board
January 02, 2018 11:50AM
So I just checked back in on the ADC performance issue thread for the ESP32 and it is not good at all. They have implemented a solution, but it is horrible. People are seeing major discrepancies from one MCU to another and even from one ADC channel to another using their solution. So I have added a ADC chip and put the temp pins on that. This did not solve my lack of pins issue though. I had only a single spare pin if I did not include a Z Probe. There was no room for an LCD or any other extras. To deal with this I have added a MAX6966AEE+ chip and moved the FAN pins as well as STPR_EN and PS_ON to that.

@dc42 - If you have a sec can you please take a look on CircuitMaker to see if I missed anything or if there are any other optimizations I could make? I am curious how you were able to get this to fit on just the ESP32 before.
Re: ESP32 Printer Board
January 02, 2018 11:54AM
You can put the direction pins on the expander but you need to adopt your software for it. The direction only changes at rather slow speeds and if your software can plan ahead then you can start the act of flipping the direction pin once the last step in that direction has been made. With this asynchronous dir flipping you should be good with an expander at low speeds.

I would not use SPI on the trinamcs to do the stepping. Have a look at the max. SPI clock speed. That will become a bottleneck.

The trinamics can trigger steps on each edge of the step signal. So instead of giving a pulse (low-High-low) to the stepper you can just give them a single edge (low or high). That greatly reduces the speed requirements for the step pins. But only in trinamics only mode. I still wouldn't put step pins on the expander,...
Re: ESP32 Printer Board
January 02, 2018 12:27PM
While ESP32 ADC are not accurate in absolute terms (20c on one board will be 21c on other) they are precise and measured results are repeatable (20c will be 20c at the same voltage). Therefore I don't think internal ADC is an issue for 3d printer controller (problem arises when doing IoT temperature monitors and such).

Here's a pinout for what could be SIX stepper board:

It accommodates 3 axis steppers (xyz) plus two extruders (e1, e2). ss/cs is relegated to mux switch, pwm on SPI IO expander and stop through IO expander's interrupts. ADC could be multiplexed to free up two temperature pins (they are GPI so they would have to be swapped with INT pins) towards third extruder e3step, e3dir making it a six stepper controller board. Of course, with 32 pins on the io expander one could drive more steppers with less precision but perhaps good enough for extruders)

GPIO / purpose

4 xdir
5 ydir
17 zdir
22 e1dir
13 e2dir
27 xyze1e2 EN
19 xstep
25 ystep
26 zstep
18 e1step
12 e2step
39 io exp1 MCP23S17(1) int1
21 io exp1 MCP23S17(1) int2
16 io exp2 MCP23S17(2) int1
36 io exp2 MCP23S17(2) int2
32 mux s0
23 mux s1
33 mux s2
0 mux s3
14 SPI SCK
15 SPI SI
2 SPI SO
34 temp e1
35 temp e2
36 temp bed

EDIT: removed mux chip part number as this IC was not a good choice for driving CS lines

Edited 4 time(s). Last edit at 01/02/2018 12:54PM by newbob.
Re: ESP32 Printer Board
January 02, 2018 12:39PM
The SPI control mode of the TMC2130 is for use with an external motion controller like the TMC4361. Basically it allows the motion controller to set the specific current in each coil.
Re: ESP32 Printer Board
January 02, 2018 01:00PM
@newbob - Issue report Scroll towards the bottom. People are reporting that if you use the calibration system they put in place to calibrate one channel of the ADC to a set Vref and then read same Vref with a different channel on the same ADC it can read as much as 300mv off from one to the other. What this means is you cannot set two extruders to the same temp and actually get the same temp.
Re: ESP32 Printer Board
January 02, 2018 02:09PM
I don't see that in thread you've linked to - could you point at a post that brought you to that conclusion (in the last post from 7 days ago I think the issue is that tcsaba101 is reading at the top of the range - I'd make 3250 my max)? Overall I agree, while they iron out bugs we could use SPI ADS118 to existing SPI bus and use two temp pins for another stepper smiling smiley or drive SPI display on a separate SPI bus (through spare temp pins) to lessen contention on SPI bus with CS lines controlled by mux.

Edited 5 time(s). Last edit at 01/02/2018 02:31PM by newbob.
Re: ESP32 Printer Board
January 02, 2018 02:58PM
Wouldn't the use of an SPI ADC save you enough pins for your second extruder? Assuming of course that you use a shared SPI bus.


Delta printer calibration calculator, mini IR Z probe, and colour touch screen control panel: [escher3d.com]

Large delta printer, and other 3D printer blog postings: [miscsolutions.wordpress.com]

Disclosure: I have a financial interest in sales of the Panel Due, Mini IR height sensor, and Duet WiFi/Duet Ethernet [www.duet3d.com].
Re: ESP32 Printer Board
January 02, 2018 03:39PM
I have attached the MCU schematic as I currently have it.

Right now there are no issues on the SPI bus for contention with my current design. The TMC2130's are mostly configured via SPI on initialization. After that it is just to check the status registers when the DIAG pin triggers. That leaves just the PWM and ADC chips. Because the PWM chip is handling the PWM there wont be many updates to that. As such the ADC being polled on a regular basis should be the most traffic on the SPI bus.

At this point I am more or less happy with the layout. Assuming no other major issues come up I am probably going to stick with these chips. The only thing I am considering is moving the heater PWMs to the PWM chip so there is open pins on the MCU. For safety I would use one of those opened pins as a heater MOSFET enable. That way I can kill the heaters as long as the MCU is still working.
Attachments:
open | download - MCU.png (273.7 KB)
Re: ESP32 Printer Board
January 02, 2018 03:42PM
@dc42 - I do not see how. Please take a look at my design and let me know if you see something.
Re: ESP32 Printer Board
January 02, 2018 04:20PM
@CthulhuLabs On the attached I don't see stepper DIR signal anywhere.

Btw, when using mux for CS lines - are you planning apply weak pullup on all lines? I wonder how much SPI speed would you loose that way (due to mandatory wait after CS selection)

EDIT: found it about 1uS with 4.7k pullup - that's about 300 clock cycles.

Edited 3 time(s). Last edit at 01/02/2018 04:38PM by newbob.
Re: ESP32 Printer Board
January 02, 2018 04:33PM
@newbob - It is there IO5. As for the PU res., yes. Just have not gotten that far yet. As for delay it should not do much hopping around on CS lines
Re: ESP32 Printer Board
January 02, 2018 04:44PM
I know you can apply EN to all steppers but how do you control direction with single DIR signal?
Re: ESP32 Printer Board
January 02, 2018 04:51PM
Step all steppers going one way. Flip DIR. Step all steppers going the other way.
Re: ESP32 Printer Board
January 02, 2018 05:17PM
Thanks. From TMC doc (page 69) I calculated one cycle (change dir, one step, change dir) to be 652ns (internal 4MHz clk) resulting in max pulse rate of 1533742/s.

tDSU+tSH+tSL+tDSH

20+(36+250+20)+(36+250+20)+20=652ns period

652ns cycle = 1533742.33Hz

EDIT: corrected calculations

at 128 microstepping - that's 1533742/128=11982 steps or ~11982/400=30 revolutions/s or 1800rpm.

Just for reference, power, chopper etc calculators:
TMC2130
TMC2208

All being equal TMC2208 needs to dissipate almost 40% less power than TMC2130.

Edited 5 time(s). Last edit at 01/02/2018 09:05PM by newbob.
Re: ESP32 Printer Board
January 02, 2018 10:42PM
What about killing several birds with one stone: Use an ATMEGA16u4 for everything the esp32 doesn't have. It could:

->Be a custom USB to Serial adapter
->Fix the analog issue
->add GPIO
-> PWM that is as customizable as you can get!
->controllable over SPI (slave-mode well documented) or/and UART

Price is about 4$ in single quantities, + a crystal; better than individual ADC, GPIO/PWM, and USB-serial chips.
Considering that people run entire controllers on ATMEGAs, it should have more than enough CPU.

Also, I have 2 esp32 boards (sparkfun esp32 thing) so if anyone needs someone to check code, I can help out there.
Re: ESP32 Printer Board
January 02, 2018 11:49PM
Hmm. Interesting idea.
Re: ESP32 Printer Board
January 03, 2018 12:11AM
Programming would be more complex, but it would increase functionality considerably.
Re: ESP32 Printer Board
January 03, 2018 03:49AM
There are also 8051 ┬ÁControllers available that don't need a crystal can do all that is listed and more and are cheaper,...
Re: ESP32 Printer Board
January 03, 2018 05:10AM
Quote
JustAnotherOne
There are also 8051 ┬ÁControllers available that don't need a crystal can do all that is listed and more and are cheaper,...

They don't provide the USB interface.


Delta printer calibration calculator, mini IR Z probe, and colour touch screen control panel: [escher3d.com]

Large delta printer, and other 3D printer blog postings: [miscsolutions.wordpress.com]

Disclosure: I have a financial interest in sales of the Panel Due, Mini IR height sensor, and Duet WiFi/Duet Ethernet [www.duet3d.com].
Re: ESP32 Printer Board
January 03, 2018 07:10AM
Quote
dc42
Quote
JustAnotherOne
There are also 8051 ┬ÁControllers available that don't need a crystal can do all that is listed and more and are cheaper,...

They don't provide the USB interface.

They do. The first I found:
[www.silabs.com]

And they are around 1 Dollar,...

But they don't come with Arduinoo IDE, so you have to do real programming,.. ;-)

PS: Wasn't the Idea to connect them to the ESP as an SPI slave? So why do they need to have USB?
Re: ESP32 Printer Board
January 03, 2018 09:06AM
That's interesting, I didn't know there were USB-capable 8051s.

The reason for using a USB-capable MCU was to avoid the need for a separate USB-to-serial converter chip.


Delta printer calibration calculator, mini IR Z probe, and colour touch screen control panel: [escher3d.com]

Large delta printer, and other 3D printer blog postings: [miscsolutions.wordpress.com]

Disclosure: I have a financial interest in sales of the Panel Due, Mini IR height sensor, and Duet WiFi/Duet Ethernet [www.duet3d.com].
Re: ESP32 Printer Board
January 03, 2018 09:28AM
Quote
JustAnotherOne
But they don't come with Arduinoo IDE, so you have to do real programming,.. ;-)
Have to anyways. Was going to port RepRapFirmware to this.

Quote
JustAnotherOne
PS: Wasn't the Idea to connect them to the ESP as an SPI slave? So why do they need to have USB?
Looking at replacing the FTDI serial converter with a second MCU that can act like a USB-UART chip as well as the ADC and PWM. The USB serial interface on the the second MCU would just take all data on the USB serial interface and spit it out the UART over to the ESP32. The ESP32 would give the second MCU commands over SPI though.

This chip looks like it will work EFM8UB2 and it is only 2 bucks.
Re: ESP32 Printer Board
January 03, 2018 09:37AM
Quote
CthulhuLabs
Looking at replacing the FTDI serial converter with a second MCU that can act like a USB-UART chip as well as the ADC and PWM. The USB serial interface on the the second MCU would just take all data on the USB serial interface and spit it out the UART over to the ESP32.

Bear in mind that if you do that, you don't get any hardware flow control - just like almost all 8-bit controller boards - so the board will have to use software flow control to the host PC. This is a serious issue if you are trying to print over USB, or upload files over USB. But if you expect the USB port to be used only for debugging and initial configuration because you will print from SD card files uploaded over WiFi, I guess it's not a problem. Alternatively, you could use the SPI bus to do flow control, e.g. the ESP32 could periodically send the number of characters it can receive to the slave. Or you could send the USB data over SPI instead of UART.


Delta printer calibration calculator, mini IR Z probe, and colour touch screen control panel: [escher3d.com]

Large delta printer, and other 3D printer blog postings: [miscsolutions.wordpress.com]

Disclosure: I have a financial interest in sales of the Panel Due, Mini IR height sensor, and Duet WiFi/Duet Ethernet [www.duet3d.com].
Re: ESP32 Printer Board
January 03, 2018 09:54AM
Quote
dc42
Or you could send the USB data over SPI instead of UART.
... I didnt know that could be done. lol.

More over that with the second MCU acting as a slave to the ESP32, wouldnt it cause issues when the ESP32 is communicating with one of the TMC2130s?

Edited 1 time(s). Last edit at 01/03/2018 10:00AM by CthulhuLabs.
Re: ESP32 Printer Board
January 03, 2018 10:40AM
Quote
CthulhuLabs
Quote
JustAnotherOne
But they don't come with Arduinoo IDE, so you have to do real programming,.. ;-)
Have to anyways. Was going to port RepRapFirmware to this.

Quote
JustAnotherOne
PS: Wasn't the Idea to connect them to the ESP as an SPI slave? So why do they need to have USB?
Looking at replacing the FTDI serial converter with a second MCU that can act like a USB-UART chip as well as the ADC and PWM. The USB serial interface on the the second MCU would just take all data on the USB serial interface and spit it out the UART over to the ESP32. The ESP32 would give the second MCU commands over SPI though.

This chip looks like it will work EFM8UB2 and it is only 2 bucks.

Nice find - this chip seems like a perfect fit...if going that route. Given that PWM and ADC have to be 100% reliable for safety reasons I would suggest not to do it however and rather spend $3 more and keep it simple.

Edited 1 time(s). Last edit at 01/03/2018 10:41AM by newbob.
Re: ESP32 Printer Board
January 03, 2018 11:25AM
Here is an alternate MCU schematic using the EFM8UB20F32G-A-QFP32.

@newbob - I see no difference between having the Primary MCU control the PWM and the ADC through external chips vs the Secondary MCU. In fact I think having the Secondary MCU control them is better than those chips as I can put some logic into it. I gave both MCUs heater enable pins. If either wants to kill the heaters they can.
Attachments:
open | download - MCU_ALT.png (459.3 KB)
Re: ESP32 Printer Board
January 03, 2018 12:06PM
It looks neater for sure...three interrupts and individual DIR lines do offer more flexibility over old setup. Looking forward to see how it turns out.

Btw, looks like some of the GPI 34-39 are assigned output tasks...
Re: ESP32 Printer Board
January 03, 2018 12:36PM
Damn it. Did it again. Fixed in CircuitMaker. I need to check the pins on the EMF8 for that as well.
Re: ESP32 Printer Board
January 03, 2018 01:31PM
I think that reliable USB-Serial conversion could be done on an 8-bit. The arduino due uses an ATMEGA16u2 as it's USB-Serial chip.

The only drawbacks to the EFM8UB2 are that there is less code documentation (not huge issue). Otherwise, It looks like a good option. (Bonus higher clock 48 vs 16 MHz)
It also can do 48MHz at 3.3volts, so no need for level conversion. (AVR can do 3.3V, but clock goes down to 8MHz)
Looking at the page for the EFM8UB2, there does appear to be good example code.

USB-Serial code: [www.silabs.com]
other code: [www.silabs.com]

One thing I noticed is that in the thread about that USB code, it was mentioned that the connected computer didn't go to sleep if it was connected. (Good thing if printing from computer I think?)
Re: ESP32 Printer Board
January 03, 2018 02:52PM
Quote
nathan25
I think that reliable USB-Serial conversion could be done on an 8-bit.

That goes without saying. The remarks in this thread were only regarding flow control. Having the second MCU handle the USB communication means that the data somehow needs to be transfered from the EFM8 to the ESP32 and back.

Using UART for that would be possible, but then issues might arise if one of the two firmwares (ESP32 and EMF8) blocks for longer than one byte on the UART. Because then the byte would get lost.

On USB that can not happen as there the bytes would "wait" until they get read.

Choosing SPI as interface between the two MCUs could solve that. The EFM8 would be an SPI slave and buffer all incoming bytes. The EFM32 could then read the data when it wants / has time and no data loss would occur.
Sorry, only registered users may post in this forum.

Click here to login