How to Tame Your Shady Chinese e-Bike Controller: Self-Learn Hall Sensor Calibration Mode

In my continued quest to discover new ways to EV on the cheap for builders, I’ve worked on demystifying several types of sketchy Chinese motor controllers to assess how applicable they are to little electric rideable things. My most recent favorite has been the “Jasontroller” electric bike controller. Like every other generic Chinese electromechanical product – it has no actual real name (the “Jason” moniker started as an inside joke in our EV contingency and is a bit of a satire on companies like Kelly), no well-known company with customer support to back it, nor any real details about hookup and operation.

(Scheduled plug: By the way, I still have alot of stuff for sale!)


Do you guys, like, know eachother?

Most of these generic Chinese e-bike controllers are pretty much the same functionality and firmware-wise, but what appealed to me specifically regarding that model is that it has a reasonably competent sensorless mode, complete with motor current limiting, for driving inertial loads, specifically vehicles. R/C type aircraft and car ESCs just aren’t the same in this regard; more details can be found in my Instructable on the matter. I’ve found that the sensorless mode on the Jasontroller is fine enough for scooters (and their design target, electric bikes) because you can always move just a little to avoid the zero-speed condition that sensorless is worst at. For things where you don’t get to push off, like Chibikart and DPRC, they’re somewhat hopeless. The algorithm is very simplistic and typical of ‘block’ commutation startup – just open-loop power the motor phases until a valid phase voltage waveform is detected. Usually in the case of an inertial load, the slow bobbing of the rotor is not strong enough to cause any significant motion and the startup fails. In the case of a cheap R/C type controller with no current limiting, the controller explodes from having to power a stalled motor.

While the controllers usually do have a Hall sensor connection, the hard part is adding sensors to the motor itself and connecting them correctly. In the past, I’ve accomplished this by both putting them inside the motor as well as outside on 3D printed mounts and cute sensor holder rings. Then, explaining the process of lining up the 3 sensor bits with the 6 internal states of the 3 phase motor usually takes at least half an hour and much confusion – without knowing the way the motor was wound (i.e. you didn’t wind it), there’s 12 possible ways to hook up motors and sensors and some times you have to brute force them all before finding the right one.  Additionally, sensors aren’t optimal at anything except low speed anyway because they suffer from hysteresis-induced timing lag.

Optimally, you’d have a controller that uses the Hall sensor feedback just to kick off. Even if the sensor combo was total bullshit, actively driving the motor in one direction and getting some kind of positive position change is enough to begin ramping the motor sensorlessly up to speed.

What I’ve been kind of hiding is that many of the latest generation e-bike controllers, including the Jasontroller (I have enough of an emotional connection with the thing to name it), has this exact functionality. I’ve never explored it until recently when curiosity got the best of me, and I think this is a total boon for everyone who is building small EVs. It is now my goal to explain how the mode is used and what its limits are. There appears to be some confusion on how the mode is used (example and another), and as a result I haven’t seen it frequently mentioned.

We begin with a picture of the rear of a Jasontroller, where the mysterious Chinese sticker is located.

For your entertainment, I’ve fansubbed the Jasontroller below. I’m not gonna claim perfection with my several-versions-out-of-date Chinese language drivers, but hey, who else is gonna give you an English manual?

All of the Chinese e-bike controllers you can find are probably generally wired the same way. The funny thing is, as amusing as these devices are to me and many other EV hackers, I’m willing to bet that literally millions of people use them on a day to day basis and find them nothing too ordinary. These are generic replacement controllers for electric bicycles, moped, and scooters made and used by the millions in China. To people who have one of those things, it’s like changing windshield wipers or something.

Take note of the “Self Learn” wire in the lower right. The instructions on the bottom are basically how to use the self-calibration mode of the controller.

The magic green (may be other colors on your specific variant) wire is usually embedded in the forest of wires these things come with. It’s terminated in a small snap-on connector.

Basically, the controller recognizes that this pin is connected when you first power on. It attempts to run the motor sensorlessly and captures what the Hall sensor waveform looks like, saves it to memory, and then when throttle is commanded, it will power the phases according to what state the motor is in and what it ‘saw’. You can indicate that the motor is being learned in the wrong direction (by unplugging and reconnecting the self-learn wire once) and it will reverse the direction and record the states again, saving that and associating that direction with “forward”.

