rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
supply.c File Reference

A programmable supply and its model. More...

#include "supply.h"
#include <math.h>
#include <stddef.h>
#include "bench_state.h"

Functions

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 ..
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.
static bool over_for (float *over_s, bool *over, float *at, bool arrived, float value, float threshold, float hold_s, float dt)
 One reading against its threshold: true once it has been over for hold_s, counted from the first reading seen over – not from the one before it, which was not over, so the first interval is not credited.
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.
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.

Detailed Description

A programmable supply and its model.

See supply.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ over_for()

bool over_for ( float * over_s,
bool * over,
float * at,
bool arrived,
float value,
float threshold,
float hold_s,
float dt )
static

One reading against its threshold: true once it has been over for hold_s, counted from the first reading seen over – not from the one before it, which was not over, so the first interval is not credited.

A threshold of 0 or less is off.

Parameters
over_sThe time over the threshold, in s.
overtrue while the reading is over.
atThe threshold the count was made against.
arrivedtrue when the reading arrived.
valueThe reading.
thresholdThe threshold.
hold_sThe time over the threshold that trips, in s.
dtThe time since the last call, in s.
Returns
true once the reading has been over for hold_s.

◆ supply_caps_limited()

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.

A cap below the supply's own minimum leaves the range at that minimum.

Parameters
capsThe supply's caps.
limThe limits to narrow by.
Returns
The caps narrowed by lim.

◆ supply_count_totals()

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 ..

1s, as the bench's totals are.

Parameters
sThe supply state.
dt_sThe time since the last call, in s.

◆ supply_reset_peaks()

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.

The minimum voltage is a reading only while the output is on: an output switched off reads 0V, and a floor of 0V reads as a collapsed rail.

Parameters
sThe supply state.

◆ supply_reset_totals()

void supply_reset_totals ( supply_state_t * s)

The run begins: nothing delivered, nothing counted.

Parameters
sThe supply state.

◆ supply_sim_init()

void supply_sim_init ( supply_sim_t * m)

Sets up the supply model.

Parameters
mThe model to set up.

◆ supply_sim_output()

void supply_sim_output ( supply_sim_t * m,
bool on )

Switches the model's output on or off.

Parameters
mThe model.
ontrue to switch the output on.

◆ supply_sim_set()

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.

Parameters
mThe model.
vThe set point voltage, in V.
iThe set point current, in A.

◆ supply_sim_step()

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.

Parameters
mThe model.
dt_sThe time step, in s.
outReceives the readings, mode and set points.

◆ supply_snap()

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.

A step of 0 or less only clamps.

Parameters
valueThe value to snap.
minThe lowest value.
maxThe highest value.
stepThe step above min, in the value's unit; 0 or less only clamps.
Returns
The value clamped to min .. max and snapped to a step.

◆ supply_track_peaks()

void supply_track_peaks ( supply_state_t * s)

Take this sample into the run's extremes, only what arrived.

Parameters
sThe supply state.

◆ supply_trip_reset()

void supply_trip_reset ( supply_trip_t * t)

Clears the trip state.

Parameters
tThe trip state.

◆ supply_trip_step()

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.

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
tThe trip state.
limThe trip limits.
sThe readings.
dt_sThe time since the last call, in s.
Returns
The trip that fired.