Guides
Sensor readings
Each analog reading the firmware takes has two controls. A normal value is what the reading is in normal operation, so the rest of the board still acts on it. A forced value is what the firmware reads instead, as from a faulty sensor or measurement path, until you release it.
Find the readings
Boards that offer these list them under panels such as temperature-sensors and power-monitors, named after the firmware's own telemetry:
for c in board.controls():
if c.name.startswith("power-monitors.motor-bus-current"):
print(c.usage)
# power-monitors.motor-bus-current-normal <value 0..3.6 V>
# power-monitors.motor-bus-current-forced <value 0..3.6 V>
# power-monitors.motor-bus-current-releaseEach reading also has four values to read: …-current (what the firmware reads now), …-current-normal, …-current-automatic (what the board drives the pin with now) and …-current-forced (None when nothing is forced).
Units
The values are volts at the processor's ADC pin: the sensor's or monitor's output voltage. That is the NTC divider's output for a temperature, or the current-sense amplifier's output for a current. The simulated ADC then scales and quantizes them against its reference, as the chip does, and your firmware converts them as it would on the board. A board lists a reading in °C or amps only when its model has that sensor's transfer function, so the simulation never makes up a conversion.
- The range is 0 V to the pin's absolute maximum (3.6 V on a 3.3 V part). Anything else is refused with an error.
- Above the ADC's reference the reading saturates at full scale, as a real converter does.
- A normal value is not a rail voltage. A rail's own control (a supply, a regulator) changes the rail and everything on it.
Change a normal value
A reading that follows a rail keeps doing so. Here the motor current monitor sits behind a current limiter: set its normal value, and it still reads 0 when the limiter trips.
def test_overheat_derates_the_motor(hardlabs_board):
board = hardlabs_board
board.do("temperature-sensors.stepper-casing-normal", 1.10) # V at its pin: a hot casing
board.wait(2) # the firmware's next readings
... # assert your firmware's response
def test_normal_current_still_drops_on_a_trip(hardlabs_board):
board = hardlabs_board
board.do("power-monitors.motor-bus-current-normal", 0.20)
board.do("U9.trip") # the motor rail's limiter
board.wait(0.1)
assert board.read("power-monitors.motor-bus-current") == 0Force a reading
A forced reading changes only what the firmware reads. The rail stays tripped, its fault line stays as the part drives it, and nothing extra flows. Everything under the reading keeps changing:
def test_stuck_current_sensor(hardlabs_board):
board = hardlabs_board
board.do("power-monitors.motor-bus-current-forced", 0.30) # the sensor sticks
board.do("U9.trip")
board.wait(0.5)
assert board.read("power-monitors.motor-bus-current") == 0.30 # what the firmware reads
assert board.read("power-monitors.motor-bus-current-automatic") == 0 # what the board does
assert board.read("U9.fault-injected")
board.do("power-monitors.motor-bus-current-release")
assert board.read("power-monitors.motor-bus-current") == 0 # the trip, as it is nowOrder of precedence, highest first:
- Forced: the firmware reads it, whatever else happens.
- Automatic behaviour: a tripped or switched-off rail reads 0.
- Normal value: the reading otherwise.
Setting a normal value while the reading is forced is kept for later, and the firmware reads it once you release. Releasing never brings back a value from before the force.
When the firmware sees it
A change reaches the firmware at its next conversion of that channel. A result already converted stays in the ADC's data register until then, and your firmware's own averaging or filtering applies on top. Let some simulated time pass with Board.waitbefore you check the firmware's response.
How long a value lasts
- A firmware reset (a watchdog, a software reset or the reset button) keeps normal and forced values: they are the board's conditions, not the chip's.
Board.restartandBoard.startstart a new simulation, so every reading goes back to the board's defaults. Only the memory chips carry over a restart. Set your values again after one.- Memory snapshots (
Board.save_memory) hold memory chips only, not readings. - Between tests, the pytest board is shared for the session. A value you set stays for the next test until you put it back.
import pytest
@pytest.fixture(autouse=True)
def default_readings(hardlabs_board):
yield
hardlabs_board.do("temperature-sensors.restore-defaults") # nothing forced, every normal value back
hardlabs_board.do("power-monitors.restore-defaults")Each simulation has its own values, so two boards never share them. Use release-all to release every forced reading on a panel and keep its normal values.