E-Bike system – Part 2 – CAN Interface

The first part of the E-bike system will be a computer interface to connect to all the nodes using the CAN-bus. This will be used for diagnostics, parametrization and software flashing. This makes it the logical starting point before developing the other parts of the system.

There are several commercial tools for this. Of course I could have used one of them, but it’s more fun, and cheaper to build my own. The tool I’m used to, is CANalyzer from Vector which is extremely competent but also extremely expensive. CANalyzer woll be a big inspiration for the windows application I build to communicate with the hardware interface.

Windows application

The windows application will have some basic features for setting up a signal database and debug generic messages, but also some specific features for communication with the different parts of the E-bike system. The application is created in C# .NET using Microsofts free Community edition of Visual Studio

Hardware Interface

The hardware will be built around the STM32F042C6 processor which have built in crystal-less USB and a CAN-interface which makes for a very low part-count device. Apart from some LEDs and passives, its only a processor, can transceiver and voltage regulator. For low volume production the BoM cost of the v0.1 prototype is around $10.

I’ve already designed and built the first prototype hardware and ordered the boards from OSH Park.

USB2CAN PCB v0.1 top
Top view of the USB2CAN board prototype v0.1
USB2CAN PCB v0.1 bottom
Bottom view of the USB2CAN board prototype v0.1

Firmware

The embedded firmware is built on top of the ChibiOS RTOS using ChibiStudio which is a great tool for getting started with ARM Cortex-M development. Functions for communicating with the USB and CAN hardware and task synchronization is already done in the RTOS with the corersponding HAL.

The first version of the firmware works fine for sending and receiving CAN messages. There is still some work on the bootloader and the windows application. But I’m far enough to move on to the next part of the e-bike system, the BMS.

E-Bike system – Part 1 – Introduction

I’m currently working on replacing the complete electric system on my E-bike. The new system will be completely DIY and consist of several parts connected by a CAN-bus. I will post about the progress here continuously.

The system will be divided into several parts, all of them controlled by a STM32-series ARM Cortex-M processor running ChibiOS RTOS. The image below shows a system overview.

Overview of E-Bike system
Overview of E-Bike system

Handlebar Control Unit [HCU]

The main node controlling the rest of the bike will be mounted on the handlebars. Later on I’m thinking about something with a ~4.3″ TFT screen. To begin with it’ll probably be something much simpler. The main tasks would be to sample the acceleration and braking request and forward to the motor controller. It will also controll and display status from the BMS

Motor controller [DCAC]

I will probably start with a VESC with a redesigned PCB more suitable for e-bike use with heftier power transistors. Perhaps I’ll develop my own software to this later on since I find motor control software very interesting.

Battery Management System [BMS]

The battery will be built of 12 cells long series of 18650 cells. To monitor, balance and protect these I will build a BMS around the Maxim MAX14920 chip. This is an analog front end for voltage level conversion and balance discharge of 12 cell batteries. A STM32F373 processor will handle the sampling, control SoC estimation and communication with the rest of the system. The BMS will be able to continue running after the rest of the bike is shut down to handle charging and balancing after a ride.

Voltage Stepdeown [DCDC]

To generate 12 V from the main battery for driving the other nodes and things like lights. To begin with this will probably be designed around an off-the-shelf switching regulator controlled with a hard wire from the BMS which should have its own power supply.

CAN interface [CAN2USB]

This will be the first part I develop, the first prototype is already built up and somewhat tested. I will write a longer post about this later on. The CAN interface will be used to be able to download software, parameters and to read diagnostics using a computer. There are comersialy available alternatives but how fun is that. I manage to get the BoM down to the $10-$15 range as well. The can interface is based on a STM32F042 processor with built-in crystal-less USB and a CAN transceiver chip. This will talk with a Windows application over a virtual com port. The Windows application is written in C# using the community edition of Visual Studio.

Charger

A “dumb” standard Lithium battery charger like the one I have for my previous E-bike could be used as a start, but it would be nice if the charger was connected to the CAN-bus and let the BMS handle the charge and current control.

Mechanics

The mechanics will be the same ase described in for example [these] posts. The difference is that the bike will be touched up quite a lot with both paint and parts.

Dual pulse battery spot welder

I recently bought 20 Sanyo NCR18650GA Lithium batteries. 12 of them will be used for developing a BMS for a upcoming E-bike project. From the other cells I will put together 2 battery packs for my bicycle lights, 4 cells each in 2s2p configuration.

This type of cells are usually spot welded together using thin nickel strips. I’ve read that many have been successful soldering the cells together but how fun is that when you can build a DIY battery spot welder.