Nifty. That’s so much software I can’t imagine ever doing it myself. Luckily, some smart Chinese guy has figured it out (and probably got pirated).

Here’s my Rig of Science that I set up. A 63mm outrunner with my custom Hall holder rig, externally adjustable so I can try and confuse the Jasontroller. The jumper wires that connected the sensor board to the controller was also rearrangeable. Basically, I wanted to see how much bullshit I can feed it and still have the thing work.

The process was basically to train it on a specific sensor arrangement, then swap the sensor combination around and move the board such that the timing is terribly off, and combinations thereof.

What I found was the following:

  • If sensors are present and the controller hasn’t been trained before, it will use the factory programmed motor state model.
  • The sensors must be 120 or 60 degree space electrically – if there is significant inequality in the spacing, the process incrementally gets worse and worse with spacing error until it just errors out.
  • If the sensors are incorrect (do not result in continuous motion) or throw an error for any reason, it will automatically try to switch to sensorless mode.
  • Once “trained” for a specific sensor arrangement, it will retain that and use it for any other motor it is connected to until trained otherwise, pursuant to the above rule.
  • The sensors are only used for low-speed and stall conditions. There is an audible transition to sensorless mode – the motor sounds “smoother”, lacking the hard-switched sound of the sensored mode.
  • Sensored mode does not bypass the internal hardware “speed limit” as a result – the processor is still only capable of running the motor to a relatively modest speed.

There were moments where I got the controller “stuck” in sensored mode, but I can’t consistently replicate the problem. It seems to happen only when the sensors are horrifically off-timing that, I assume, the sensorless algorithm cannot lock in, but why it doesn’t just ditch the sensors at that point is not known to me.

Additionally, another weird symptom that happened several times but I cannot replicate reliably is that if only 2 sensor wires are swapped, it catches on and figures the problem out. The first start is false and runs sensorlessly, but the next start is properly adapted to the new sensor arrangement.

The fuck? Are these things actually sentient and just messing with me instead of vice versa?

Basically, what I found is that if you line up any sensor with a slot (placed in the middle), the controller will figure it out just fine. For any sensor over a slot, there’s a valid combination that will result in motion, maybe not in the intended direction (but that is what the “reverse learn” switch is for, right?). In the above picture, the rightmost sensor is centered over a slot. I don’t have any info on how this motor wound, so which slot it is is completely not known!

If a sensor is not centered in a slot, then the startup gets rougher and rougher with increasing error until it just switches to sensorless. The transition between sensored and sensorless mode also becomes less smooth.

summary

Here’s a video where I demonstrate how to use the auto-calibration as well as illustrating what happens if a sensor is not located over one slot.

conclusion

Suddenly, the Jasontrollers have become alot more favorable to me. I’ve had a few of them die running all-sensorless into an R/C type outrunner because the current limiting circuit is just not fast enough for those motors, which are generally super-low inductance (current changes very quickly).

Not even Kelly controllers can do this sensor auto-recognition thing right now, and they are currently my go-to for when someone asks me what controller to use for their brushless setup. Calibrating sensors and adjusting timing is one of the worst “black box” magic processes that people have to do, and they matter alot in having smooth vehicle operation.

This neat little feature will save alot of time and effort in vehicle construction. All you really need now is a way to mount sensors to the motor.While I now favor external sensors for outrunners due to their ease of adjustment, the controllers having an automatic sensorless switchover after a certain speed means that embedding sensors in the middle of a slot (inside the motor, by taking it apart) is completely reasonable. This would be an option for people who do not have, or want to make, an external sensor-holding jiggie thing.

I’m probably going to try throwing Halls in DPRC‘s 50mm outrunners in order to truly test this hypothesis under load.

Of course, now I also really want to start selling these sensor holders and boards. Perhaps that will be a product line parallel to RageBridge


Seeds for your melon

In conclusion,

Why should I go to the length of adding sensors to my motor to use this feature?

