Towards ChibiOS stepper
Posted at 2015-12-27.
I got some cheap and cheerful L9110S bridge modules, so I thought why not try to spin one of those steppers I rarely use. The dual module should be able to run a bipolar stepper, which a simple darlington array like ULN2803A won't. One motor option would be old CD or floppy drive stages. I should have a few stashed away.
One thing to note about the L9110 boards is that the input lines have pullup resistors to board VCC, so they float high to the motor voltage. Controllers probably don't appreciate the voltages. Perhaps not even +5 V. The datasheet is not very clear on what the input levels are. It also doesn't contain a complete state table. These things can be figured out, though. Changing to pulldowns or pulling to logic high instead would of course solve the problem if the controller levels are ok. Otherwise it might be best to add a set of transistors as OC/OD inverters to pull the lines down with logic high.
I didn't even notice the step theme in post titles, but why not. :)
Plans
- Set up a ChibiOS task to perform sequence stepping and IO
- Set up a command to control step task
- Set up messages for the task
- Connect motor module to Maple
- Connect power to motor module (remember the pullups!)
- Test stepping with LEDs or other harmless IO
- Test stepping with bridges
- Test stepping with motors
- Test stepping with various parameters
- Implement PWM
Experiment
I picked a fresh Maple mini clone and soldered on some pin headers. I've already set up ChibiOS environment and project I can use for this. I also tested a driver board with a plain DC motor by poking the input pins to ground.
I (finally) threw together a new source file with a new task.
ch> info
Kernel: 3.0.3
Compiler: GCC 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 224288]
Architecture: ARMv7-M
Core Variant: Cortex-M3
Port Info: Advanced kernel mode
Platform: STM32F10x Performance Line Medium Density
Board: LeafLabs Maple Mini
Build time: Dec 27 2015 - 16:21:54
ch> threads
addr stack prio refs state
20002654 2000137C 64 1 SLEEPING
200026A0 20002734 1 1 READY
20001D68 20001E54 64 1 SLEEPING
20001BF8 20001CE4 64 1 SLEEPING
200027A8 20002F74 64 1 CURRENT
ch>
I realized I never looked how many threads the demo runs. So, comment out the starting line and...
ch> info
Kernel: 3.0.3
Compiler: GCC 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 224288]
Architecture: ARMv7-M
Core Variant: Cortex-M3
Port Info: Advanced kernel mode
Platform: STM32F10x Performance Line Medium Density
Board: LeafLabs Maple Mini
Build time: Dec 27 2015 - 16:21:54
ch> threads
addr stack prio refs state
2000250C 2000137C 64 1 SLEEPING
20002558 200025EC 1 1 READY
20001C20 20001D0C 64 1 SLEEPING
20002660 20002E2C 64 1 CURRENT
One less. There might be a way to decode some of that. Funny about that start time. I guess it gets compiled into another file that doesn't get rebuilt.
Next step is probably
ChibiOS HAL
for access to IO pins.
Looks like the module to find is called PAL
.
Also, the board file (check board.h
) apparently contains initial pin
configurations.
Some handy pins seem to be D18..D22.
These don't seem to have special functions and they're marked 5V tolerant.
Finding others might be necessary if using timers or other neat functions
later.
- PB4: D18
- PB3: D19
- PA15: D20
- PA14: D21
- PA13: D22
A bit scattered, but probably individually pokeable. It seems I should define a new board to change the IO definitions at boot, but I think HAL should allow me to reconfigure them at task startup.
Sadly, I could not find a way to control any GPIO pin apart from the LED.
I changed the board file, commands, init blocks and tasks.
Only thing that had effect were the blink task and using
palSetPadMode(GPIOB, 1, PAL_MODE_INPUT);
, which disabled the blinking LED.
I should test the Tiva port to see if it's something I don't see with ChibiOS or the Maple bootloader.
Results
Thread seems to have been created and pieces gathered. A little documentation got thrown together in these notes.
Eclipse is still somewhat annoying. I wouldn't be too happy to recommend it as a simple setup and I really wouldn't recommend it over separate tools and commandline. ChibiOS looks pretty nice so far. I'm more accustomed to FreeRTOS and things aren't often where I expect. So far, useful use (IO) is completely out of reach.
Edit: Actually, using STM32Duino, I can blink a LED on pin 17 by toggling PB5. So, it should not be the Maple or the bootloader, but ChibiOS or my attempt at using it.
Edit2: I pulled a fresh copy on a Debian machine. It seems the current HEAD for 3.0 fails to build, but two steps back builds as usual. I only modified the blinker thread to set pad mode and blink PB5 and it works. So, it looks like I've screwed up something or I need a newer upstream.
Edit3: Also, pulling my own repo and adding blink lines works, so it should not be upstream but something lurking in the Windows environment and code.
Edit4: See the next post, Blog: Chibios vs Maple JTAG, for solution.
Links
- Blog: Chibios second steps
- Blog: ChibiOS in Windows Eclipse.
- Blog: ChibiOS 3.0.2 on Windows 8.1 host
- Blog: Chibios Windows redux
- ST AN235 on stepper motors (pdf)
- ST AN2820 on stepper motors with STM32F103 timers (pdf)
- L9110S on eBay
- Lock antiphase drive explained
- Sign-magnitude drive explained
- H-bridge basics explained
- Stepper sequences
- ChibiOS
- Old stepper test video