Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite of remote control code #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ version 3.8 or higher (3.7 sometimes crashes during compilation).
The datasheet of the STM8S005 claims a write endurance of only 100 flash cycles
but this is only for marketing purposes as it [contains the same die](https://hackaday.io/project/16097-eforth-for-cheap-stm8s-gadgets/log/76731-stm8l001j3-a-new-sop8-chip-and-the-limits-of-stm8flash)
as the STM8S105 which is rated for 10000 cycles. So you don't have to worry
about bricking your device by flashing it too often. Mine has far more than 100
about bricking you device by flashing it to often. Mine has far more than 100
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this? The original text looks good to me.

cycles and still works. You can easily verify the two chips are the same as you
can write the whole 1kB of EEPROM the STM8S105 has instead of only 128 bytes
as claimed by the STM8S005 datasheet.
Expand Down Expand Up @@ -103,6 +103,58 @@ run mode.
* SUP: 12V input voltage is too low. Connect better power supply.
* INT: Internal error. Should not happen. Check the source code where this error is set and try to fix it.

### Serial Remote Control
Command can be sent to the device over the serial port. All settings can be modified and the load can be enabled and disabled. A help system is included. Send `HELP` or `command HELP` for details. The code is designed to be easily expandable if you need to add more commands.

#### SETMODE [CC|CV|CR|CP]
Set the operating Mode of the electronic load.
* CC = Constant Current
* CV = Constant Voltage
* CR = Constant Resistance
* CP = Constant Power

#### SETI [mA]
Set the target amperage for constant current mode.
* mA = Target amperage in milliamps between 200 (0.2A) and 10000 (10A)

#### SETV [mV]
Set the target voltage for constant voltage mode.
* mV = Target voltage in millivolts between 500 (0.5V) and 30000 (30V).

#### SETR [mR]
Set the target resistance for constant resistance mode.
* mR = Target resistance in milliohms between 10 (0.01 ohms) and 15000 (15 ohms)\n"

#### SETP [mW]
Set the target power for constant power mode.
* mW = Target power in milliwatts between 0 and 60000 (60W)

#### SETBEEP [OFF|ON]
Enable or disable alarm and notification sounds.
* OFF = Turn off alarms and notifications
* ON = Turn on alarms and notifications

#### SETCUTOFF [mV|OFF]
Target cutoff voltage. If the voltage falls below target, the load will be disabled.
* mV = Cutoff voltage in millivolts between 500 (0.5V) and 30000 (30V)
* OFF = No action will be taken if voltage falls too low

#### SETILIMIT [mA]
Set current limit. If this current is exceeded, the load will be disabled.
* mA = Amperage limit in milliamps between 200 (0.2A) and 10000 (10A)

#### SETPLIMIT [NOLIMIT|LIMIT]
Set action to take if maximum power limit is exceeded.
* NOLIMIT = No action is taken
* LIMIT = Load will be disabled if power limit is exceeded

#### LOAD [ON|OFF]
Requests the load to activate or deactivate.
* ON = Activates the load
* OFF = Deactivates the load
NOTE: ON is similar to pressing the run button and will take you up one menu level. It will only enable the load if you are at the top menu level. Send multiple LOAD ON commands until you see the realtime output indicate the load is on.
NOTE: OFF disables the load but does not return you to the menu. Use the hardware run button if you need to get in to the menu

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remote control should be independent of the currently selected menu.

## History
This firmware started as a project to extend the firmware written by
[soundstorm](https://github.com/ArduinoHannover/ZPB30A1_Firmware) but it turned
Expand Down
55 changes: 0 additions & 55 deletions serial protocol.md

This file was deleted.

2 changes: 1 addition & 1 deletion software/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ STLINK_VERSION=2

MAIN=electronic_load.c
SRC=tm1650.c uart.c utils.c fan.c ui.c eeprom.c timer.c load.c settings.c \
adc.c beeper.c menu_items.c
adc.c beeper.c menu_items.c remote.c
BUILDDIR=build

SRC:=$(MAIN) $(SRC)
Expand Down
174 changes: 174 additions & 0 deletions software/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,176 @@
# ZPB30A1 Firmware
This repository is there to build an open-source firmware for the 60W ZPB30A1 electronic load (often sold as "60W electronic load" without any article number).

## Features
* Modes
* CC: Constant current
* CR: Constant resistance
* CP: Constant power
* CV: Constant voltage (slow regulation due to hardware limitations)
* Easily usable menu system with many configuration options
* Logging of all operating parameters via UART.
* Much better accuracy than stock firmware.
* Clean firmware structure for easy extendability.


## Original Firmware
The original firmware has read out protection enabled. Therefore you can't go
back to this version once you flash a different one. But this firmware aims to
be much better in every possible way. If you need a feature either add it on
your own and submit a pull request or open an issue and wait till I add it.

## Compiler

This software requires [Small Device C Compiler (SDCC)](http://sdcc.sourceforge.net/)
version 3.8 or higher (3.7 sometimes crashes during compilation).

## Chip
The datasheet of the STM8S005 claims a write endurance of only 100 flash cycles
but this is only for marketing purposes as it [contains the same die](https://hackaday.io/project/16097-eforth-for-cheap-stm8s-gadgets/log/76731-stm8l001j3-a-new-sop8-chip-and-the-limits-of-stm8flash)
as the STM8S105 which is rated for 10000 cycles. So you don't have to worry
about bricking you device by flashing it to often. Mine has far more than 100
cycles and still works. You can easily verify the two chips are the same as you
can write the whole 1kB of EEPROM the STM8S105 has instead of only 128 bytes
as claimed by the STM8S005 datasheet.


## Flashing
As the original firmware has the bootloader disabled you need a STLink programmer
in order to unlock it. Connect it like this:

![Programmer connection](images/stlink.jpg)

If you are programming the chip for the first time you have to unlock it.
'''WARNING:''' This irreversibly deletes the original firmware.

make unlock

Then you write the new firmware with

make flash

and if you are flashing for the first time you should also clear the EEPROM:

make clear_eeprom

## Menu
Contrary to the original firmware which requires rebooting to change modes this
firmware is completely configurable by an integrated menu system. Push the
encoder button to select an item. The "Run" button acts as a back button in most
situations. Only in the top level menu it is used to enable the electronic load.
The currently selected option blinks. When setting a numeric value the two
LEDs between the displays show the selected digit.
Values shown with a decimal point are in the unit shown by the LEDs or on the
display. If no decimal point is shown it means the display shows 1/1000 of the
selected unit.
### Examples
* 10.0 + V LED: 10.0V
* 1.23 + A LED: 1.23A
* 900 + V LED: 900mV = 0.9V


### Menu structure
* MODE
* CC: Constant current (default)
* CV: Constant voltage
* CR: Constant resistance
* CW: Constant power
* VAL: Sets the target value for the currently selected mode. The upper display
shows the unit.
* ILIM: Current limit (not active in CC mode)
* ...: More settings
* BEEP: Beeper on/off
* CUTO: Undervoltage cutoff
* ENAB: Enable/disable
* CVAL: Cutoff value in Volt
* MAXP: Maximum power action
* OFF: Turn off load when the required power would be greater than the hardware limit
* LIM: Reduce load current to stay within hardware limits

## Run mode
While in run mode the top display show V, Ah, or Wh. The bottom display show
the current.
The unit in the top display switches automatically after some seconds. Rotating the encoder
changes the unit manually and disables automatic switching.
Pressing the encoder enters a menu to change the current setpoint without exiting
run mode.

### Error codes
* OVP: Over voltage protection. Voltage connected to P+/P- is too high. (Note: This function can only warn about voltages which are slightly to high. Large voltages will destroy the electronic load!)
* OVLD: The load can't maintain the set value. Usually this means that the source can't deliver enough current or the source's voltage is to low.
* PWR: Power required to maintain the setpoint is greater than hardware's power limit.
* TEMP: Temperature is to high. Check if the fan is working and the thermistor is connected.
* SUP: 12V input voltage is too low. Connect better power supply.
* INT: Internal error. Should not happen. Check the source code where this error is set and try to fix it.

### Serial Remote Control
Command can be sent to the device over the serial port. All settings are can be modified and the load can be enabled and disabled. A help system is included. The code is designed to be easily expandable if you need to add more commands.

* SETMODE [CC|CV|CR|CP]
Set the operating Mode of the electronic load.
CC = Constant Current
CV = Constant Voltage
CR = Constant Resistance
CP = Constant Power

* SETI [mA]
Set the target amperage for constant current mode.
mA = Target amperage in milliamps between 200 (0.2A) and 10000 (10A)

* SETV [mV]
Set the target voltage for constant voltage mode.
mV = Target voltage in millivolts between 500 (0.5V) and 30000 (30V).

* SETR [mR]
Set the target resistance for constant resistance mode.
mR = Target resistance in milliohms between 10 (0.01 ohms) and 15000 (15 ohms)\n"

* SETP [mW]
Set the target power for constant power mode.
mW = Target power in milliwatts between 0 and 60000 (60W)

* SETBEEP [OFF|ON]
Enable or disable alarm and notification sounds.
OFF = Turn off alarms and notifications
ON = Turn on alarms and notifications

* SETCUTOFF [mV|OFF]
Target cutoff voltage. If the voltage falls below target, the load will be disabled.
mV = Cutoff voltage in millivolts between 500 (0.5V) and 30000 (30V)
OFF = No action will be taken if voltage falls too low

* SETILIMIT [mA]
Set current limit. If this current is exceeded, the load will be disabled.
mA = Amperage limit in milliamps between 200 (0.2A) and 10000 (10A)

* SETPLIMIT [NOLIMIT|LIMIT]
Set action to take if maximum power limit is exceeded.
NOLIMIT = No action is taken
LIMIT = Load will be disabled if power limit is exceeded

* LOAD [ON|OFF]
Requests the load to activate or deactivate.
ON = Activates the load
OFF = Deactivates the load
NOTE: ON is similar to pressing the run button and will take you up one menu level. It will only enable the load if you are at the top menu level. Send multiple LOAD ON commands until you see the realtime output indicate the load is on.
NOTE: OFF disables the load but does not return you to the menu. Use the hardware run button if you need to get in to the menu

## History
This firmware started as a project to extend the firmware written by
[soundstorm](https://github.com/ArduinoHannover/ZPB30A1_Firmware) but it turned
out as an almost complete rewrite which keeps the user interface idea.

## Schematic
Schematic can be found in [hardware/schematic.pdf].

### Schematic corrections:
* R5 = 10k
* R27 = 1k
* D6 = reversed polarity

### Component locations
![Component locations](images/components.jpg)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't duplicate the text from the main README.

# Module interface
* NAME_init(): Initialize hardware and variables. Set module to a safe state
* NAME_timer(): Called when the systick timer counts from the main loop.
Expand All @@ -8,3 +181,4 @@
* TIM2: Systick
* TIM3: CCR2: Fan
* TIM4:

12 changes: 8 additions & 4 deletions software/electronic_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "fan.h"
#include "adc.h"
#include "beeper.h"
#include "remote.h"
#include "inc/stm8s_clk.h"
#include "inc/stm8s_exti.h"
#include "inc/stm8s_itc.h"
Expand Down Expand Up @@ -55,26 +56,28 @@ void gpio_init()


void main(void) {

clock_init();
gpio_init();
adc_init();
uart_init();
remote_init();
systick_init();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use same indention settings as existing code.

load_init();
beeper_init();
fan_init();
settings_init();

__asm__ ("rim");

// Power on beep
beeper_on();
delay10ms(10);
beeper_off();

// Init UI after power on delay to avoid spurious button events.
ui_init();

systick_flag = 0; // Clear any overflows up to this point
while (1) {
if (systick_flag & SYSTICK_OVERFLOW)
Expand All @@ -88,10 +91,11 @@ void main(void) {
ui_timer();
load_timer();
uart_timer();
remote_timer();
systick_flag &= ~SYSTICK_COUNT;
}
uart_handler();
}

}

//Voltage OK interrupt
Expand Down
Loading