Most commercial sensorless motor controllers usually fail at zero and low speed because they depend on having a voltage feedback from the motors to determine rotor position, only possible with continuous motor motion. This means you have to be moving before you can move. While this is okay for, say, scooters and bikes because it is totally reasonable to push off with a foot before hitting the throttle, the same is not true of go-karts, robots, wheelchairs, etc. which you cannot really push off without compromising the function of the vehicle. These MUST have a “zero speed” torque on demand.

What should the motor and sensor arrangement be?

The sensors should be spaced 120 or 60 electrical-degrees (both industry standards), mostly because they divide equally into 360 degrees. Incorrect spacing will probably just result in the controller bailing out to sensorless mode anyway. The way to tell is if the motor has very little startup torque or just twitches helplessly. One sensor should be aligned with 1 slot between the windings on the stator and the controller will be able to figure out the rest. This is true for a standard 12-tooth stator with fractional magnet to slot ratio, anyway – other motors are currently not determined. If the sensor is not aligned with the slot, the startup and switchover transition become rough and rougher with positioning error.

Is this really simpler than running a normal, all-sensor-commutated controller like a Kelly?

Oh hell yes. There is no more playing the keep-it-change-it-flip-it game with sensor vs. phase combinations.

So, simpler, and I believe potentially better. Hall sensors introduce significant timing lag at higher speeds, and the optimal sensor position also changes with speed and load. Having the sensors there only for startup solves the low end torque issue, while driving the motor sensorlessly at high speeds effectively means you drive the motor more according to how it wants to be driven at a given speed and current draw.

Note that your shady-ass generic Chinese e-bike controller may be different. I can only account for the controllers retailed by “bobzhangxu” on eBay at the moment. However,

That lead image. Be prepared for a massive Beyond Unboxing post in the next few days where I will attempt to catalog several different shady e-bike controllers and see which ones can perform this training routine! I literally went on eBay and bought 1 of every controller that was under $30 with free shipping or under $40 with shipping. There are 7 in total. The intention is to make an index like my copier motors spreadsheet.

Some more 3D printing shenanigans: The Up!

Scheduled plug: I’ve added a pile of new things to the Stuff for Sale page! Go check it out.

An exciting new thing came for me in the mail right after Maker Faire, and I think I’ve gotten finished playing with it enough to post.

Back in June, I wrote up the Democratic People’s Republic of Chibikart for Instructables and entered the Make It Real contest. It won one of the first prizes, which is an Up! Plus 3d printer, to add to my flock of 3D printers.

That was in July. I just got it a week ago, due to Instructable’s famed lack of shipping organization. That said, I was greeted with this in the shop last week:

Shiny. Let’s open it up!

I see the thing…

Very shiny (looks like glossy enamel) indeed. And orange, I guess because this was an Instructables-commissioned machine.

The Up is a pretty simple machine. It uses the ‘overhung arm’ architecture where the table is mounted on one moving axis and the head is mounted on another traveling, perpendicular axis. Now, I actually think this is the worst design for 3D printers because not only do you have issues stemming from workpiece acceleration (it’s moving), but the axis inertias are also mismatched.

Furthermore, the arm that sticks out is really flexible – it seems to be only mounted by one flap of sheet metal. It The X movement of the extruder is transmitted as vibration into the arm, and the end can resonate a fair amount – at least 3 or 4 mm of wobble at the end! Luckily the printing occurs very close to the arm’s support, so it seems to retain resolution accuracy. But still, it makes the machine design side of me cry a little. The new Up! Mini addresses this with a dual-rail axis design.

It also has a really really loud buzzer that makes it sound like an overly enthusiastic microwave oven whenever it starts, warms up, and begins/ends a print.

It also comes with a fairly extensive toolkit. Fairly typical 3d printer diddling tools like tweezers and a paint scraper are included, as are build platforms, mounting screws, and a nozzle wrench (but no replacement nozzle). I also got a pair of fabulously pink work gloves, but I’m not sure how they’re supposed to be used (are you supposed to grab the nozzle while hot?)

After I made a klein bottle as the printer’s first test, I let it run overnight on this compound of 5 cubes.

I’ll take a moment mention the UP! software. As far as I can tell, it’s closed source. It offers the usual array of tunable features – layer thickness, speed (just fast, medium, or fine), and infill (loose, dense, solid, hollow…), but only generates a square mesh (while Replicator can generate hexagonal meshes or just line scribble). It also slices way faster than ReplicatorG, but the user interface is a little strange with its button press sequence to do a common task like scaling or rotating, but that is a minor complaint.

