Add calibration VREF option and set as default
This commit is contained in:
parent
5aaa1edad7
commit
70d20f3deb
@ -107,6 +107,7 @@ formatted as line-delimited JSON.
|
|||||||
| `pwm <0/1> pid` | Let output current to be controlled by the PID |
|
| `pwm <0/1> pid` | Let output current to be controlled by the PID |
|
||||||
| `center <0/1> <volt>` | Set the MAX1968 0A-centerpoint to the specified fixed voltage |
|
| `center <0/1> <volt>` | Set the MAX1968 0A-centerpoint to the specified fixed voltage |
|
||||||
| `center <0/1> vref` | Set the MAX1968 0A-centerpoint to measure from VREF |
|
| `center <0/1> vref` | Set the MAX1968 0A-centerpoint to measure from VREF |
|
||||||
|
| `center <0/1> vref_calib` | Set the MAX1968 0A-centerpoint to a stable calibrated VREF |
|
||||||
| `pid` | Show PID configuration |
|
| `pid` | Show PID configuration |
|
||||||
| `pid <0/1> target <deg_celsius>` | Set the PID controller target temperature |
|
| `pid <0/1> target <deg_celsius>` | Set the PID controller target temperature |
|
||||||
| `pid <0/1> kp <value>` | Set proportional gain |
|
| `pid <0/1> kp <value>` | Set proportional gain |
|
||||||
|
@ -20,8 +20,8 @@ pub struct Channel<C: ChannelPins> {
|
|||||||
pub state: ChannelState,
|
pub state: ChannelState,
|
||||||
/// for `i_set`
|
/// for `i_set`
|
||||||
pub dac: ad5680::Dac<C::DacSpi, C::DacSync>,
|
pub dac: ad5680::Dac<C::DacSpi, C::DacSync>,
|
||||||
/// Measured vref of MAX driver chip
|
/// Calibrated vref of MAX driver chip
|
||||||
pub vref_meas: ElectricPotential,
|
pub vref_calib: ElectricPotential,
|
||||||
pub shdn: C::Shdn,
|
pub shdn: C::Shdn,
|
||||||
pub vref_pin: C::VRefPin,
|
pub vref_pin: C::VRefPin,
|
||||||
pub itec_pin: C::ItecPin,
|
pub itec_pin: C::ItecPin,
|
||||||
@ -36,11 +36,11 @@ impl<C: ChannelPins> Channel<C> {
|
|||||||
let mut dac = ad5680::Dac::new(pins.dac_spi, pins.dac_sync);
|
let mut dac = ad5680::Dac::new(pins.dac_spi, pins.dac_sync);
|
||||||
let _ = dac.set(0);
|
let _ = dac.set(0);
|
||||||
// sensible dummy preset taken from datasheet. calibrate_dac_value() should be used to override this value.
|
// sensible dummy preset taken from datasheet. calibrate_dac_value() should be used to override this value.
|
||||||
let vref_meas = ElectricPotential::new::<volt>(1.5);
|
let vref_calib = ElectricPotential::new::<volt>(1.5);
|
||||||
|
|
||||||
Channel {
|
Channel {
|
||||||
state,
|
state,
|
||||||
dac, vref_meas,
|
dac, vref_calib,
|
||||||
shdn: pins.shdn,
|
shdn: pins.shdn,
|
||||||
vref_pin: pins.vref_pin,
|
vref_pin: pins.vref_pin,
|
||||||
itec_pin: pins.itec_pin,
|
itec_pin: pins.itec_pin,
|
||||||
|
@ -45,7 +45,7 @@ impl ChannelState {
|
|||||||
adc_time: Instant::from_secs(0),
|
adc_time: Instant::from_secs(0),
|
||||||
// default: 10 Hz
|
// default: 10 Hz
|
||||||
adc_interval: Duration::from_millis(100),
|
adc_interval: Duration::from_millis(100),
|
||||||
center: CenterPoint::Vref,
|
center: CenterPoint::VrefCalib,
|
||||||
dac_value: ElectricPotential::new::<volt>(0.0),
|
dac_value: ElectricPotential::new::<volt>(0.0),
|
||||||
i_set: ElectricCurrent::new::<ampere>(0.0),
|
i_set: ElectricCurrent::new::<ampere>(0.0),
|
||||||
pid_engaged: false,
|
pid_engaged: false,
|
||||||
|
@ -101,6 +101,13 @@ impl<'a> Channels<'a> {
|
|||||||
match self.channel_state(channel).center {
|
match self.channel_state(channel).center {
|
||||||
CenterPoint::Vref =>
|
CenterPoint::Vref =>
|
||||||
self.read_vref(channel),
|
self.read_vref(channel),
|
||||||
|
CenterPoint::VrefCalib => {
|
||||||
|
match channel {
|
||||||
|
0 => self.channel0.vref_calib,
|
||||||
|
1 => self.channel1.vref_calib,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
},
|
||||||
CenterPoint::Override(center_point) =>
|
CenterPoint::Override(center_point) =>
|
||||||
ElectricPotential::new::<volt>(center_point.into()),
|
ElectricPotential::new::<volt>(center_point.into()),
|
||||||
}
|
}
|
||||||
@ -293,8 +300,8 @@ impl<'a> Channels<'a> {
|
|||||||
|
|
||||||
let vref = (value as f64 / ad5680::MAX_VALUE as f64) * ElectricPotential::new::<volt>(DAC_OUT_V_MAX);
|
let vref = (value as f64 / ad5680::MAX_VALUE as f64) * ElectricPotential::new::<volt>(DAC_OUT_V_MAX);
|
||||||
match channel {
|
match channel {
|
||||||
0 => self.channel0.vref_meas = vref,
|
0 => self.channel0.vref_calib = vref,
|
||||||
1 => self.channel1.vref_meas = vref,
|
1 => self.channel1.vref_calib = vref,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -560,6 +567,8 @@ impl Serialize for CenterPointJson {
|
|||||||
match self.0 {
|
match self.0 {
|
||||||
CenterPoint::Vref =>
|
CenterPoint::Vref =>
|
||||||
serializer.serialize_str("vref"),
|
serializer.serialize_str("vref"),
|
||||||
|
CenterPoint::VrefCalib =>
|
||||||
|
serializer.serialize_str("vref_calib"),
|
||||||
CenterPoint::Override(vref) =>
|
CenterPoint::Override(vref) =>
|
||||||
serializer.serialize_f32(vref),
|
serializer.serialize_f32(vref),
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,7 @@ pub enum PwmPin {
|
|||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum CenterPoint {
|
pub enum CenterPoint {
|
||||||
Vref,
|
Vref,
|
||||||
|
VrefCalib,
|
||||||
Override(f32),
|
Override(f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,6 +358,7 @@ fn center_point(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
|
|||||||
let (input, _) = whitespace(input)?;
|
let (input, _) = whitespace(input)?;
|
||||||
let (input, center) = alt((
|
let (input, center) = alt((
|
||||||
value(Ok(CenterPoint::Vref), tag("vref")),
|
value(Ok(CenterPoint::Vref), tag("vref")),
|
||||||
|
value(Ok(CenterPoint::VrefCalib), tag("vref_calib")),
|
||||||
|input| {
|
|input| {
|
||||||
let (input, value) = float(input)?;
|
let (input, value) = float(input)?;
|
||||||
Ok((input, value.map(|value| CenterPoint::Override(value as f32))))
|
Ok((input, value.map(|value| CenterPoint::Override(value as f32))))
|
||||||
|
Loading…
Reference in New Issue
Block a user