A programmable supply: what it can be set to, what it was set to, and what it delivers.
More...
|
| #define | SUPPLY_CAPS_PPS_DEFAULT { 3.3f, 21.0f, 0.02f, 0.5f, 5.0f, 0.05f } |
| | The range a USB-PD PPS (Programmable Power Supply) source offers in its widest profile, 3.3 to 21V in 20mV steps and up to 5A in 50mA steps.
|
|
#define | SUPPLY_OK_VOLTAGE 0x01u |
| | Which readings arrived; an absent one is drawn and logged empty.
|
|
#define | SUPPLY_OK_CURRENT 0x02u |
| #define | SUPPLY_SIM_LOAD_OHMS 6.0f |
| | A supply feeding a servo-like load, for the panel to run while no driver exists, and for the screenshots.
|
|
#define | SUPPLY_SIM_PERIOD_S 3.0f |
|
#define | SUPPLY_SIM_BURST_S 0.6f |
|
#define | SUPPLY_SIM_BURST_A 1.4f |
|
#define | SUPPLY_SIM_SOURCE_OHMS 0.05f |
|
| supply_caps_t | supply_caps_limited (const supply_caps_t *caps, const supply_limits_t *lim) |
| | The supply's caps narrowed by lim: the set points a screen offers.
|
| void | supply_trip_reset (supply_trip_t *t) |
| | Clears the trip state.
|
| supply_trip_kind_t | supply_trip_step (supply_trip_t *t, const supply_limits_t *lim, const supply_state_t *s, float dt_s) |
| | Take dt_s of the readings in s into the trips.
|
| float | supply_snap (float value, float min, float max, float step) |
| | value clamped to min .. max and rounded to a multiple of step above min.
|
| void | supply_reset_peaks (supply_state_t *s) |
| | The run's extremes start again from what is shown, and only from readings that arrived; a maximum with nothing under it starts at 0.
|
| void | supply_track_peaks (supply_state_t *s) |
| | Take this sample into the run's extremes, only what arrived.
|
| void | supply_reset_totals (supply_state_t *s) |
| | The run begins: nothing delivered, nothing counted.
|
| void | supply_count_totals (supply_state_t *s, float dt_s) |
| | Add dt_s of the readings to the run's charge and energy while the output is on, only what arrived; dt_s is clamped to 0 ..
|
| void | supply_sim_init (supply_sim_t *m) |
| | Sets up the supply model.
|
| void | supply_sim_set (supply_sim_t *m, float v, float i) |
| | Set points are snapped to the caps; the output's state is kept.
|
| void | supply_sim_output (supply_sim_t *m, bool on) |
| | Switches the model's output on or off.
|
| void | supply_sim_step (supply_sim_t *m, float dt_s, supply_state_t *out) |
| | Advance dt_s and write the readings, mode and set points into out, counting one more sample; peaks, totals and taken_ms are the caller's.
|
A programmable supply: what it can be set to, what it was set to, and what it delivers.
The SUPPLY screen and the log see this and never the supply's own wire, so the same screen runs on the panel's model now and on a driver for the PD mini (a USB Power Delivery trigger controlled over a UART) once its protocol is known. Which board talks to it is not decided either; this struct is what crosses whichever boundary that turns out to be.
Pure C, no ESP-IDF (Espressif Internet-of-Things Development Framework).
SPDX-License-Identifier: MIT
| #define SUPPLY_SIM_LOAD_OHMS 6.0f |
A supply feeding a servo-like load, for the panel to run while no driver exists, and for the screenshots.
The load is a resistance with a burst on top: LOAD_OHMS at rest, and every SUPPLY_SIM_PERIOD_S a burst of SUPPLY_SIM_BURST_A for SUPPLY_SIM_BURST_S, which is what a servo moving under load draws. When the load would draw more than the limit the model holds the limit and the voltage falls with it (CC); otherwise it holds the set voltage less a 0.05ohm source resistance (CV). Deterministic, so a screenshot is the same every time.
Take dt_s of the readings in s into the trips.
The count starts at the first reading seen over a threshold, and each reading over it after that adds the time since the one before; one at or under it starts the count again, and one that did not arrive leaves it where it is. A trip that is off forgets its count, and so does one whose threshold changed. A trip time of 0 fires on the first reading over. Returns which trip fired, once the time over reaches lim->trip_s; nothing while the output is off. dt_s is clamped to 0 .. 1s, as the totals' steps are.
- Parameters
-
| t | The trip state. |
| lim | The trip limits. |
| s | The readings. |
| dt_s | The time since the last call, in s. |
- Returns
- The trip that fired.