Hi Peeps!
First time posting, been lurking a while trying to find answers to my intentions:
I have built a motorized injection machine that I wish to add to the Precious Plastic initiative, that originally wished to control via Arduino (I am pretty familiar with ArduinoIDE, making functions, state machine, etc), and had so far got an isolated setup with FastAccelStepper to move the motor very nicely, both continuous via button press until release, and commanded moves, endstops to stop movement, and was adding encoder support (this stepper has a 1000PPR optical AB encoder), but here started running into issues, as the interrupts on the Arduino are used by both FastAccel and Encoder, slow speeds work, but medium speeds start to interfiere, steps lost on motor, encoder also loses pulses, etc…
so after a look at alternatives, decided for BluePill, as was basically only STM32 available locally, and having hardware encoder support and motor timer PWM support offloaded from MCU, thought would be great to get the hard calcs/counters onto dedicated interfaces… THEN I found SimpleFOC and obviously the attraction of uniting all the data from motor, encoder and current sensing seemed sent from heaven… had seen that in 2022 step/dir was not directly supported, but my workflow I don’t (strictly) need full FOC:
When Stepper motor is firstly compressing recently introduced cold plastic, with the nozzle blocked to avoid already hot plastic coming out* I WANT the stepper motor to reach full load and lose steps, as therefore I am sure that max power and compression has been applied… the same for actual injection, to make sure mould is full (depends on mould, others requiere less force)… I had created a comparison function that took the motor steps ordered and the encoder feedback, and when there start to appear a discrepancy, then this is because motor is losing steps, so back off speed, but keep going until new threshold of loss is past, etc, until speed is below min…
I was also contemplating incorporating current sensing to add to the mix, and detect similar situations (later testing would indicate which system is more reliable), so finding SimpleFOC seemed ideal…
- (production works on reload after each injection, but full stroke may do 3-8 injections depending on mould size, plastic takes 10-15 mins to heat up, so adding after each injection and making sure a full strokes worth of plastic takes at east 15mins helps maintain continuous (paused between each injection!) production)
So I am somewhat confused about the current state of controlling stepper motors via step/dir commands, the speed/dir driver is for listening, not sending commands…? have not been able to find an image of how to actually wire a step/dir setup, all seem for at least 2PWM set up, using 2 half bridges for complete phase control (necessary for full FOC support), but I am relying on encoder positioning to maintain realtime plastic use, plunger position (later wish to add a ESP32 Display to show the reported plastic Refills, with a graphic that can show coloured rectangles with times since intro, so the user can see how much hot-enough plastic is available for next mould size (which will also be stored in ESP32 Display as “mould-profiles”, including injection speed, amount, possible current max) which can be loaded from a pre-saved list of calibrated “NextInjection” parameteres that would be sent to the STM32 before each injection, keeping the STM32 only for actual motor movement and control…)
Sorry for the ramblings, first time trying to describe everything, may be a bit chaotic, hope someone can help me sort out best path to go forward… am learning STM32CubeIDE, a lot more confusing that ArduinoIDE, but have so far managed to assign in STM32CubeIDE and configure most of the pins for Motor Speed/Dir, EncoderA&B, USART3 for communication to ESP32 Display (although will be starting with a simpler ESP32 loaded with serial passthru to talk directly to the PC, to get encoder data every second, and beable to send new arrays of mould-profile data sets for NextInjection) SPI to thermocouple daughter board, and current sensores to phA/B (although inline current sensing image seems to indicate to use phB+/-…?) - still have to add 3 user buttons, a couple of strips of WS2812B, to change button colors as per State of machine…
I must admit I am more of a hardware guy, the machine I made some decisions what hardware could be useful, with respect to the power needed (the stepper goes thru a 20:1 reductor, drives plunger thru rack & gear), whilst having a reasonable Arduino knowledge, but did not realise the limits of Arduino would requiere something like a STM32 with dedicated hardware pins for the most intensive tasks…
To use the SimpleFOC I am doing a complete rewrite of my code, which so far was only half complete, as had run into this issue of getting driver library and encoder readings to work together… had tried various other libraries for both, but none gave good combined results… I would like to use the SimpleFOCdriver implementations if possible, as would seem to take advantage of the STM32 hardware encoder and PWM motor timing available, but as mentioned, am at a bit of a cross roads as to where to go from here, as options are various and in some cases limited…
Thanks for reading, maybe someone can do a TL;DR post after mine, I’m not good ad resuming… (although have been starting to use ChatGPT to help with Arduino programming, it helped me find an optimised version of driver/encoder code that worked at low speed where nothing else would even do that… )