Well, it looks as though this series of posts (of which this is the second and possibly last) could be badly mis-titled.
For a start, it doesn’t look as though the pedal sensor of my malfunctioning e-bike is faulty.
And it now appears unlikely that I’m going to fix anything – not in the near future, anyway.
However, I had fun diagnosing and reverse engineering, so it’s worth delving into this a bit more. Troubleshooting, even when the trouble refuses to be shot, is entertaining in itself.
To briefly recap: the sensor that detects whether I’m pedalling got damaged some time back. Recently, the bike gave an error message and refused to work, so I assumed the sensor had finally given up the ghost – not least because it fell to pieces in my hand. At least, its plastic case did.
I tried attaching another sensor to the bike, but this didn’t clear the error. Hmm.
So I decided to take another look at the original. Although most of the plastic in which it was embedded had fallen to pieces, there was much still adhering to the circuit board. It took some time to scrape this away.
What I saw was the Hall effect sensor itself (that is, I thought it was one – this turned out to be wrong), a few passives, an LED and an 8-pin IC that I assume is a microcontroller. There are no markings on it.
I decided to power it up and see what happened. Like before, I hooked up the red VCC wire to +2.5V because this is the voltage I measured coming from the bike. The black wire was connected to ground (GND) and I pulled up the white wire to VCC via a 10KΩ resistor.
Waving a magnet near the sensor had no effect at all. The LED didn’t light and the voltage on the white sensor line remained the same as VCC. Oh well, I thought, the sensor or something else on this board is definitely dead.
But I got to thinking about that 2.5V. It seemed strangely low.
And I took a closer look at the board, cleaning it up some more. That’s when I realised that there are, in fact, two Hall effect sensors on the board, placed hard against each other. And there were codes on one of them – the numbers 2302 and 509.
Searching around Farnell, Mouser and the Interwebz showed that virtually every sensor of this kind in this sort of package is a 3.3V or 5V device. I found a datasheet for the HAL509 sensor, which looks a good candidate for what’s on the board, and that definitely does not operate below 3V.
According to the datasheet for the HAL509 Hall effect sensor: “The output turns low with the magnetic south pole on the branded side of the package and turns high if the magnetic field is removed. The sensor does not respond to the magnetic north pole on the branded side.”
Time to learn a little more about the circuit. It’s pretty simple, so I figured it wouldn’t take long.
The first step was to use the multimeter in continuity mode to buzz out the board, checking which sides of which components were attached directly to the VCC (red), GND (black) and signal (white) wires.
I also peered through a strong magnifier to see what I could learn from visible PCB traces. In three instances, the traces led under the IC, connecting to the pins from inside the chip’s footprint, which is always annoying. But using the continuity tester again told me which trace led to which pin.
There were a few awkward moments: testing continuity between the legs of the Hall effect sensors and the pins of the IC was tricky because they’re on opposite sides of the board. Wedging the meter probe between my chest and the board did the trick, but not without considerable use of a robust Anglo-Saxon vocabulary.
Eventually, though, I came up with this schematic.
It still doesn’t tell me a lot because of the obscure nature of that 8-pin IC. Power comes in via a diode (which causes a 0.6V drop). There’s the inevitable bypass capacitor for the chip. The output lines from the two Hall effect sensors go to separate pins on the IC (3 and 6). Pin 5 of the IC passes through a 330Ω resistor to both the anode of the LED and the white sensor line. The current through the LED also passes through a 10KΩ resistor to ground.
The white sensor wire is normally pulled high, which means that the LED will light via the 10K resistor (it is quite dim). I presume that the microcontroller will pull pin 5 low when it detects a magnet (or absence of one) which means the sensor line will go low. Pin 5’s other state is, I presume, high impedance.
With the sensor reconnected to my bench power supply, I cranked up VCC to 5V – and, sure enough, the LED came on. Moving a magnet past the sensor caused the LED to go off and then come on again.
So, in spite of sitting inside a shattered housing, with parts of the circuit being exposed to the elements for the past three years, it seems this sensor board is still working.
Which is a bit of a bugger, really. This sensor would have been relatively easy to replace. Now I’m going to have to look elsewhere, in more difficult places, for the fault.
[ADDENDUM] Since writing the post and setting it to go live, I took another look at the schematic above. I haven’t used KiCad in a while and so it was a good excuse to reacquaint myself with it.
I’m not planning to build the circuit, but it annoyed me that the schematic failed to pass the electrical rules check (ERC). It said that pin 1 of U2 (one of the Hall effect sensors) was not driven and the same for the GND connection you see at the bottom left corner.
I was going to ignore this, but my OCD kicked in.
My suspicion fell on the diode. You can see in the schematic above that it sits between the VCC input, top left, and where various components attach to the power rail. In other words, the U2 sensor’s VCC pin is not directly connected to VCC – there’s another component in the way. (Why the ERC didn’t complain of the same problem with U3 will forever remain a mystery.)
So, I moved VCC and its attendant PWR_FLAG to the other side of the diode. Now U2 has a direct path to VCC. This solved the problems (including the error with the GND connection – go figure). However, it also meant that pin 1 of the diode was now not connected to anything, so KiCad complained about that.
That was easily solved by adding a connector (a 1×1 header) for the red power wire – which I’d already done on the right side of the circuit to show where the white sensor wire connects. For good measure, and to keep my OCD completist pixies quiet, I also added a connector for the black ground wire.
I have no idea if this is the ‘correct’ way of doing all this, but it does have the benefit of making the three wire connections explicit. And it passes the ERC.