Sun, March 12, 2006 11:38 PM
ISR Timing and Throughts on Speed Calculation
As of r40, the Hall ISR is taking between 9.6 µs and 13.6 µs to execute. I ran the motor up as fast as I could (the car started making a pulse-quickening murmur), and determined that the Hall interrupts can come as often as every 260 µs. I'd be amazed if our car ever ran that fast in practice. (As a side note: I was about to stop pushing it faster when all of a sudden the whole thing shut down. I was shitting bricks. I thought I had burned something up again, but I immediately disconnected power, and nothing was even warm. Turns out, the power supply tripped into error mode, and cut power. Whew!)
With a transition every 260 µs, and a 200 Hz control loop, that's a maximum count of less than 20. This means our low-speed speed measurement is pretty poor, because we get a transition every 16 ms or so. We could probably do the speed calculation every 10th iteration of the control loop. Even this count, 200, would fit in a byte, speeding up the hall ISR. With a 200 Hz control loop, that would give us a new speed value at 20 Hz, which should be more than adequate. There's still a timer available, perhaps we can set up a separate control loop for the speed.
The Control timer ISR usually takes between 18 µs and 19.2 µs, but sometimes I see it take as much as 55 µs. I'm guessing this is some timing glitch, because it's all over the map, and happens relatively infrequently.
10 revolutions of the wheels is 478 Hall transitions, for 47.8 Hall transitions/wheel rotation. On the living room carpet, the wheel makes about 4.75 revolutions per meter (revolutions measured by eye), over a single meter, or about 14.2, measured over 3 meters (4.73 revolution/m). This gives 226.1 Hall transitions per meter.
If the math is right, a Hall transition (ht) every 260 µs means 1 wheel revolution (r) every 260 µs/ht * 47.8 ht/r = 12.43 ms/r, which means 1 s / 12.43 ms/r = 80.5 r/s, which is 80.5 r/s / 4.73 r/m = 17 m/s! That's 61.2 km/h (38 m/h)!
Obviously, it won't actually go that fast, except maybe downhill.