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

The schedule's move capture on the FAST channel, and FAST's history the level before a command is taken from. More...

#include "sense_sched_int.h"
#include <string.h>

Functions

bool sense_cap_under_way (const sense_cap_t *c)
 Whether a capture is armed, waiting or moving.
bool sense_sched_cap_arm (sense_sched_t *s, const sense_cap_arm_t *levels)
 Arm a capture on FAST with levels; rise_ua SENSE_CAP_RISE_AUTO takes the level before the command from FAST.
static float ua_to_a (int32_t ua)
 Convert µA to A.
static int32_t a_to_ua (float a)
 Convert A to µA, rounded half away from zero.
void sense_sched_cap_edge (sense_sched_t *s, uint64_t edge_us)
 The PWM frame carrying the new pulse starts at edge_us, on the clock now_us() reads; it may lie ahead.
void sense_sched_cap_disarm (sense_sched_t *s)
 Stop a capture; its count stays.
static void cap_end (sense_cap_t *c, sense_cap_state_t state)
 The capture ends as state, with what the move measured.
static int32_t fast_ua (const sense_sched_t *s, const sense_value_t *v)
 A clipped FAST sample at the end of the range it is at or past, as the capture's filter takes it; a sample with a value as it is.
static void fast_keep (sense_sched_t *s, const sense_value_t *v, uint32_t at_t)
 A FAST sample into the history the level before a command is taken from.
static bool take_rise (sense_sched_t *s)
 The level before the command: the mean of the FAST samples stamped in the SENSE_WINDOW_MS before the edge.
static void cap_step (sense_sched_t *s, const sense_value_t *v, uint32_t at_t)
 A FAST sample, or none, and the clock: both at at_t.
void sense_cap_step (sense_sched_t *s, const sense_value_t *v, uint32_t at_t)
 The capture's step: FAST's sample of this tick, or NULL with none, at at_t (0.1ms).

Detailed Description

The schedule's move capture on the FAST channel, and FAST's history the level before a command is taken from.

See sense_sched.h.

SPDX-License-Identifier: MIT

Function Documentation

◆ a_to_ua()

int32_t a_to_ua ( float a)
static

Convert A to µA, rounded half away from zero.

Parameters
aCurrent in A.
Returns
Current in µA.

◆ cap_end()

void cap_end ( sense_cap_t * c,
sense_cap_state_t state )
static

The capture ends as state, with what the move measured.

Parameters
cThe capture.
stateThe state the capture ends in.

◆ cap_step()

void cap_step ( sense_sched_t * s,
const sense_value_t * v,
uint32_t at_t )
static

A FAST sample, or none, and the clock: both at at_t.

Parameters
sThe schedule.
vFAST's sample, or NULL when there is none.
at_tTime of the step, in 0.1ms.

◆ fast_keep()

void fast_keep ( sense_sched_t * s,
const sense_value_t * v,
uint32_t at_t )
static

A FAST sample into the history the level before a command is taken from.

Parameters
sThe schedule.
vThe FAST sample.
at_tTime of the sample, in 0.1ms.

◆ fast_ua()

int32_t fast_ua ( const sense_sched_t * s,
const sense_value_t * v )
static

A clipped FAST sample at the end of the range it is at or past, as the capture's filter takes it; a sample with a value as it is.

Only called with a FAST channel.

Parameters
sThe schedule.
vThe FAST sample.
Returns
The current in µA.

◆ sense_cap_step()

void sense_cap_step ( sense_sched_t * s,
const sense_value_t * v,
uint32_t at_t )

The capture's step: FAST's sample of this tick, or NULL with none, at at_t (0.1ms).

Then the sample into the history.

Parameters
sThe schedule whose capture and history are updated.
vFAST's sample of this tick, or NULL when there is none.
at_tTime of the step, in 0.1ms.

◆ sense_cap_under_way()

bool sense_cap_under_way ( const sense_cap_t * c)

Whether a capture is armed, waiting or moving.

Parameters
cThe capture to test.
Returns
true while the capture is armed, waiting or moving.

◆ sense_sched_cap_arm()

bool sense_sched_cap_arm ( sense_sched_t * s,
const sense_cap_arm_t * levels )

Arm a capture on FAST with levels; rise_ua SENSE_CAP_RISE_AUTO takes the level before the command from FAST.

Refused, and nothing changed, with no FAST channel or while its INA3221 is not online.

Parameters
sThe schedule.
levelsThe capture levels.
Returns
true when the capture is armed; false when refused.

◆ sense_sched_cap_disarm()

void sense_sched_cap_disarm ( sense_sched_t * s)

Stop a capture; its count stays.

Parameters
sThe schedule.

◆ sense_sched_cap_edge()

void sense_sched_cap_edge ( sense_sched_t * s,
uint64_t edge_us )

The PWM frame carrying the new pulse starts at edge_us, on the clock now_us() reads; it may lie ahead.

The samples taken while armed seed the filter. Nothing unless a capture is armed.

Parameters
sThe schedule.
edge_usStart of the PWM frame carrying the new pulse, in µs.

◆ take_rise()

bool take_rise ( sense_sched_t * s)
static

The level before the command: the mean of the FAST samples stamped in the SENSE_WINDOW_MS before the edge.

False with none.

Parameters
sThe schedule.
Returns
true when at least one sample lies in the window before the edge; false otherwise.

◆ ua_to_a()

float ua_to_a ( int32_t ua)
static

Convert µA to A.

Parameters
uaCurrent in µA.
Returns
Current in A.