using blue pill for stepper control - related to 3d printers

What are you developing?
Post Reply
ag123
Posts: 810
Joined: Thu Jul 21, 2016 4:24 pm

using blue pill for stepper control - related to 3d printers

Post by ag123 » Sat Oct 21, 2017 5:48 pm

with the recent interest in 3d printers has anyone thought about using blue pills as stepper motor controllers? The main motivation is *microstepping* and *higher currents* and *reducing* the number of interfacing *pins*

for sure there are already the A4988
https://www.pololu.com/file/download/a4 ... e_id=0J450
https://www.ebay.com/sch/i.html?_nkw=a4988&_sacat=0
and the better drv8825
http://www.ti.com/lit/ds/symlink/drv8825.pdf
https://www.ebay.com/sch/i.html?_nkw=drv8825&_sacat=0
which are now literally 'plug in' modules for RAMPS type boards and a lot of 'cheap' 3d printer controller boards i'd guess

but those chips are very hard to *cool* due to the small foot print, especially if you want to drive more currents into the motors
reprap has a very nice article about stepper motors torque
http://reprap.org/wiki/Stepper_torque
if one use 'high inductance' motors with lots of fine windings, the good thing would be that you could use very little current to drive that motor.
the bad thing is that the motor is incapable of any speed as if you drive up the stepping frequency, torque would drop drastically due to its high inductance

in addition the above chips only use DIR and STEP pin when ends up with the mcu needing more interfacing pins as controllers can't share these pins.
And the control is very 'chatty' requiring a tight loop between the mcu and several motors for every (micro) step

then of course there is the very *smart* L6470 from ST, that can do SPI and can literally drive the motor using *commands*
http://www.st.com/content/ccc/resource/ ... 255075.pdf
the only trouble is that it cost a whopping ~$9-$10 for that 'smart' a chip
https://www.ebay.com/sch/i.html?_nkw=l6470&_sacat=0

digging further lead me to the L298N
http://www.st.com/content/ccc/resource/ ... 000240.pdf
the trouble is that this is a bipolar device rather than a FET device (runs hot perhaps due to the 0.7v bipolar voltages)
it is designed to be bolted to a heat sink which is a big plus
https://www.ebay.com/sch/i.html?_nkw=l298n&_sacat=0

but the trouble is that L298N is merely a more versatile h-bridge with current sense. it needs a mcu, pwm with current sense etc to do all that elaborate *microstepping*

out of curiosity i've taken a look at stm8s which has nice timers similar to stm32f103 and is cheaper. But the trouble is stm8s open sourced development tool chain isn't quite as robust as stm32f103, e.g. it seemed there isn't an open sourced alternative to debug stm8s as stm8s don't support swd, openocd etc simply won't work
viewtopic.php?f=52&p=35790&sid=93d10c03 ... efb#p36029

hence it seemed we're left with the venerable stm32f103 blue pills or maple mini to take on the job driving the rather high amp L298N h-bridge and do elaborate microstepping etc, with all that 'heavy duty' heat sinks we'd probably be able to drive the motors at a full 1 amp or more on each windings achieving *high speeds* (of course the question then is if the motor may overheat) :lol:
blue pills & maple mini is interesting as we may not even need SPI, it can digest and filter g-codes from the host over usb-serial.
but the protocol will be 'complex' in a sense that now we'd have a 'multi controller' 3d printer controller, the co-ordination would move beyond those 'monolithic' controller driver firmware like marlin, et.al. it'd involve a lot of interaction with the host over usb and multiple blue pills / maple minis etc forming a complete 3d printing controller

lacklustrlabs
Posts: 9
Joined: Fri May 05, 2017 12:35 pm

Re: using blue pill for stepper control - related to 3d printers

Post by lacklustrlabs » Sun Nov 19, 2017 12:48 pm

I am planning on doing something similar, a generic slave pid module for stepper, servo (dc-motor + encoder) or just temperature control for 3d printers.

Right now I'm working on preparing the infrastructure needed:
* fast and reliable communication (slave mode I2C, slave mode SPI, RS485 or just plain serial)
* reliable workaround for the stm32f103 16bit timer limits. An extruder motor decoder can't have position overflow for days at full speed.
* hack or find a fork of a 'monolithic' controller driver firmware to use these co-processors/modules.
* look into how to get micros() without having to wait up to a millisecond to get result :/

I was planning on using Maple minis because they're dirt cheap. Making it feasible to have a module per axis, heater, extruder or whatnot.
But maybe an overclocked esp8266 is a better alternative, one can do a lot of bit-banging at 160Mhz.

ag123
Posts: 810
Joined: Thu Jul 21, 2016 4:24 pm

Re: using blue pill for stepper control - related to 3d printers

