This page describes the concept of memory & settings, and how parameters are saved into memory and used by the hvps-x firmware.
The hvps-x firmware relies on settings. Settings combine operational parameters (e.g. voltage set point, frequency, switching mode, etc.) and configuration parameters (voltage calibration, PID gains/constants, etc). During execution, the firmware interacts with the active settings which are stored in RAM. Three types of settings are stored in non-volatile memory (NVM).
- Current settings represents the default state and configuration of the hvps-x. They are the settings which are loaded into the active settings when the hvps-x initialises.
- Backup settings are a set of settings that can be used to restore the configuration / calibration of the hvps-x in case of corruption of the current settings or following modifications of the parameters
- Factory settings are a set of hard-coded settings that enable the firmware to run but do not contain any board-specific values. They are the only parameters that are available initially, prior to configuring a board.
Current and backup settings have a CRC error detecting code stored in memory to ensure that the set of settings is valid.
Firmware initialisation
When the firmware initialises, it will read a set of settings from memory and transfer it to the active settings in RAM
- The current settings will be read and the CRC of the data will be calculated. If this matched the CRC value stored in memory, these settings become the active settings used by the hvps-x while it is powered up.
- If the current settings are corrupted, the backup settings will be read. If the CRC of the data match the value stored in memory, these settings become the active settings used by the hvps-x while it is powered up. There is no indication to the user that the backup settings are used, but they should ideally be identical to the current settings (minus operating parameters).
- If step 1 and 2 fail, the factory settings are used. These are default settings for a 5kV hvps-x. When factory settings are used, the hvps-x is considered unconfigured. To warn the users that factory settings are used, the red and blue LED will flash for a few seconds. In addition the GUI will not connect to an unconfigured hvps-x. The library of functions has an option to connect to unconfigured devices.
When the firmware is flashed on a microcontroller for the first time, the current and back-up settings memory spaces are empty. Hence on the first start-up, factory settings are used, as will be indicated by flashing blue and red light for a few seconds. During the initial configuration, as described here, current and backup settings will be written. During the configuration stage, current settings and backup settings will be written with the exact same information.
The automatic transfer from NVM to the active settings in RAM occurs when the hvps-x is powered up, and not when the GUI is launched. This makes it possible to set the hvps-x in a desired state and use it without the GUI. It also means that if the GUI is used to set some parameters, closed, and opened again, the last used parameters will still be the active parameters, as the hvps-x only reverts to the current settings if it is power cycled.
Interacting with settings
There are different ways to interact with the set of settings in RAM and NVM and to copy one set of settings to another through the GUI or using library commands.
- Settings can be loaded from the NVM to the RAM for usage by the hvps-x. This is done automatically during initialisation (in which case current settings are used if valid), but can also be triggered at any time by the user. If manually triggered, it is possible to chose which set of settings to load (current and back-up). This is for example the way to restore the back-up settings if wrong parameters were written to the current settings.
- The active settings can be saved in memory to store the current configuration of the hvps-x. Saving to the current settings is the default and is available via a button on the GUI for convenience. Saving to the backup settings would typically be done after performing a calibration.
- Settings can be copied directly in memory, without transferring them to the active settings. The most common usage would be to copy the backup settings to the current settings to restore settings that have been altered. For example, you might have experienced with different PID gain values in the current settings, but would like to revert to the previously saved values.
- Settings can be transferred from memory to a JSON file on the computer. This is an additional way to save the settings for safekeeping.
- Settings JSON files previously downloaded can be transferred back to memory
- During normal use of the hvps-x using the GUI or library, settings are read and written using the USB connection. This direct interaction is between the host and the active settings, and will be lost once the hvps-x is powered down. However, a save command (2) can be used to commit the settings in memory. For example, this is how calibration is done: calibration constant are transferred from the host to the hvps-x active settings, and then committed to memory (either current settings when experimenting, or both current and backup settings for definitive parameters.