build your very own Lebowski controller !

Lebowski

10 MW
Joined
Jun 27, 2011
Messages
3,412
Location
beautiful Zurich, Switzerland
This thread in essence describes how to build a Lebowski style controller. A Lebowski style controller is a sine wave controller
with Field Oriented Control, which is a fance way of saying it runs very quietly and efficiently (as the timing of the signals
is near perfect). The controller has two analog throttle inputs that can independently be used for throttle and variable regen.
The controller works by controlling the torque of the motor which gives very smooth performance on the street.

Except for the actual controller IC (the brain as it where), the rest of the controller is open source. You can contact me about getting
a brain, or you can program your own if you feel you want to give it a go. I have two versions, one that runs with hall sensors or sensorless
in case of a direct drive hubmotor, and one that can provide torque from standstill without using hall sensors (it very fancily replaces the
hall with a mechanism where the controller puts a high frequency tone to the motor and measures the position dependent motor
inductances).

teaser picture of the finished controller (6 FET version, PCB is good for upto 24 FETs):
DSC01471.jpg
 
I thought about making PCB's available for sale but the shipping costs make that it is easier that you order the PCB from
your local PCB shop.

The PCB uses a PIC 12F617 for the dual power supply, this is the MPLABX database with the program and the .hex file
for easy programming. If you don't have a programmer, you can ask me about getting a programmed 12F617.

View attachment dcdc_converter.X _6_mar_2014.zip
View attachment 8
Or use the hex file straight away:
View attachment dcdc_36_to_80_V.X.production.hex.zip
View attachment dcdc_60_to_150_V_.X.production.hex.zip

Starting from v2.30 hall support is available on verion 2. The PCB has changed slightly as 2 of the hall connection pins
have moved:
View attachment 30F_pcb_v2p30.zip

The manual for v2.10 of the controller IC:
View attachment 7

for v2.21:
View attachment user_manual_v2p21.pdf

for v2.30, now with hall sensor mode and making v1.xx obsolete:
View attachment user_manual_v2p30.pdf

v2.40 adds temperature sensor support, upto 8 independent sensors:
View attachment user_manual_v2p40.pdf
View attachment 2
 
You need KiCad to look and the PCB to see which component goes where. KiCad is available for free on the internet
for Windows and Linux (Mac too maybe ?), I myself use the one that comes with Ubuntu 12.04 LTS , but the later
versions etc should all work the same.

