Firmware for programmable bench power supply EEZ H24005
The contributors are listed in CONTRIB.TXT. This project uses the GPL v3 license, see LICENSE.TXT. EEZ psu-firmware uses the C4.1 (Collective Code Construction Contract) process for contributions. To report an issue, use the EEZ psu-firmware issue tracker.
If you consider to join us in software development please check first if anything from this list you found interesting.
This project has Arduino/Genuino sketch for Mega2560 (8-bit, AVR) (not supported in M3 and newer releases!) and Due (32-bit, ARM) boards and accompanying libraries for the open hardware EEZ H24005 power supply firmware.
The unique feature of this project is a fully featured software simulator that can be used to evaluate all firmware features without having physical power supply on disposal. The simulator can be complied to run on major platforms such as Windows, Linux or Mac. It shares all the code with the Arduino Sketch plus emulation layer for the Arduino API, Ethernet library and digital controls used for programming and monitoring power supply.
Firmware key features:
We recommend Arduino IDE version 1.6.x or newer to compile and deploy Arduino sketch to the EEZ bench power supply.
eez_psu_sketch
and libraries
from the zip archive into Arduino folder on your computer. Arduino folder is e.g. My Documents\Arduino
on Windows or Documents/Arduino
on Linux and Mac.libraries
folder.libraries
folder.eez_psu_sketch.ino
in Arduino IDE.Tools->Board
and select Arduino Due (Native USB Port)
. If Arduino Due (Native USB Port)
is not present in the list of boards then go to Tools->Board->Boards Manager
and click on Arduino SAM Boards
then click on the Install button. When install is done close the Board Manager then go to Tools->Board
and select Arduino Due (Native USB Port)
.Tools->Port
and select the COM port for your PSU.Here we will explain how to build simulator from source code on Windows, Linux and Mac.
If you are on Windows, there is a pre-build version:
After you build and run simulator, a mouse is used as simulation of finger on the TFT touchscreen display.
Console window can be used to enter SCPI commands SCPI reference manual. SCPI commands can be also send by starting a telnet session to the port 5025:
telnet localhost 5025
To build simulator from the source code you need Visual Studio 2015. You can use Community Edition which is a free version of Visual Studio 2015. Visual Studio solution for the simulator is in simulator\\platform\\Win32\\eez_psu_sim.sln
. Open solution then build and execute simulator with F5
.
Here are the steps to build simulator on Linux:
sudo apt-get install -y git libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev
git clone https://github.com/eez-open/psu-firmware
cd psu-firmware/simulator/platform/linux/
make
Start simulator with:
./eez_psu_sim
Just as in case of Arduino sketch mentioned above that runs on real hardware you can access simulator using telnet client (use localhost or 127.0.0.1 for connection).
Mac users will require Brew for building. If you don't have it you can download and install it from here.
Here are the steps to build simulator on Mac:
brew install sdl2 sdl2_image sdl2_ttf
git clone https://github.com/eez-open/psu-firmware
cd psu-firmware/simulator/platform/linux/
make
Start simulator with:
./eez_psu_sim
Just as in case of Arduino sketch mentioned above that runs on real hardware you can access simulator using telnet client (use localhost or 127.0.0.1 for connection).
EEZ bench power supply sketch source code can be divided into following layers:
Board
Talks directly to the hardware, i.e. Arduino Shield +BP module (EEPROM, RTC, Ethernet, TLC5925) and post-regulators (ADC, DAC, IO Expander). Part of this layer is eez_psu_lib, a small Arduino library with definition of all pins used by EEZ bench power supply. This layer depends on Arduino platform API and third party UIPEthernet library.
Core
Implementation of EEZ bench power supply firmware functionality, for example Channel abstraction. It doesn't work directly with the hardware but uses the board layer, so it doesn't depends on Arduino platform API.
Control
This layer is using Core layer to implement local and remote control.
Local control is GUI based using TFT touch display. Special tool was developed to assist creation of GUI interface. This layer depends on third party library (UTFT_Pro derived from Rinky-Dink Electronics UTFT) that we use to draw graphical primitives.
Remote control is based on SCPI protocol. Check SCPI reference manual for available commands. This layer depends on third party scpi-parser library.
Additionally, simulator introduces two additional layers:
Simulator Emulation Layer
This layer is simulator's replacement for the Arduino platform and consists of:
GUI Front Panel
Communication between layers is unidirectional with some exceptions:
Ethernet and Serial to SCPI.
This is used to feed SCPI with the input received on serial and TCP port.
IO Expander to Core.
IO Expander interrupt handler sends GPIO register and ADC snapshot to the Core layer.
Here are the components of the board layer (all the files are in eez_psu_sketch
folder):
board.cpp
and board.h
)
bp.cpp
and bp.h
)
buzzer.cpp
and buzzer.h
)
eeprom.cpp
and eeprom.h
)
ethernet.cpp
and ethernet.h
)
rtc.cpp
and rtc.h
)
serial_psu.cpp
and serial_psu.h
)
temp_sensor.cpp
and temp_sensor.h
)
adc.cpp
and adc.h
)
dac.cpp
and dac.h
)
ioexp.cpp
and ioexp.h
)
Arduino library eez_psu_lib
is also a part of the board layer and it is located in libraries\eez_psu_lib
folder.
Here are some components of the core layer (all the files are in eez_psu_sketch
folder):
psu.cpp
and psu.h
)
channel.cpp
and channel.h
)
calibration.cpp
and calibration.h
)
profile.cpp
and profile.h
)
temperature.cpp
and temperature.h
)
datetime.cpp
and datetime.h
)
debug.cpp
and debug.h
)
util.cpp
and util.h
)
sound.cpp
and sound.h
)
persist_conf.cpp
and persist_conf.h
)
Implementation of the GUI is based on MVC (Model View Controller) architecture.
In MVC architecture, Model is where all the data that is displayed on the screen comes from and our Model is implemented in the Core layer.
View defines how everything looks on the screen. In our case, View is defined declaratively and definitions are created with the special tool we call EEZ Studio (it is not public yet!).
This tool creates JSON based eez-project file which contains definitions of GUI pages, styles, bitmaps and fonts along with data and action definitions.
JSON file is then compiled to C++ source code files (gui_document.cpp
, gui_document.h
, actions.cpp
and actions.h
)
that are included as an integral part of the sketch.
Controller is the glue code between Model and View. It is implemented in the all the files that start with "gui_" prefix.
Also, there is some utility code that is used, for example, to interact with the hardware:
lcd.cpp
, lcd.h
and UTFT_Pro is used to draw graphical primitives on the screen.touch.cpp
and touch.h
is used to get data from the touch hardware. Input from the touch hardware is filtered using touch_filter.cpp
and touch_filter.h
- check this and this video.font.cpp
and font.h
is used to to access font definitions created with EEZ Studio.We are using third party SCPI parser and have our own branch where command definitions could be in AVR PROGMEM that helps preserve some memory space when Arduino Mega board is used (check avr_progmem branch).
There are two entry points for the SCPI commands: serial port and TCP server. Check serial_psu.cpp
and serial_psu.h
to see how SCPI commands are received on serial port, and ethernet.cpp
and ethernet.h
for the TCP server.
Files scpi_psu.cpp
and scpi_psu.h
are about SCPI parser initialization and input handling.
Also, here is defined the scpi_psu_t structure for storing SCPI parser context data specific to EEZ bench power supply.
Parameter types that are repeatedly used in multiple commands (like channel number) are handled in scpi_params.cpp
and scpi_params.h
.
Registers are set/get in scpi_params.cpp
and scpi_params.h
.
All other files that starts with scpi_
in eez_psu_sketch/
directory are about implementing various SCPI commands. Every SCPI subsystem (like APPLy, SOURce, MEASure, SYSTem, etc.) has its own pair of scpi_
We emulate only what we use:
pinMode
, digitalRead
, digitalWrite
, analogRead
, analogWrite
digitalPinToInterrupt
, attachInterrupt
tone
millis
, micros
, delay
, delayMicroseconds
Serial
SPI
Check the files Arduino.h
, arduino_impl.cpp
, arduino_impl.h
, SPI.h
from the simulator\src\arduino
folder.
For the tone
function we have two different implementations:
simulator\platform\win32\eez_psu_sim\tone.cpp
simulator\platform\linux\src\tone.cpp
The following devices are controlled via SPI bus:
These peripherals are emulated in simulator, check the files chips.cpp
and chips.h
in simulator/src/chips
.
UIPEthernet library interface is defined in files UIPClient.h
, UIPEthernet.h
and UIPServer.h
; this interface is is implemented in file uipethernet_impl.cpp and this implementation is based on platform interface defined in ethernet_platform.h. There are two implementations of this platform interface:
simulator\platform\win32\eez_psu_sim\ethernet_win32.cpp
simulator\platform\linux\src\ethernet_linux.cpp
Implementation files are in simulator/src/front_panel
.
Implementation is using eez_imgui
dynamic library.
This library is dynamically loaded at runtime, so that simulator can run even if this library is missing (check the simulator/src/dll.h
for platform independent dynamic library loading).
eez_imgui
library is very simple immediate mode GUI library that supports top level window with following widgets: