.. index:: instrument your mcu, loadmeter, multitasking, hackaday .. _loadmeter: Loadmeter ========= During embedded development, an accurate idea of the MCU load is important, and it's nice to have it confirmed by a second source ... enter the "Loadmeter". The meter is a *53 year old* Sangamo Weston uA meter .. image:: pics/loadmeter.jpg .. seealso:: This project was featured on Hackaday: https://hackaday.com/2017/05/13/microcontroller-load-meter-tells-you-how-hard-its-currently-working/ Cooperative Multitasking ------------------------ A cooperatively multitasked system relies on each process regularly giving up time to other processes on the system. One poorly designed *task* or *process* can consume all of the CPU time for itself, either by performing extensive calculations or by *busy waiting*; both would cause the whole system to *hang*. Whilst a *cooperative scheduler* starts each *task*, they must voluntarily give back control when they are finished or even during stages of their operation by using the *pause* Word. .. note:: busy-waiting, busy-looping or spinning is a technique in which a process repeatedly checks to see if a condition is true How Does It Work ? ------------------ A *loadmeter-task* sends a short pulse to a Microamp Meter. Any other tasks delay the rate at which *loadmeter-task* can send pulses, therby reducing the *duty cycle* of the square wave pulse train to the meter, giving a *lower* reading and indicating more *load*. A moving coil meter is ideal because the mechanical inertia will average the duty cycle of the pulse train. Calibration ----------- The Loadmeter is calibrated with a trimpot for a point near the high reading of the meter, (in this case the "0" on the DB meter scale) to indicate the minimum load of the default system. This is done while *only* the *loadmeter-task* is running. Usage ----- Once the *loadmeter-task* is running, subsequent *tasks* will cause the Loadmeter pointer to move to the left, indicating they are using MCU time, which is a increase in *load*. While indicating MCU load, a steady pointer shows ideal rapid cycling between *tasks*, but a pulsing Loadmeter pointer indicates a *task* may be *hogging* the MCU or perhaps the "pause" Word is in the wrong place, such as at the end of a 1 second delay, when it should be in the loop counter instead ? The Loadmeter also indicates: 1) How additional "pause" Words can have zero effect 2) Whether a *task* can be made more efficient with better code or perhaps by using a timer for a delay instead of spinning ? Schematic Diagram ----------------- A STM32F0 Discovery board was used. Loadmeter Schematic Diagram ^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: pics/ms-loadmeter-schematic.jpg Source Code and Notes --------------------- Notes: * The F0 Discovery board lacks RAM for more tasks, having only 8KB of RAM. Mecrisp-Stellaris will raise a 'Not Enough Ram' error if one more task is added. * This is all running from Flash so I can fit in the 5 tasks, if ms-loadmeter.fs is run from ram, then a task must be removed. * The USER push button lights the GREEN LED when depressed. * The Blinky flashes the BLUE LED on and off about once a second * Delays 1 and 2 just delay for a second each, they are there to waste time. * All ancillary files are available from the :ref:`library` * :download:`ms-loadmeter.fs` and :download:`ms-loadmeter.memmap.fs` are available here. .. literalinclude:: library/ms-loadmeter.fs Loadmeter Pics -------------- Load task running ^^^^^^^^^^^^^^^^^ .. image:: pics/loadmeter-load.jpg Load and blinky tasks running ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: pics/loadmeter-load-blinky.jpg Load, blinky and delay1 tasks running ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: pics/loadmeter-load-blinky-delay1.jpg Load, blinky, delay1, and delay2 tasks running ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: pics/loadmeter-load-blinky-delay1-delay2.jpg Load, blinky, delay1, delay2 and user-pb tasks running ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. image:: pics/loadmeter-all-tasks-running.jpg