Post by ag123 » Sun Nov 19, 2017 7:56 pm

while searching up ebay/aliexpress i noted that other than those pre-built breakout modules discrete l298n chips doesn't seem easily available on ebay / aliexpress
https://www.ebay.com/sch/i.html?_nkw=l298n&_sacat=0
is the l298n 'discontinued'? it still seemed a rather popular chip / monolithic (stepper) motor driver
a main issues about those l298 breakout modules is that the current sense lines are simply grounded, one would need to cut the pcb traces and hack some wires into it if you need to do some current sensing, it is pretty critical for PWM microstepping

it seemed quite possible to replace l298 with discrete transistors just that the number of components counts would be quite a few more rather than 'monolithic' it would take 4 transistors per bridge (probably an additional smaller 2 to switch the alternate pairs) and hence 8 transistors (+4 smaller) for 2 sets of bridges per stepper

an interesting alternative seem to be ta8050p
http://www.bristolwatch.com/ele2/TA8050P.htm
http://www.sullivan-county.com/ele/pdf/ta8050p.pdf

there is also the cheap china l9110 which can take only a mere 800ma
https://www.elecrow.com/download/datasheet-l9110.pdf
this probably won't survive the 3d printing currents

not too sure if there are low cost FET h-bridges for the same

found some but hardly 'low cost'
http://www.ti.com/lit/ds/symlink/lmd18201.pdf
https://www.ebay.com/sch/i.html?_from=R ... 01&_sop=15
from stm l6201
http://www.st.com/content/st_com/en/pro ... l6201.html
http://www.st.com/content/ccc/resource/ ... 000089.pdf
https://www.ebay.com/sch/i.html?_nkw=l6201p&_sacat=0
but l6203 seems to fit the bill :D
https://www.ebay.com/sch/i.html?_nkw=l6203&_sop=15

found yet another DRV8833 from TI
http://www.ti.com/lit/ds/symlink/drv8833.pdf
https://www.ebay.com/sch/i.html?_nkw=drv8833&_sacat=0
drv8841 higher voltage and pricier
http://www.ti.com/product/DRV8841
https://www.ebay.com/sch/i.html?_nkw=drv8841&_sop=15


my thoughts are that it is not necessary to stick with the status quo, we can actually have multiple BP/MM as 3d printer controllers performing different functions, the activities co-ordinated from a central host / pc over usb

lacklustrlabs
Posts: 9
Joined: Fri May 05, 2017 12:35 pm

Re: using blue pill for stepper control - related to 3d printers

Post by lacklustrlabs » Mon Nov 20, 2017 11:05 am

my thoughts are that it is not necessary to stick with the status quo, we can actually have multiple BP/MM as 3d printer controllers performing different functions, the activities co-ordinated from a central host / pc over usb
Synchronizing multiple BP/MM over USB can be difficult, it's probably easier to have a central BP/MM giving orders + sync pulses to slave BP/MM modules. The central would have to use some fancy g-code look-ahead and prepare the slaves a head of time.
If there is one slave BP/MM per axis the synchronization will have to be top priority.

When it comes to motor driver hardware I'm content with l298n, A4988 and DRV8825 for now. They are 'good enough'™ for prototyping.

ag123
Posts: 810
Joined: Thu Jul 21, 2016 4:24 pm

Re: using blue pill for stepper control - related to 3d printers

Post by ag123 » Mon Nov 20, 2017 3:28 pm

yup, i do agree that running off a single core mcu is probably the simpler approach doing so in a loop for the present firmwares like marlin etc
however, one issue is that blue pills / maple minis has a rather limited number of pins, controlling a h-bridge directly would probably need 2 pins for each winding, hence 4 pins per stepper, that's just driving the motors. then if you want to do current sensing in particular for micro-stepping it would mean 1 analog pin for each winding, that means 6 pins per stepper (not really a lot but it takes up some pins), if there are 4 steppers e.g. x, y, z movements + 1 extruder that makes 24 pins just for motor control.

this could be rather easily handled say using a stm32*vet board which has lots of pins, i'm not too sure if there are enough timer pins for pwm to do that though. hence, there is some motivation to say use perhaps 2-3 blue pills / maple mini to do the job of 1 controller. there is some benefits too as when the motor control BP/MM are busy handling the motors, the 3rd blue pill can do things like monitoring / controlling temperature, fans, check end stops etc

i read up a little on things like scada, modbus, 2 phase commit, DCS
https://en.wikipedia.org/wiki/SCADA
https://en.wikipedia.org/wiki/Modbus
https://en.wikipedia.org/wiki/Two-phase_commit_protocol
https://en.wikipedia.org/wiki/Distribut ... rol_system

