An attempt to build an Engine Control Unit based on stm32.
It's really not that hard.

The million-dollar question is how precisely we can turn outputs on and off.

The straightforward implementation would be to use hardware-based PWM timer with a callback which would turn PWM off after one pulse, but with a limited tumber of hardware timers I do not really like this solution. In current stable version of ChibiOS, context switches are based on the system ticks and the maximum frequency of the system clock seems to be around 100Khz.
An alternative solution is what is called CH_FAST_IRQ_HANDLER - that's a faster system timer which is not allowed to interact with the kernel. We do not need to interact with anyone in order to just turn pins on and off, so this should work. CH_FAST_IRQ_HANDLER callback can go up to 500KHz.

So, I have implemented a 200Hz 50% duty wave using all three approaches and connected the output pins to 12Mhz logic analyzer, here are the widths:

Hardware PWM:
2.500ms
2.500ms
2.500ms
2.500ms
2.500ms
2.500ms
2.500ms
2.500ms
2.500ms

CH_FAST_IRQ_HANDLER:
2.506ms
2.506ms
2.505ms
2.507ms
2.505ms
2.506ms
2.506ms
2.507ms
2.500ms

Sleep() implementation
2.500ms
2.520ms
2.500ms
2.520ms
2.500ms
2.520ms
2.500ms
2.520ms
2.500ms


Full snapshop is available here, you can open it with Saleae Logic Software

Click here to discuss this


Comments?

Copyright (c) 2012-2013 Andrey