Battery testing

I finally got around to tuning the new balancing robot a few days ago. It didn't go very well: I set KP and moved onto KI, but it started simply to fall over. Then I realised the battery was starting to drain: that was the problem. The charge had just leaked out over a week or so. I'd actually anticipated this, and added a little divider network to the motor board, to let me test the battery with an ADC, so I decided to add the required code.

The resulting commit is here.

There are a lot of choices when doing ADC conversion in the STM32F4: If you want to sample as fast as the device can go, you can collect the data with a callback. You could also trigger conversions periodically, using a general purpose timer.

Both of these require hardware resource assignment: Owning the ADC device, and also a general purpose timer in the second case. The STM32F411 only has one ADC, although it's pretty fast and can cycle through 16 channels. It's also a bit quirky though: You can have up to 3 different sampling settings.

Chibios doesn't bother to hide this complexity: you need to construct the values of the control registers to set it up. It does provide some helpful macros, but doesn't  document them all that well.

If you want something anywhere near as simple as Arduino, you will just want to use a thread. I guess that wastes lots of memory, but at least memory is fungible! Anyway, that's what I've done in this case.

Popular posts from this blog

3D Printer ramblings

Balance Bot V2

Robot arm