using the pc as a central host running modbus over usb-serial, i'd imagine that a rather simplified (dumb) scheme may be to distribute 3d printing g-codes with a 2 phase commit protocol, so that we can send the g-code, wait for the ready to commit message from the motor driving BP/MM, then issue a code to signal a commit to all the BP/MM. a trouble with this that i'd imagine is that the BP/MM would run a very busy loop monitoring commands, ack that, monitor commit command then execute that next motor move, in between all that it may still need to parse the g-code, calc the microsteps, physics (speeds, acceleration, deceleration etc), monitor ADC for current sensing, do microstepping calcs, tweak pwm to do fine microstepping. it may be rather challenging to keep the real time-ness to achieve sync / concurrency across all 4 motors and yet move with fluid smooth movements. of course the other way may be to make the host 'smarter' and perhaps do the physics (acceleration, const speed, deceleration) and geometry (steps) calcs , and send the BP/MM simple motor commands so that BP/MM focus on just microstepping just as would the normal stepper drivers

i'd guess these ideas are best considered 'experimental' but they seemed interesting

an alternative may be to make some BP/MM as SPI slave motor drivers, in that way they would simply execute motor movement commands and focus on the microstepping (still in a busy loop but possibly less complex), i.e. they simply replace conventional motor drivers socs

ag123
Posts: 810
Joined: Thu Jul 21, 2016 4:24 pm

Re: using blue pill for stepper control - related to 3d printers

Post by ag123 » Mon Nov 20, 2017 6:19 pm

oops a nema17 stepper i bidded on ebay arrived, i decided to go for the plain old and simple l298n
i go for a module instead, it seemed the sum of the parts l298n, heat sink, diodes, caps, board, connectors (and they throw in a 78L05 regulator onboard) would actually cost more than simply buying the module and it is soldered / assembled
https://www.ebay.com/sch/i.html?_nkw=l298n&_sacat=0
i'd then need to figure out how to cut the traces to get at the current sense pins

http://www.st.com/en/motor-drivers/l298.html
http://www.st.com/content/ccc/resource/ ... 000240.pdf
at a saturation voltage of around 2.5v per bridge for 1a, it would seem if both internal h bridges are active and i run 1a across that would generate about 5 w as wasted heat,

parasole
Posts: 4
Joined: Tue Mar 28, 2017 3:07 am

Re: using blue pill for stepper control - related to 3d printers

Post by parasole » Fri Dec 15, 2017 2:54 am

There are few interesting open sourse "duino" compatible project which enable any stepper to become a servo, perhaps a better path is just to port one of these? And interesting implementation might be to have a common CPU for 3-4 steppers, having on stepper board just position sensor and motor driver...

mechaduino:
http://tropical-labs.com/index.php/mechaduino
https://github.com/jcchurch13/Mechaduino-Hardware
https://github.com/jcchurch13/Mechaduino-Firmware

Similar to above nano_stepper:
http://misfittech.net
https://github.com/Misfittech/nano_stepper

simpler and cheaper ustepperr, interesting side of this project that you may use cheap Polulu A4988 driver as is:
http://www.ustepper.com/index/what-is-ustepper/
https://github.com/uStepper/uStepper

lacklustrlabs
Posts: 9
Joined: Fri May 05, 2017 12:35 pm

Re: using blue pill for stepper control - related to 3d printers

Post by lacklustrlabs » Sat Dec 16, 2017 3:17 pm

Interesting.. do you know if any of these closed-loop-duino-drivers are supported (e.g setting PID parameters) by marlin or grbl? Yes, I admit - i didn't spend time investigating it myself.

ag123
Posts: 810
Joined: Thu Jul 21, 2016 4:24 pm

Re: using blue pill for stepper control - related to 3d printers

Post by ag123 » Sat Dec 16, 2017 7:14 pm

thanks, i think mechaduino, nano stepper and ustepper are good projects that's pretty much 'been there done that'
one of the interesting things about the stepper control projects is the use of PID closed loop feedback control
as this you tube video illustrates, it could make a difference in terms of preventing missing steps
https://www.youtube.com/watch?v=s2dpCpUqGnE

found a video of mechaduino in action
https://www.youtube.com/watch?v=Lb030bdcfjc

well, this would likely be more 'experimental' than really practical for now, it is probably simplier and perhaps more practical to work with integrated stepper controllers like a4988 or drv8825 for ordinary 3d printers.
one of those things i noted would be that the voltage and thus currents across the motor depends in part on the pwm time slices
http://homepage.divms.uiowa.edu/~jones/ ... t.html#pwm

at the moment i think this is controlled via a variable resistor on those drv8825 or a4988 modules
that's a practical solution to limiting the currents into the motors (it'd probably at least affect the speed, torque and likely vibrations/resonances)

Post Reply