Most designs that I have found is based on a SSR (Solid State Relay) controlled MOT (Microwave Oven Transformer) with the secondary replaced by few turns of heavy wire which converts mains voltage to high welding current. This doesn’t seem like a good solution since the current comes in 100 Hz pulses which makes welding energy control very difficult. I know some SSR can only break the current at the zero-crossing-point of the mains voltage resulting in a pulse time resolution of 10 ms. I don’t think this is good enough to get a consistent result.

There are also variants which discharge a large capacitor bank through a MOSFET which seems like it would give a much higher degree of control. I also found a similar design using a car starter battery instead of capacitors which seemed even more interesting.

I don’t have any spare car batteries, instead I’ll use some high power LiPo batteries. I have a pack of 4 Turnigy 6S 20C 5Ah batteris that I could connect in parallell. This will result in a 6s4p 20C 20Ah pack capable of delivering  ~20 V 400 A continuous. It will not have any problem delivering enough current for battery tab welding in short ~10 ms pulses.

The main focus of the build was to use as much parts from my junk-bin as possible.

Electrodes

The electrodes are built om 10 mm copper rods sharpened in one end and threaded with an M10 thread in the other. On the threaded end a 25 mm² welding cable are connected. To set off the welding pulse I have placed a small button on the top of one electrode.

Electrode
Left hand electrode, a sharpened 10 mm copper rod
Trigger
Right hand electrode with trigger placed for thumb activation

Electronics

To switch the current I found six FDP8440 MOSFETs rated at 40 V with a very low RDSon of 2.2 mΩ. If the welding current reach 1200 A they will handle 200 A each resulting in ~90W losses. This will easily be handled for a few hundredths of a second every 10 s or so. Especially since they are mounted on a thick copper busbar.

The control circuit semi-temporarily built on a Veroboard
The control circuit semi-temporarily built on a Veroboard

The mosfets will be controlled by a Microchip TC4421 from a 8-bit PIC microcontroller. Haven’t used a 8-bit PIC in ages, nowdays i prefer ARM Cortex-M processors, mainly the STM32 and LPC series. Since I’m building this on a veroboard I needed a DIP-casing so I decided to use an ancient PIC16F648A from the junkbin. This processor was perfect for a quick job like this, extremely simple keeping the datasheet reeding to a minimum

Spot welder schematic
Spot welder schematic

It has an internal 4 MHz 1% oscillator which will work fine for this application since there are no asynchronous communication, and 1% precision of the pulse timing is more than enough, no need for an external crystal oscillator. The reset-pin can be turned off with the config bits and all I/O-pins on Port B have internal pull-ups saving me a few resistors.

To program the processor I used Microchip MPLAB X IDE, XC8 compiler, and a PICkit 2 programmer. I’ve never used MPLAB X before, but it worked rather well. This is the application firmware, perhaps a little bit overdone, but why not?

The pulse length is currently hard coded in the application, it’s easy enough to update. If needed i will later add a switch with a few presets. The microcontroller has no A/D-converter, otherwise a potentiometer for setting this would have been nice.

A 6 S LiPo used as a power source discharging in a 3,3 ohm power resistor.
A 6 S LiPo used as a power source discharging in a 3,3 ohm power resistor.

There is a lot to read about pulse welding online, essentially the first pulse is to break any oxide layers and the second performs most of the welding. I have set pulse 2 to 10 ms, and pulse 1 to 1,25 ms which works fine for 8 x 0,18 mm Nickel strips.

I haven’t received the nickel strips I ordered yet, so my first test subject was some pieces of box cutter blades. It worked perfectly, but perhaps I need to shorten the pulses a little with the much thinner nickel strips.

Top side of welded knife blades
Top side of welded knife blades
Bottom side of welded knife blades
Bottom side of welded knife blades

Future plans

I will use this to build a few batteries, if the design works well, I’ll probably make a new PCB with a display, rotary encoder and a more modern processor.

Hacking Viasat branded version of Netgear WN602 v2 wireless bridge

Viasat WN602 v2
Viasat WN602 v2

The Viaplay package of my satellite receiver contained two Netgear WN602 v2 wireless network bridges to connect the satellite box to my network. These are a Viasat branded version with custom software for easy setup. To get the wireless bridge working I just had to connect the network cables, power them up and press the WPS setup button.

My house will soon get a fiber internet connection, to prepare for that I’m installing a wired network instead in the house and these boxes became superfluous. Instead I was thinking of using these as access points to extend my wireless network. This should be possible with the original Netgear firmware, but the Viasat firmware did not expose any interface for changing settings or update firmware.

Opening up the device i found a pin header with 4 pins, and i know these units often expose a TTL-serial port. Pin #1 is marked with a white dot and I could measure 3.3 V between pin 1 & 4, and made the assumption that pin 2 & 3 was the Rx & Tx pins. Using an FTDI-based serial adapter with 3,3V TTL levels I detected by trial and error that I could get a console bye connecting the adapter Rx to pin 2 (Tx) and the adapter Tx to pin 3 (Rx). The communication settings should be 115200 baud, 8 databits, no parity and one stop bit, otherwise you would just receive garbage.

