succd: eke out a few extra bits of precision by oversampling ADC
This commit is contained in:
parent
05d102ab9b
commit
9e02f07b90
|
@ -22,7 +22,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func formatVolts(v float32) string {
|
func formatVolts(v float32) string {
|
||||||
return fmt.Sprintf("%.3f V", v)
|
return fmt.Sprintf("%.4f V", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// formatMbar formats a millibar value using scientific notation and returns a
|
// formatMbar formats a millibar value using scientific notation and returns a
|
||||||
|
|
|
@ -23,8 +23,9 @@ type daemon struct {
|
||||||
|
|
||||||
// mu guards state variables below.
|
// mu guards state variables below.
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
// adcPiraniVolts is the last readout of adcPirani.
|
// adcPiraniVolts is a moving window of read ADC values, used to calculate a
|
||||||
adcPiraniVolts float32
|
// moving average.
|
||||||
|
adcPiraniVolts []float32
|
||||||
}
|
}
|
||||||
|
|
||||||
// process runs the pain acquisition and control loop of succd.
|
// process runs the pain acquisition and control loop of succd.
|
||||||
|
@ -55,7 +56,11 @@ func (d *daemon) processOnce(_ context.Context) error {
|
||||||
return fmt.Errorf("when reading ADC: %w", err)
|
return fmt.Errorf("when reading ADC: %w", err)
|
||||||
}
|
}
|
||||||
d.mu.Lock()
|
d.mu.Lock()
|
||||||
d.adcPiraniVolts = v
|
d.adcPiraniVolts = append(d.adcPiraniVolts, v)
|
||||||
|
trim := len(d.adcPiraniVolts) - 100
|
||||||
|
if trim > 0 {
|
||||||
|
d.adcPiraniVolts = d.adcPiraniVolts[trim:]
|
||||||
|
}
|
||||||
d.mu.Unlock()
|
d.mu.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -64,7 +69,13 @@ func (d *daemon) processOnce(_ context.Context) error {
|
||||||
// pirani returns the Pirani gauge voltage and pressure.
|
// pirani returns the Pirani gauge voltage and pressure.
|
||||||
func (d *daemon) pirani() (volts float32, mbar float32) {
|
func (d *daemon) pirani() (volts float32, mbar float32) {
|
||||||
d.mu.RLock()
|
d.mu.RLock()
|
||||||
volts = d.adcPiraniVolts
|
volts = 0.0
|
||||||
|
for _, v := range d.adcPiraniVolts {
|
||||||
|
volts += v
|
||||||
|
}
|
||||||
|
if len(d.adcPiraniVolts) != 0 {
|
||||||
|
volts /= float32(len(d.adcPiraniVolts))
|
||||||
|
}
|
||||||
d.mu.RUnlock()
|
d.mu.RUnlock()
|
||||||
|
|
||||||
// Per Pirani probe docs.
|
// Per Pirani probe docs.
|
||||||
|
|
Loading…
Reference in a new issue