Using a Pi Pico for an Electronic Lead Screw Controller
The purpose of this thread is to discuss an Electronic Leadscrew System based on the Pi Pico. There have been a number of other similar projects in various forums and on youtube channels, but as far as I know none have used the Pi Pico. There are many processors that can do this job adequately, this is not really to determine which processor is "best", but to study the suitability of the Pico for this task, and perhaps share some ideas and maybe even some code for this work, and to encourage others to try this for their own project(s). This is not intended to take away from the similar Teensy 4.1 project, or other similar projects, but to separate the discussions based on the specific different hardware. There are many ways to do this project!!
The more I look at the Pi Pico the more I think it is an especially suitable choice for an Electronic Lead Screw microcontroller. It has hardware and support software that is well suited for the task, and it is small, available and inexpensive. In these times of chip shortages the availability is a key feature. It is also well supported by the Pi Foundation and many tutorials, software and libraries for it are developing at a very fast pace, including support from the large Arduino community. There are multiple toolsets and environments available for the Pico already, and it is a very young microcontroller with what I expect is a very bright future.
For those not familiar with the Pi Pico, here is a summary of this new microcontroller and board from the Raspberry Pi Foundation:
Pi Pico Feature Summary
21 x 51mm (0.83 x 2.1 inches) breadboard friendly DIP format
RP2040 Dual Core ARM Cortex M0+ up to 133 MHz
265KB on chip SRAM
2MB on board Flash
26 GPIO pins including 3 Analog Inputs
2 UART, 2 SPI, 2 I2C, 16 PWM
USB controller with Mini USB connector
1.8-5.5VDC supply
low power sleep modes
accurate on chip clock (microseconds since boot in 64 bit register)
temperature sensor
accelerated integer and floating point libraries on chip
The Pico PIO has a powerful I/O subsystem with Two blocks:
Each block has Four programmable state machines, with
Two I/O FIFOS, 32 instructions, and two IRQs to the Pico,
For a total of 8 state machines with 16 FIFOS
Note that there are many other boards from other vendors that have this new microcontroller chip, and they each offer slightly different features.
Suitability for an ELS
Dual Cores are an excellent fit for a real-time system with a user interface as the ELS requires. One core can be dedicated to the real time critical performance while the other can be dedicated to the user interface and other less critical tasks. The PIO blocks can be used to provide improved hardware level real-time I/O performance in reading the spindle encoder and generating output pulses to the motor controller.
An ELS has basically one critical task - to read a spindle encoder, and at a precise ratio, control a motor that drives the carriage threading and feeding shafts. The goal is to both do away with loose change gears, and to provide a wider set of gear ratios for threading and feeding.
In many cases a lathe has a gearbox with some selections for threading and feeding, but usually this set of ratios is incomplete, especially in the smaller lathes. It may be lacking metric ratios, or some in-between less common imperial ratios may not be present or are only available by changing loose gears into the drive chain. Many ELS systems essentially ignore the existing gearbox. My PM-1228 lathe has a 15 speed gearbox, so I would like the ELS to be able to work with the gearbox rather than ignoring it, allowing me to choose gearbox settings that optimize the overall performance of the machining operation.
Real Time Requirements for an ELS
A popular encoder for ELS systems is a 1024 line rotary encoder which produces 4096 edges per rotation. If the spindle is turning 2500 RPM the resulting encoder input to the microcontroller has 170,667 edges per second, or one edge every 5.86 microseconds. While this is a fairly high rate for a microcontroller a modern chip like the Pico has a maximum clock frequency of 133 MHz so it has about 779 clock cycles per encoder event to do the processing. So it requires some care in programming but is certainly not impossible.
This can be handled by the microcontroller running in a tight loop, or by using interrupts. Handling interrupts at these rates requires care and libraries that don't turn interrupts off for more than a few microseconds at a time. Dedicating a core to the realtime task is very appealing.
Pico PIO Blocks
The Pico PIO State Machine Blocks are particularly well suited to the ELS realtime task. For example one could be used to generate the direction and step pulses with appropriate timing for the motor control. Another could be used to preprocess and decode the incoming spindle encoder signals, or it even might be possible to fit the gear ratio calculation into a PIO. I'm just starting to learn what these powerful but small state machine processors can do.
Next Steps
I have a small Pi Pico testbed set up that I've been playing with for awhile. It's reading a GPS and displaying information about GPS altitude information using MicroPython.
So far all I've done with the ELS is to research existing systems online and make notes and calculations. I do have a spindle encoder and possibly a motor controller and motor that would be suitable. The hardest part of this project is probably mounting the gear on the lathe, not making the electronics and software.
Are others interested in discussing and/or investigating a Pi Pico based ELS?
What other projects might the Pico be suitable for?
What have you done with the Pi Pico??
Alan B
The purpose of this thread is to discuss an Electronic Leadscrew System based on the Pi Pico. There have been a number of other similar projects in various forums and on youtube channels, but as far as I know none have used the Pi Pico. There are many processors that can do this job adequately, this is not really to determine which processor is "best", but to study the suitability of the Pico for this task, and perhaps share some ideas and maybe even some code for this work, and to encourage others to try this for their own project(s). This is not intended to take away from the similar Teensy 4.1 project, or other similar projects, but to separate the discussions based on the specific different hardware. There are many ways to do this project!!
The more I look at the Pi Pico the more I think it is an especially suitable choice for an Electronic Lead Screw microcontroller. It has hardware and support software that is well suited for the task, and it is small, available and inexpensive. In these times of chip shortages the availability is a key feature. It is also well supported by the Pi Foundation and many tutorials, software and libraries for it are developing at a very fast pace, including support from the large Arduino community. There are multiple toolsets and environments available for the Pico already, and it is a very young microcontroller with what I expect is a very bright future.
For those not familiar with the Pi Pico, here is a summary of this new microcontroller and board from the Raspberry Pi Foundation:
Pi Pico Feature Summary
21 x 51mm (0.83 x 2.1 inches) breadboard friendly DIP format
RP2040 Dual Core ARM Cortex M0+ up to 133 MHz
265KB on chip SRAM
2MB on board Flash
26 GPIO pins including 3 Analog Inputs
2 UART, 2 SPI, 2 I2C, 16 PWM
USB controller with Mini USB connector
1.8-5.5VDC supply
low power sleep modes
accurate on chip clock (microseconds since boot in 64 bit register)
temperature sensor
accelerated integer and floating point libraries on chip
The Pico PIO has a powerful I/O subsystem with Two blocks:
Each block has Four programmable state machines, with
Two I/O FIFOS, 32 instructions, and two IRQs to the Pico,
For a total of 8 state machines with 16 FIFOS
Note that there are many other boards from other vendors that have this new microcontroller chip, and they each offer slightly different features.
Suitability for an ELS
Dual Cores are an excellent fit for a real-time system with a user interface as the ELS requires. One core can be dedicated to the real time critical performance while the other can be dedicated to the user interface and other less critical tasks. The PIO blocks can be used to provide improved hardware level real-time I/O performance in reading the spindle encoder and generating output pulses to the motor controller.
An ELS has basically one critical task - to read a spindle encoder, and at a precise ratio, control a motor that drives the carriage threading and feeding shafts. The goal is to both do away with loose change gears, and to provide a wider set of gear ratios for threading and feeding.
In many cases a lathe has a gearbox with some selections for threading and feeding, but usually this set of ratios is incomplete, especially in the smaller lathes. It may be lacking metric ratios, or some in-between less common imperial ratios may not be present or are only available by changing loose gears into the drive chain. Many ELS systems essentially ignore the existing gearbox. My PM-1228 lathe has a 15 speed gearbox, so I would like the ELS to be able to work with the gearbox rather than ignoring it, allowing me to choose gearbox settings that optimize the overall performance of the machining operation.
Real Time Requirements for an ELS
A popular encoder for ELS systems is a 1024 line rotary encoder which produces 4096 edges per rotation. If the spindle is turning 2500 RPM the resulting encoder input to the microcontroller has 170,667 edges per second, or one edge every 5.86 microseconds. While this is a fairly high rate for a microcontroller a modern chip like the Pico has a maximum clock frequency of 133 MHz so it has about 779 clock cycles per encoder event to do the processing. So it requires some care in programming but is certainly not impossible.
This can be handled by the microcontroller running in a tight loop, or by using interrupts. Handling interrupts at these rates requires care and libraries that don't turn interrupts off for more than a few microseconds at a time. Dedicating a core to the realtime task is very appealing.
Pico PIO Blocks
The Pico PIO State Machine Blocks are particularly well suited to the ELS realtime task. For example one could be used to generate the direction and step pulses with appropriate timing for the motor control. Another could be used to preprocess and decode the incoming spindle encoder signals, or it even might be possible to fit the gear ratio calculation into a PIO. I'm just starting to learn what these powerful but small state machine processors can do.
Next Steps
I have a small Pi Pico testbed set up that I've been playing with for awhile. It's reading a GPS and displaying information about GPS altitude information using MicroPython.
So far all I've done with the ELS is to research existing systems online and make notes and calculations. I do have a spindle encoder and possibly a motor controller and motor that would be suitable. The hardest part of this project is probably mounting the gear on the lathe, not making the electronics and software.
Are others interested in discussing and/or investigating a Pi Pico based ELS?
What other projects might the Pico be suitable for?
What have you done with the Pi Pico??
Alan B