Serial port on PCB
The serial port is accessible on the PCB. Pinout is:
1. 3.3 V
2. Tx
3. Rx
4. GND

The console access was not very helpful since i needed the root password to perform anything useful, this password was most likely kept secret by Viasat. Directly after power up the bootloader, U-Boot, instead called the router WRN612, which seemed very similar. Some googling verified that the WN602 essentially is a WNR612 with the WAN port removed. U-Boot also prompted for a key-press together with a down counter to abort the normal boot and enter a command prompt for the bootloader:

U-Boot
U-Boot

Luckily U-Boot is rather well documented, from here, loading a new firmware should be easy.

My first choice would have been to install dd-wrt instead which is an open source firmware for routers. Sadly dd-wrt had no support for neither WN602 nor WNR612, the D-Link DIR-601 A1 would perhaps work since it is based on the exact same chips, and these units are usually very similar to the chipset manufacturer reference design. The main processor in these are an Atheros AR7240 and the wireles network chip is an Atheros  AR9285. I decided to try OpenWRT instead, which is a similar project that had an excellent wiki entry for WNR612 on which most of this guide is based.

To flash the router with Open WRT I did like this:

  1. Connect a serial console to the hardware serial port described above. I used a FTDI based USB to Serial adapter from Sparkfun together with PuTTY as a terminal application. Be sure not to connect the 3,3 V pin, GND, Rx and Tx is enough. Connecting the power pin could damage the router, serial adapter and/or your USB-port
  2. Power up the router and be ready to press the “any key” when the bootloader asks for it.
  3. When the boot have been interrupted and you are in the boootloader console enter:

    to disable flash write protection, and then:

    to activate a TFTP server waiting for firmware upload
  4. Enter a static IP address from the 192.168.1.0/24 series on your computer and connect it to one of the network ports on the device.
  5. Use a TFTP client on your computer to upload the firmware to address 192.168.1.1, i used TFTP Utility to upload the file named openwrt-ar71xx-generic-wnr612v2-squashfs-factory.img from the openwrt firmware repository.

    TFTP Util
    TFTP Util

DONE!

Firmware flashed successfully
Firmware flashed successfully

Now I can use both wireless bridge devices as wireless access points instead of putting them on a shelf somewhere and forget about them.

Upgrading Turnigy 9x with er9x firmware

A couple of weeks ago I ordered a Turnigy 9x RC radio transmitter. This is a cheap but capable transmitter sold by HobbyKing. I’m very impressed by the quality of the hardware and the thing have more buttons, switches and channels than I’ll ever use, but I’m not really satisfied with the firmware.

Luckily there are a lot of custom firmwares for this radio and from what I’ve read, the one named er9x is currently the preferred one. Guides on how this update is done can be found on many places (for example here), this is how I did it:

I used a USBasp AVR programmer, these can be bought off eBay for a couple of dollars. Since i generally prefer PIC processors, this was nothing I had so I ordered one. But I guess you could use any programmer supported by AVRDUDE.

When you have your programmer, there is a software called eepe that is a specially made AVRDUDE frontend for programming er9x firmware. I downloaded and installed that program.

Then you need to connect your programmer to the processor, this is the hardest part, but not really that hard. First unscrew the six screws on the back of the radio. Then disconnect the cable hold the two halves of the radio together.

Disconnect
Disconnect this cable

after that you need to locate the connection points where the programmer should be connected. These are all around the processor in the lower part of the radio. NOTE: I have the v2 version of this radio, the connection points differ on the older v1 of this radio!

Connection points
These are the six connection points that needs to be connected to the programmer. Note that I have the v2 version of this radio, these could differ on older versions.

To connect the USBasp programmer I made a custom cable like this

Programming cable
The programming cable made from a 10 pole flat cable and a 2×5 connector.
AVR connector
These are the different signals in the 2×5 AVR programming connector, with the connector in the same orientation as on the image above.

Note that the leads 3, 6, 8 & 10 are cut off and not used.

I soldered the cable to the connection points and followed the instructions for eepe. When I was done, I left the soldered cable inside the radio if I want to flash it again someday.

 

Updates on the RepRap build

Last week I received 5 NEMA 17 stepper motors for my Prusa Mendel RepRap. They are pretty small and I’m a bit worried that they will be to weak for some parts of the printer (mainly the extruder) but I have to wait and see.

I also ordered a complete RAMPS kit and 1 kg of plastic filament from 3D Gadgets. The shipment from china with FedEx was super fast but since I work office-hours it seems impossible for FedEx to deliver it to me.