What is REALLY nice about it, though, is how it generates the support lattice. This is the one place where I think it beats everything for intelligence, because alot of planning has to go into making a homogenous-material (i.e. not dissolvable or something) support that just falls away when done. If you’re a Stratasys printer, you can just puke support material everywhere because the intention is for said support to be dissolved away in the bubbling cauldron of lye. This is a very different, controlled kind of puking.

That entire cocoon for my cube thing came off in one piece, with absolutely no knifing or prying. Same deal with the “raft” layer. Contrast this with the amount of scraping and filing I have to do to the average Replicator(G) print and it seemed almost magical. I’m not sure how it is able to do this -it doesn’t seem to pause for a temperature change when moving between supports and part, so I think it must just be very careful extruder control to make sure the parts just barely come into contact.

It generates several different types of support – there’s the loose lattice that is used to build up the bulk of the support, then a very fine and nearly solid layer that is the one which makes contact with the part (which makes the near trivial breakaway even more amazing). There’s also a “cross hatch” like option which is used only for the loose layers.

Either way, seriously, what? I wouldn’t mind seeing a more robust support generation scheme for Replicator. Or, even better, maybe I should try hybridizing this guy with our Replicator 1 and make an Uplicator. I’d love to combine the high speed-capable gantry head of the Replicator with the Up’s slicing engine and controls.

There’s also one more thing I like, which isn’t Up-specific but I have not seen it until now: perfboard build plate. I am a definite fan of this. On that giant 4.25″ wide print, there was less than 1mm of lift on one corner of the hexagonal base. In ABS! As far as I can tell, the little holes in the perfboard cause the molten ABS to flow into them and hence achieve a mechanical interlock, way better than counting on the strong force interaction or something with a smooth tape. The Up came with 3 pieces of 2mm-space perfboard. I’m tempted to go buy a 6 x 8 panel from Radioshack and check out how it works with our Replicator.

I did a little more research into it and found that perfboard is now a common build surface, especially in conjunction with “ABS juice” that is made of ABS bits dissolved in acetone and painted on the platform.

The more you know…

After experimenting with the Up, I was determined to tune our Replicator to achieve similar qualities. Most of all, I was out to play with the support generation to see if I can achieve a less tenaciously integrated support lattice. I had been opposed to messing with before since technically it’s not “my” Replicator, but belongs to our research group, but I have literally not seen anyone else use it except me, so who’s gonna complain!?

I began by turning down the support flow rate ratio in Skeinforge way down. I had noticed before that the support material was almost as thick as my part lines, which seemed unnecessary. Next, I increased the density of the interface layers (which seems to drive the density of the support layers) so there was more ‘support resolution’. This did involve figuring out a better system so I could get the raft off the part easier (the denser interface layers appeared to want to stick to the part more than anything else). One more parameter I messed with was turning up the “support gap” ratio, which caused the lattice to be spaced further away – this was increased from its native 0.005 (meaning pretty much touching) to as far as 0.1.

I tested these settings by printing a few overhang dongles using full support and rafts, then when I thought I was at a good location, by test printing a difficult object which required full supports: this figurine on Thingiverse.

I think it turned out pretty damn great. Full disclosure: I tried this on the Up! and it got about 3/4 of the way up before the wiggling of the build plate caused the nozzle to bump the whole print off the machine. Oops. That’s what you get for being non-gantry, I guess.

Chunking off the support was pretty easy, but there were definitely lots of areas where I had to knife pretty hard. It looks like I’m the first person on Thingiverse to even try this print, too.

Additionally, one thing I noticed was that the long runs of very thin support lattice (seen in the first picture of the print) tended to warp and buckle much easier than a thin walled part would, probably because the flow rate is modified so much. On smaller prints it was okay, but I’ve definitely had support detatch from itself and curl up before. Once that happens (it seemed to happen at the base of the model), it is generally very hard for it to pick itself up again.

So I decided to try turning on the “crosshatch” option, which normally in RepG makes a pretty damn solid lattice that is utterly impossible to do anything with, but turning the flow rate down even further. The result is what I will call “point cloud” support. The string of plastic breaks between intersections (or leaves very very fine threads) and basically forms a coarse-, open cell, layer-by-layer deposited foam:

 

