Skip to content

Commit e4ce0ce

Browse files
committed
altos/easymotor: Move pressure conversion code to ao_motor_flight.c
This inline function uses a pile of constants which aren't defined in ao_pins.h, so move it to ao_motor_flight.c where it is used Signed-off-by: Keith Packard <[email protected]>
1 parent 28e4cb2 commit e4ce0ce

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

src/easymotor-v3/ao_pins.h

+3-25
Original file line numberDiff line numberDiff line change
@@ -156,36 +156,14 @@
156156

157157
typedef int16_t motor_pressure_t;
158158

159-
/* want about 50psi, or 344kPa */
159+
/* want about 50psi, or 344kPa for boost and 30psi for coast */
160160

161161
#define AO_FULL_SCALE_PRESSURE 11031612 /* 1600psi */
162162
#define AO_BOOST_DETECT_PRESSURE 344000 /* 50psi */
163163
#define AO_QUIET_DETECT_PRESSURE 207000 /* 30psi */
164164

165-
static inline int16_t ao_delta_pressure_to_adc(uint32_t pressure)
166-
{
167-
static const double volts_base = 0.5;
168-
static const double volts_max = 4.5;
169-
170-
/* Compute change in voltage from the sensor */
171-
double volts = (double) pressure / AO_FULL_SCALE_PRESSURE * (volts_max - volts_base);
172-
173-
/* voltage divider in front of the ADC input to decivolts */
174-
double adc_dv = volts * 10 * 10.0/15.6;
175-
176-
/* convert to ADC output value */
177-
double adc = adc_dv * AO_ADC_MAX / AO_ADC_REFERENCE_DV;
178-
179-
if (adc > AO_ADC_MAX)
180-
adc = AO_ADC_MAX;
181-
if (adc < 0)
182-
adc = 0;
183-
184-
return (int16_t) adc;
185-
}
186-
187-
#define AO_BOOST_DETECT ao_delta_pressure_to_adc(AO_BOOST_DETECT_PRESSURE)
188-
#define AO_QUIET_DETECT ao_delta_pressure_to_adc(AO_QUIET_DETECT_PRESSURE)
165+
#define AO_PRESSURE_VOLTS_BASE 0.5
166+
#define AO_PRESSURE_VOLTS_MAX 4.5
189167

190168
struct ao_adc {
191169
int16_t v_batt;

src/kernel/ao_motor_flight.c

+29
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,35 @@ static AO_TICK_TYPE ao_interval_end;
5252

5353
uint8_t ao_flight_force_idle;
5454

55+
/* Compute ADC value change given a defined pressure change in Pa */
56+
57+
static inline int16_t
58+
ao_delta_pressure_to_adc(uint32_t pressure)
59+
{
60+
static const double volts_base = AO_PRESSURE_VOLTS_BASE;
61+
static const double volts_max = AO_PRESSURE_VOLTS_MAX;
62+
63+
/* Compute change in voltage from the sensor */
64+
double volts = (double) pressure / AO_FULL_SCALE_PRESSURE * (volts_max - volts_base);
65+
66+
/* voltage divider in front of the ADC input to decivolts */
67+
double adc_dv = volts * (10.0 * (double) AO_PRESSURE_DIV_MINUS /
68+
((double) AO_PRESSURE_DIV_PLUS + (double) AO_PRESSURE_DIV_MINUS));
69+
70+
/* convert to ADC output value */
71+
double adc = adc_dv * AO_ADC_MAX / AO_ADC_REFERENCE_DV;
72+
73+
if (adc > AO_ADC_MAX)
74+
adc = AO_ADC_MAX;
75+
if (adc < 0)
76+
adc = 0;
77+
78+
return (int16_t) adc;
79+
}
80+
81+
#define AO_BOOST_DETECT ao_delta_pressure_to_adc(AO_BOOST_DETECT_PRESSURE)
82+
#define AO_QUIET_DETECT ao_delta_pressure_to_adc(AO_QUIET_DETECT_PRESSURE)
83+
5584
/*
5685
* Landing is detected by getting constant readings from pressure sensor
5786
* for a fairly long time (AO_INTERVAL_TICKS), along with the max being

0 commit comments

Comments
 (0)