I hope I’ll find a solution to get my package and will post some pictures on both RAMPS and the steppers when it arrives.

I also discovered that I could run the whole RepRap on 24 V using RAMPS or that I could divide it so the steppers and extruder run on 12 V using the 5 A fuse on the board and the heatbed running on 24 V using the 11 A fuse allowing me to push 264 W of power into the heatbed. Should be enough.

To buy before first print:

  • Extruder
  • Power supply
  • Endstops
  • Piece of glass to use as print surface.

Prusa Mendel printbed

I put together a heated printbed for my Reprap using three parallel 10 Ω 100 W power resistors. The resistors are screwed onto a 220 mm x 200 mm x 5 mm aluminum sheet. This will make the whole printbed a 3.3 Ω 300 W heating element.

Printbed power resistors
Three 100 W power resistors connected in parallel will act as a heating element.

On top of the sheet I will place a 220 mm x 220 mm sheet of glass to use as a print surface.

Top of printbed plate
Top of printbed plate

When printing the printbed should be between 60° C and 110° C depending on which plastic is used.

Since the main voltage used on the reprap is 12 V, maximum power that can be achieved is

[latex]
\frac{U^2}{R} = \frac{12^2}{3.3} = 44 W
[/latex]

My guess is that it will take at least two eternities before it gets hot enough, but for a start I’ll use the printbed temperature logic built into the RAMPS controller card.

Later on I think I’ll build my own temperature controller with either a step-up or a separate power source with a higher voltage to get more power out of the printbed.

Propeller driven Lego car.

Lego Technic is perfect for creating quick prototypes of pretty much anything, combine this with RC stuff and you can create really fun stuff. One simple example is the robot i describe in this post:
Sunday afternoon robot

My old Lego is usually stuffed away in a box in the basement, but when we have kids visiting we usually bring it up to the apartment. I suspect I’m the one enjoying it most and this time I built a RC lego car

Lego Propcar 1
From the side
Lego Propcar 2
The motor and propeller us used as a pusher
Lego Propcar 3
The battery, ESC and receiver is secured with a rubber band
Lego Propcar 4
I use a HXT900 servo to steer

After a few testruns I added a propeller protection bar to minimize the risk of running into something with the propeller.

Lego Propcar 5
Propeller protection

Runs great, I’ll probably update this post with a video when I’ve recorded one.

Have somebody seen my magic smoke?

A little while since the last post, this is maybe old information if you have read my posts on Endless Sphere or the Swedish Electronics Forum. We played around for the whole weekend with the moped until the motor got enough. My guess is that several hard accelerations during a short period of time heated the stator enough for the insulation to melt.

The black insides of a BLDC motor
The black insides of a BLDC motor

Not pretty! I’m afraid I’ll have to torment my hands with another rewind. A member on SEF is good enough to donate a large roll of 1,5 x 2,5 mm flat copper wire to me which I will use for the rewind. I have three different actions to prevent this from happening again.

  • Increase the gear ratio. Less torque on the motor means less current.
  • Increase kv, one less turn of copper wire will increase kv to match the higher gear ration and reduce the resistance. It will also leave more room for air to flow through the motor
  • Forced cooling, I’ll put a fan in one end of the motor to force more air through.

I’ve also ordered a spare motor from china. The 80-100 is very hard to get nowdays, but I found a 80-85 motor with the same mounting profile and axle. But i’ll keep a close watch on the stock of the 80-100 motor.

First testrun of the E-Puch

Today I’ve made the first test-run of the E-Puch. As I’ve written about before it is an old ICE moped that I’ve removed the engine and replaced with an electric BLDC outrunner.

Today, me and my brother threw everything together for a quick testrun just to see that everything works, and try out the performance.

E-Puch ready for testrun
E-Puch ready for testrun

I will soon write a post about the motor controller which I ordered from a guy named Lyen on the Endless Sphere forum. It is currently set to limit battery current around 40 A, but I think I could increase the current limit by 50% without any modifications. Which would give 50% more torque.

Controller temporarily mounted to the frame
Controller temporarily mounted to the frame

The motor is mounted on two 5 mm aluminum sheets that are bolted in the original motor holes in the frame.

Motor and motor mount
Motor and motor mount, I think I'll remove the axle on this side.

Except for the motor and motor sprocket the drivetrain is original.

Original chain with 10 tooth front sprocket and 43 tooth rear sprocket
Original chain with 10 tooth front sprocket and 43 tooth rear sprocket

I use 4 bricks of 6S 5 Ah Turnigy 20C batteries mounted in 12S2P configuration. For now these are in a plastic box on the rear end of the moped.

Temporary battery box
Temporary battery box

And at last a video of my father trying the moped.