Tag Archives: USB Bootloader

Stepper Motor Controller Rev B

Looks almost like the first version

This board may look familiar to some of you. Because at first glance, it looks just like its older brother described here: Dividing Head Controller. But many things have been improved in Revision B.

Changes are only visible from the back side

It has also found new use cases. Depending on how it is programmed, it can be applied wherever a stepper motor needs to be driven from a user interface or PC. So while it was first designed specifically to drive a dividing head, it is actually quite universal.

Re-designed power supply on the left

Now what’s new? First of all, the power supply has been improved to accept input voltages in the range of 6 – 60 volts instead of 6 – 30 volts previously. For me, this was one of the main reasons for the upgrade. The stepper motor I’ve used for the dividing head lacked a bit more torque at higher RPMs when operated from 24V. This new version has allowed me to use a 48V supply which has solved all the torque problems.

A more powerful microcontroller on the left and the new flash chip on the right

The other main upgrade is a more capable microcontroller, a PIC18F47J53. Together with a 32Mbit flash chip, this allows for a USB bootloader. It enables firmware updates without any specialized hardware or software. Any PC with a USB port will do, no matter the operating system. Watch this video for a demonstration of how it woks.

Since the stepper controller behaves just like a USB drive when connected to a computer, it also allows users to customize their device by simply editing a config file that resides on that drive.

Besides the fan output, there is now also an output for a mechanical brake. But despite the labelling, these are simply open collector outputs, with flyback diodes included, capable of driving around 1 amp. So depending on the software, they can be used for any other purposes.

Three devices during programming and testing

The remaining features are unchanged: There is still a 4 x 20 characters LCD display and two nicely hardware-debounced rotary encoders. There is still a buzzer, EPROM memory, reverse-polarity protection, an on-board temperature sensor and an input for an external temperature sensor (or any other analog input signal in the 0-3.3V range).

Desktop application for the dividing head

And there still is that USB port. But with the USB bootloader and the config file, this USB port has become much more useful. And I’v also spent some time writing software so that the device can be controlled from a (Windows) PC.

A different desktop app for a different use case. But absolutely identical hardware.

And as I’ve mentioned, the board has found new use cases that use application-specific software but absolutely identical hardware. And the modular design of the software allows for the most of the software to be re-used so you don’t have to re-invent the wheel whenever you have a new application for this device. You don’t have to re-do all the heavy lifting required for USB or smooth motion control. A few changes to the user interface and the corresponding API will typically cut it.

All the hardware and software is open source, ready for you to use, improve and adapt. It’s all on GitHub so let me just share the various repos:

Hardware:
https://github.com/soldernerd/StepperMotorController

Bootloader:
https://github.com/soldernerd/StepperMotorController_Bootloader

Firmware:
https://github.com/soldernerd/StepperMotorController_Software_RevB

Desktop applications:
https://github.com/soldernerd/RotaryTableApp

USB Mass Storage Device Bootloader

Let’s start with a video. It will tell you most of what I’m going to write about today.

That Hackaday Prize final has passed and unfortunately for me, the solar charger didn’t make it into the top 5. The good news is that there are plenty of projects and stuff that I would like to share. Things that I did over the last one or two years but never had time to write about. I’m trying to catch up with all that now.

First of all, I have completed the USB bootloader for the solar charger. This part of the project will enable the non-technical end user to easily and reliably update the firmware in the field.

Unlike a USB HID (Human Interface Device) bootloader that requires some application to run on the host computer, this USB MSD (Mass Storage Device) bootloader requires absolutely nothing in terms of host software. It’s entirely independent of the OS used. Windows, Linux, Mac, it all doesn’t matter. As long as they can deal with a USB drive, they’re good to go. Just copy the new software (in the form of an .hex file) to the Solar Charger drive and follow the instructions on the display.

It might even be that this bootloader is the world’s first of its kind for the PIC18 platform. To be sure, this kind of bootloader has been around for years for more powerful 32-bit microcontrollers like ARM Cortex and the like. But in my online research I have been unable to find any other such project for the PIC18 family (or any other 8-bit microcontroller). So I had no choice than to write my own. If you know of any other implementation, please let me know.

Once the file has been found and the user has pressed the button, the file is checked. If all those checks pass, we can be confident that we have a valid hex file. Of course, it doesn’t tell us anything about the quality of that code, that’s an other issue. But technically we should be fine.

Once the checks have passed, the user is once again requested to press the push button to confirm that this file should be programmed onto the chip. While it’s programming, it keeps displaying the current hex file entry it is processing to give the user an idea of the progress. It also keeps track of the number of flash pages it has written. One page corresponds to 1024 bytes on this architecture.

Once all the new code is flashed onto the chip, a message is displayed and the user is asked to once again press a key to re-boot the device into normal operating mode.

There are two different ways to enter bootloader mode. One is to press the push button at power-up. The other one consists in writing the value 0x94 (an arbitrarily chosen value) to the EEPROM address 0x100. In this case, the device will start up in bootloader mode no matter the state of the push button. The bootloader then overwrites this value (to 0x00) in order to start up normally next time.

After the reboot, you should be greeted by the startup screen of the solar charger firmware as shown above.

While I wrote this bootloader specifically for the solar charger, the code is rather universal. It can be ported to other PIC18 projects with relatively little effort. As always, the code’s on github: https://github.com/soldernerd/PIC18_USB_Bootloader.