The “point cloud” is supported by the interaction of all those fine drool threads  and is remarkably solid if you push on it, but it falls away in huge chunks and the remainder is easier to scrape off. Still not Up! class, but a pretty awesome departure away from having to chisel your part out of its own pupa.

 

I next tried this method on the ultimate test: something I 3d scanned, so is not going to be remotely clean or easy anywhere.

 

The model in question is a Hatsune Miku mini-Nendoroid figure that I own. Now, if you know me, you know that just about the only thing I can be considered a ‘fan’ of is Miku and the Vocaloid media franchise and user community. It’s difficult to explain what it is without sounding like an internet startup guy, hipster and open-source advocate at the same time. In short it’s crowdsourced user-supported synthesized music you’ve never heard of.

Hey, when did I get a 3D scanner?!

It’s not mine, per se, but the IDC lab space has been getting some new toys since the last semester, partially in support of MAS.863, the renowned MIT Media Lab class that teaches fabrication and design skills (which Mechanical Engineering doesn’t have an equal to, by the way). This NextEngine triangulating laser scanner is one of them.

Since this was pretty much my first stab at 3D scanning, I neglected to take more than a few orientation scans (which meant the model had a ton of uncloseable holes in it) and then tried to save it at full resolution into an STL. The result was a 130 megabyte STL file that nothing could open or slice. I had to go back and greatly simplify the polygon count in order for ReplicatorG to even think about working with it.

While the STL just had too many gaps and errors for Replicator to generate a successful tool path (there’s some places that are just totally missing or filled with garbage), the “point cloud” support worked as intended. It looks really messy and disgusting on the outside, but the interior is a regular grid of very fine blobs and lines.

Since the whole point of this exercise is really just to get me a Miku figure clone, I tried it on the venerable Up. It handled the errorful STL wonderfully, though it pointed out to me where each and every one of the missing faces was. This was once again an overnight job…

Miku ended up being 4 discrete solids because of the holes in my model – the scanner couldn’t really capture the detail of the hair joint in the orientations I had it, so the point/mesh cleanup routine chopped them off. And no matter how removable the Up support is, it was still made out of the same ABS and so I had to cut part of her loop antenna structure off to remove the internal support, then reglue it back on.

Her legs are also… uhh, detachable?

But some hot glue fixes both problems.

I’m going to sacrifice this figure by supergluing the joints together so it can stay in one pose, long enough for me to scan it from every orientation. Then maybe I can get a higher resolution and fully one-shot printable model up on Thingiverse.

The bigger lesson here, though, is that I really like the “point cloud” support method. I’ve made so many changes to my Skeinforge settings that it’s not really worth trying to narrate them all here. So I’m just going to upload my slicing settings here (stuff the whole folder into your .replicatorg/sf_50_profiles directory and it should automatically recognize from within Skeinforge.

I’m actually kind of serious about trying an Uplicator hybrid. Pretty much all 3D printers are just a few steppers and a heater or two, so I don’t see much difficulty. They even sell the control board for the Up, but sell the CPU separately…for one hell of a sum. I wonder if that’s just an ATMega chip on a breakout board.

The only issue I see right now is that the Up homes differently than the Replicator – the former homes at “Z maximum” and the latter at Z minimum, necessitating different limit switch placement. In the mean time, Up!

but there’s a catch

With two competent hobby-class 3D printers sitting next to me, there’s something that has been a little forgotten which I will now finally decommission.

Poor Make-a-Bot.

The last time I turned this thing on was in late March some time. Ever since then, it’s been sitting quietly on a table, gathering MITERS grunge. The hardware, Makerbot’s Gen3 boards, and the extruder (a stepper chopped MK5), are generations behind. It was really never meant to be a 3D printer – too beefy and solid, but with my extra-stiff axes and much larger stepper motors I could still hold good resolution even at moderate (50-60mm/s) speeds. It’s really better off as a PCB router or very small mill.

Make-a-Bot isn’t being dismantled. Instead,

I’ve sold it to a hopefully loving new home that will turn it into something else awesome. Bye Make-a-Bot :(