this is the PCB I had made (for the Europeans: I used http://vrint-pcb.com/ ):
DSC01419.jpg

When you open the database to have a look at the board it looks kinda messy and crowded:
sc1.jpg
on the right hand sight yo can see the layers that are selected, start by switching a bunch of them off until
you're left with the silkscreen and a bunch of text:
sc2.jpg
on the right in the visibles window you can now switch off both 'values' and 'references' to end up with a very clear picture:
sc3.jpg
now if you turn on 'references' you can see the component references (like R56, C47 etc) which makes it possible
to see where the components are in the schematic
sc5.jpg
and when you select 'values' you have a good guide for soldering in all your parts
sc4.jpg

talking about parts, I ordered all my parts from Digikey. To get a list with Digikey ordering references,
open the schematic and select 'generate bill of materials' at the top
sc6.jpg
make sure you select 'all existing user fields'
sc7.jpg
KiCad will now generate a .csv file which can be opened with a spreadsheet program:
sc8.jpg
The column under 'D' shows the part numbers as I ordered them from Digikey. In the picture above many parts don't
have a Digikey number yet, but by the time I upload the database most of them should be there (I'm not going to include
resistors though, that's a ton of work !)
 
Start by soldering all the components for the power supply. This so that its output voltages can be measured and adjusted, before soldering the rest of the components.
The power_supply schematic in KiCad will show you which components are part of the power supply.
DSC01420.jpg
The power supply contains one heavy component, the 1.5 mH inductor. Because of all the bouncing around when the controller is used on a vehicle the big inductor
should be fixed to the PCB. I used a plastic 3mm screw, I imagine epoxy glue would also work.

The power supply contains three resistors of which you will have to determine the value yourself. The first one determines the current through the zener diodes. The resistor
value can be calculated using the minimum battery voltage, which in my case is 80V (I intend to run between 20s and 30s, so 80 to 120V).
In the board view the component value is not given, instead it's marked R_zen
sc12.jpg
The equation is given in the power_supply schematic
sc13.jpg

For 80V for instance the value works out to 42600 Ohm, which I rounded to 39k.

Two other resistors have to do with adjusting the 5V and 15V to the correct values.
sc10.jpg
Because all resistors are created different and also the internal reference voltage of the 12F617 varies from chip to chip, some adjustment mechanism is necessary to accurately
obtain the correct voltages. The schematic is designed such that when you leave out R_5V and R_15V, both voltages will be a little bit too low. So, after soldering the complete
power supply the way to go about things is to attach your battery (don't forget a FUSE !!!) and measure the 5V and 15V on the board. The measured values will be too low. To increase
them to the correct value the equations as given in the schematic should be used.
View attachment 3
The obtained resistor values should be rounded up. In my case both worked out to be 10k Ohm. Note that the '5V' power supply should actually be a little bit higher for reliable
operation (memory writing when in the setup menus), with the give equaltion it should end up at 5.1V

To measure the 5V the hall connector pins can be used
DSC01425.jpg

For 15V, measure on the jumper (the jumper is there to interrupt the power supply to the gate drivers, this is necessary when you want to flash a new program to the 30F4011)
DSC01424.jpg
 
Next up are the gate drivers for the output stage. The PCB was designed to be flexible and can drive 6, 12, 18 or 24 FETs.
To make sure the FETs are driven properly for a 6 or 12 FET one gate driver IC is used per channel A, B and C, for a 18 or 24 FET
2 gate driver IC's per channel are used.
toplevel.jpg
Going from left to right through the top level schematic, first there is the power supply, then the processor block containing the
controller IC and then to the right you can see how each output of the processor block is connected to two output stage driver
blocks (each output stage driver block contains one gate driver IC).
sc1.jpg
The picture above shows the content of an output stage driver block. On the bottom is the gate driver IC with its bootstrapped power
supply. The high and low side outputs of the gate driver IC have two sets of diodes / resistor combos, each combo to be used with
one FET.
For a 6 FET you only need to place the components for one gate driver block and one diode/resistor combo each for the high and low
side FETs. For a 12 FET, one gate driver block per channel and two diode/resistor combos. For 18 FETs, two gate driver blocks per
channel, one using both diode/resistor combos and one only a single diode/resistor combo. And finally for 24 FETs, place everything.

on the board it looks like this:
DSC01434.jpg
DSC01435.jpg
DSC01436.jpg

Since I'm building a 6 FET, my driver stages look like this:
View attachment 3

For the RS232 connection I only need 3 wires, but to prevent wrong myself from plugging it in wrong I use a 4 pin connector with one pin
removed on the male side and one hole blocked on the female side. The (female) RS232 plug can go straigt into your computer or RS232 <-> USB cable.
DSC01441.jpg
DSC01440.jpg

Now the board can be populated until complete. Follow the text in the schematic for whether you have a 1.xx or 2.xx controller IC.
(the board below is for a 2.xx , the hall sensor resistors are not populated but the battery voltage measurement components are)
DSC01443.jpg
 
The output stage will be build according to the principles outlined in this thread:
http://endless-sphere.com/forums/viewtopic.php?f=30&t=55641

To mount the FETs choose some sort of platform attachable to a heatsink. I use a 4mm thick L-piece of aluminium which I can later
(with the short leg of the L) mount to the wall of my controller box, with the heatsink on the outside of the box.
DSC01444.jpg
DSC01445.jpg
The L-piece has 6 small holes where the FETs will be screwed down and 3 big holes though which the 3 motor phases exit.
The FETs need to be isolated from the aluminium to prevent shorts (as the tabs are also connected to the drain of the FETs)
DSC01446.jpg
Take 2 FETs (I use 4115's for this design, part nr. same as the 4115 in the PCB's power supply) for each motor phase. Cut the
gate tab short, for one FET bend the drain up, for the other the source. Attach opposite of each other as shown in the picture below.
(Note: the mica isolation plates will be added later, I did not want to risk damaging them during soldering)
DSC01449.jpg
Place the FETs for all three phases, solder the legs together that meet in the middle over the hole for the phase wire. Make sure the
legs that are sticking up are exactly opposite each other (this is the reason the 2 times 3 holes for attaching the FETs are not alligned
exactly opposite each other, but have an offset such that the legs sticking up are exactly opposite)
DSC01451.jpg
Attach the phase wires
DSC01452.jpg
take a copper sheet and some scissorts and cut two rectangles (I used 6 cm x 2 cm x 0.6 mm), these will be the power supply 'wires' from the
battery. Solder the copper pieces on each side to the legs sticking up. Add a 470nF and a 220uF capacitor as shown in the picture, keep connections
as short as possible !
DSC01453.jpg
view from the top
DSC01456.jpg
to connect the output stage to the PCB wires should be attached to each FETs gate and source. It is very important that the wires are
tightly twisted as shown in the picture ! (else you'll have too much inductance in the gate path and will get ringing)
DSC01458.jpg
DSC01459.jpg
while you're at it, solder the phase wires from the FETs to the 'FETs' side of the current sensors. Later on, make 100% sure the gate drives and current
sensors are matched up, the FETs driven by gate drivers 'A' must have their phase wire soldered to current sensor 'A' !!!!
DSC01460.jpg
 
The gate drive connections on the PCB are marked 'hi' and 'lo' for high and low side respectively.
DSC01462.jpg
The connection marked 's' is the source connection for the FET, the other one the gate.

In the following two pictures you can trace all the FET connections to the PCB
DSC01465.jpg
DSC01466.jpg

time to finish up ! Solder the output wires to the motor to the current sensors (on the 'motor' side), and solder the PCB power supply
to where the battery wires are connected to the copper plates of the output stage
DSC01467.jpg

don't forget to put the mica isolation plates between the FETs and the heatsink. Put some (oven or baking) paper between the two copper
plates. Measure with an ohm-meter to make sure there are no dead shorts anywhere (about 1000 Ohm between the supply plates is normal).
DSC01468.jpg

some good practise tips: add a cable pull relief
DSC01469.jpg

I decided to make holes for the two power supply LEDs, I used plenty of hot glue to make it (kinda) water proof:
DSC01470.jpg

Done ! All ready for connecting the throttle and setting up the controller IC :D
DSC01471.jpg

I always use cable operated throttles:
DSC01492.jpg

Notice the ducktape on the output stage. This tape serves two (ok, actually three) purposes: it keeps the oven paper in place that prevents the two copper
plates from creating a short. Secondly, it keeps the two copper plates close together ensuring minimal inductance. And thridly, everything is just better
with ducktape :mrgreen:
DSC01491.jpg
 
The following images are screenshots of the terminal program I use for setting up the chip. These are for version 2.00, just to show that setup is easy.
The program I use is gtkterm under Linux, for Windows you can use Termite

This is the main menu from v2.00
View attachment 10

best is to always go through the menu's in alphabetical order. When you change something in menu a it's recommended you look
through all subsequent menus to make sure nothing changed, as some parameters share a dependency.

sc2.jpg
With the PCB as it is the PWM setup is shown as above, 21 kHz freuquency and 400ns deadtime. This menu also shows an
autocomplete function under option g: whenever a menu has an autocomplete it will fill in all the options after the autocomplete
option, so here the chip enters option h by itself. Typically the autocomplete uses information from previous options (here for
instance option h is calculates as two times the PWM frequency minus 1) and information from previous sub-menus.

sc3.jpg
I'm going through the submenu's in order, so above shows the current settings menu. The current sensor transimpedance can be
found in the datasheet of the sensor, for the ACS768 series it typically is 2000/I_max mV/A . Above is for 50A sensors. After entering
the maximum motor phase and battery currents, the chip can autocomplete the rest. Autocompleted options, by the way, can be
overrided by selecting them and typing a new value.

View attachment 7
the throttle menu is the same as for v1...

sc5.jpg
At the moment the battery voltage is only used later on to calculate the measured inductance/resistance. I can imagine that in future versions
here you can set the low voltage cutoff

View attachment 5
This menu is for the calibration of the current sensors in combination with the motor. Option a resets b and c, and autocompletes d. When you
select option b the motor will make a horrible noise for about a second. Option c, it will make a horrible noise and rotate the motor, so watch out
and make sure the motor can rotate freely. If for some reason it jerks too much (cogging), increase the position force current in the current settings menu).

With option c, after it's run the chip will display the measured gains. The total should be about 300%. Sometimes the measurement goes wrong and
all three sensors will display about 189%. In this case, you MUST select option a to reset all the settings and try again.

Option c measures not only the gain of the current sensors but also small differences in the motor windings. For instance, if one winding for whatever
reasons has a different resistance this will show up as a different gain. Therefore, do not change the wiring around after running this calibration as
the values will then no longer be valid. In such a case, you must re-run.

sc7.jpg
These are the controll loop parameters. The whole menu autocompletes. If the controller during use refuses to go into drive 3, typically options
b,c and d must be all increased with a (common) factor (I use 1.5). Don't go overboard though as higher numbers here increase the amount of
noise in the system.

sc8.jpg
This menu autocompletes.

sc9.jpg
This menu autocompletes for options b and c. You need to select option d, after which the motor will make a horrible noise. After this the chip will
display the measured motor resistance and inductance. For the values to be correct the battery voltage entered earlier must be correct.

View attachment 1
These options are the same as for v1, menu autocompletes.

sc11.jpg
this is the save menu. Option a saves everything to ROM so that the chip can read all the settings before starting to run the motor. Option b gives you a hex dump which
you can copy/paste into a text file for later use. Many terminal programs have the option to transmit a text file over RS232. This can be used in combination with option c
to read in previously saved settings in one go. Remember though, the settings include throttle and current sensor calibration, so if the throttle or current sensors are different
(maybe because you have a different controller) these settings are not correct.
AFTER READING IN THE SETTINGS FROM A TEXT FILE, OPTION A MUST STILL BE USED TO WRITE THE SETTINGS TO ROM !!!
Option d finally allows the on-line current sensor calibration to be stored. If you short the setup pins in motor mode all LEDs will flash and the
new calibration data will be written to ROM. This will also disable this option, so online data can only be written once. The online calibration data
is only gathered in drive 2, so keep the motor there for a few revolutions before writing to ROM with the setup pins. The current sensor gain data
will be overwritten, so if you want to see the new measured data you can go into that menu

Finally, the 4 drive modes are:
drive 0: waiting for the motor to stop spinning before the controller can take controll of the motor.
drive 1: the motor will be forced into a certain position and the HF tone will start. The motor must be able to turn freely (don't sit on the bike yet !) but will only move for a very small amount.
drive 2: the motor is run with the HF tone
drive 3: the motor is running sensorless without HF tone.

oops, seems I've forgotten one menu, will add this later (the erpms menu)
 
I'm so excited! I never built the first one you were kind enough to send me, but Im currently craving a good sensorless! (Just over frocking around with encoders/sensors).

This is so awesome! There is no better PMAC controller brain in the world that I've ever seen. Not just the best, a head and shoulders ahead of the next best.
 
thanks for making this available open source!

once we all get our cassette motors we can tune it to work perfectly with signal injection for sensorless startup

is the pilot tone adjustable?
 
flathill said:
thanks for making this available open source!

once we all get our cassette motors we can tune it to work perfectly with signal injection for sensorless startup

is the pilot tone adjustable?
The tone is adjustable in amplitude. Its frequency has a fixed relation to the (adjustable) sampling rate...
 
This is only the brain, skull and spine, right? No arms or legs?

:roll:

I mean, this is controller IC, gate drivers and no output stage, right? :lol:

Edit: Oh, and an indication of the total cost of components would be nice, just something in the ballpark.
 
Futterama said:
This is only the brain, skull and spine, right? No arms or legs?

:roll:

I mean, this is controller IC, gate drivers and no output stage, right? :lol:

Edit: Oh, and an indication of the total cost of components would be nice, just something in the ballpark.

The PCB holds the controller IC, gate drivers, current sensors and low voltage power supply (to make the 15V and 5V the gate drivers
and controller IC needs out of the battery voltage). The only thing not on the PCB is the output stage, which should be
build according to the low impedance output stage thread (which is an output stage not really suitable for a PCB):

http://endless-sphere.com/forums/viewtopic.php?f=30&t=55641
 
Can I send you one of my double motors with 6 phases, so you can see if 2 of your brains can run with adjacent windings? If there's no interference, then it makes high powered sensorless a real possibility. Motor control is still holding me back in a big way.
 
John in CR said:
Can I send you one of my double motors with 6 phases, so you can see if 2 of your brains can run with adjacent windings? If there's no interference, then it makes high powered sensorless a real possibility. Motor control is still holding me back in a big way.

I think in your case (with the 6 phase motor) a master slave setup is best. I had a think about it and it should be possible to have a
master controlling 3 phases, and a slave powering the other 3 phases. The slave can be set to run at a programmable phase difference
(which in your case would need to be 30 degrees). It would need data communication at about 640 kbit/sec (16 bit at 40kHz f_sample)
which should be possible with the SPI interface. Problem is I still don't know whether this would influence the sensorless operation, but
I have the feeling it should be OK. Second thing (big problem !) is that there would be no error detection on the slave controller, meaning
that it wouldn't notice a blown FET (normally it sees this). And lastly, it would be such a large amount of work, take so much time....

Sending me a motor would be of no use as it would need to be tested under load (so you need vehicle and batteries too) ...
 
This is a good idea dude. Thanks for making/posting this. The forum needs this.
 
Hi Lebowski :)
What reasons will you give me if I ask you why to use your controller and not an infinion based one that can be bought on Ebay for cheap?
I would like to have a controller to use any kind of brushless motor on :)
But after reading for the past month on the forum it feels impossible to make an decision on what controller to have.
Can I buy a Kit from you? And assemble my self? And then build probably 9fet 4110 power stage?

Regards :)
 
added the KiCad file to the second post, contains schematics and PCB design. Also, the subdirectory 'gerbers' contains all the files you
need to send to your local PCB shop to have the PCB made.

Also added the first part of the output stage construction.
 
Back
Top