The debugger module is very straight forward. Let’s take a look!

Above is the header file for the Debugger module. The debugger has 4 main components: a reference to the load regulator, a reference to the thermal regulator, a reference to the main timer and an instance of the HAL_UART class. The references to the regulators are necessary so that the debugger can retrieve information from the modules, as well as issue commands to them as necessary. The reference to the timer is needed so that the module knows when it should be executing code. Lastly, the HAL_UART class is necessary for the module to read and write information through serial communication.
There’s only one method for this class: run_debugger. It is responsible for outputting information about the system through serial, as well as reading user input.

First, the method checks the time and sees if enough time has passed for the rest of the method to run. If it has, then it grabs the measured voltage and current information from the load regulator module, along with the desired current and current offset. Then, if the load regulator is in constant current mode, then a string is constructed in char_tx_buffer to display the information. In the case of constant current mode, the measured voltage, measured current, desired current and offset are displayed.

In constant power mode, measured voltage, measured power, target power, desired current and current offset are displayed.
All other modes have information displayed similar to constant current and constant power mode, so I won’t be going through all of them. When the mode is OFF, only the measured voltage is displayed.

After the switch statement, regardless of what mode the load regulator is in, the debugger module adds the duty cycle of the fan, which it reads out of the temperature regulator. This completes the string construction, so the module finally transmits the string using the Serial class.
One thing to note is that the string is being transmitted using send_string_int, as opposed to send_string. send_string_int only sets up the transmission, and then the actual transmission is done using an interrupt handler. This allows the debugger module to transmit long strings without significantly impacting the timing of the rest of the system.

After setting up the transmission, the debugger module checks for input. read_rx_buffer returns the number of characters received; if nothing has been received, then the if statement doesn’t execute, and nothing happens. If a byte (or more) has been received, then the first byte is read. ‘c’, ‘p’, ‘r’, ‘v’ and ‘o’ set the load regulator to constant current, power, resistance or voltage mode, or OFF, respectively. If a number has been received, then the number is interpreted as a floating point, and the target value of the current mode is updated. For example, if “2.5” is the floating point and the load regulator is in constant power mode, then the load regulator will update to have a target power of 2.5 W. If anything else is received, then the input is invalid and ignored.
The debugger module is used for testing and is very useful when an LCD screen is not hooked up to the PCB. It’s pretty simple and limited, but fine for this project.