4 ms·
In the 90s I implemented a PWM motor controller in asm, for a robot with enough power to accelerate hard on soft grass, outside. Robot was rather over engineere
by robotresearcher 5y ago
In the 90s I implemented a PWM motor controller in asm, for a robot with enough power to accelerate hard on soft grass, outside. Robot was rather over engineered by a team mate who previously worked on automated farm machinery. Tested the microcontroller on the breadboard with an oscilloscope, all looked well: nice PWM shapes.
For the first integrated test on the robot, I high-centered it on some bricks so the wheels would turn freely, on the bench. Didn't want to deliver too much torque with wheels up, so asked for 1% PWM duty cycle. The robot leaped into the air, tearing off its umbilicals, hit the floor spinning and generally smashing shit up, including bits of me.
Debugging revealed that the output PWM duty cycle was inverted when commanded <2%, so my 1% command was 99% power. My breadboard tests had never gone below 3%, which I guessed was the minimum to overcome stiction on soft ground. Poor robot. The chunks out of my hands were the price I paid to learn to test important corner cases.
- MauranKilom 5y agoOuch. I'm curious what would cause the PWM output to invert under such condition? Was there a special case built in for <2% that was coded incorrectly, or did it emerge from something else?
- robotresearcher 5y agoMy timing bug, if I recall correctly. I was very inexperienced. I got better but never great at that kind of development.
- xondono 5y agoPWM periods and on-time are implemented in the time domain in hardware, so my guess would be issues with integer algebra. Some hardware implementations are notoriously weird on edge cases. Some manufacturers built PWM modules so 0 setting on the on-time register means “no signal”, while for others it means “minimal on-time” (no signal is achieved by turning off the module). The other bad handled case is when going above period (if period is set at 210 clocks but on time is set to 250). Some implementations wrap around, some get locked in “always on”.
- robotresearcher 5y agoThe uC I used did not have built in PWM. I implemented it using GPIO with excitingly bad results.