wideband/firmware/pump_dac.cpp

30 lines
565 B
C++
Raw Normal View History

2020-10-27 16:33:32 -07:00
#include "pump_dac.h"
#include "pwm.h"
#include "hal.h"
// 48MHz / 1024 = 46.8khz PWM
static Pwm pumpDac(PWMD3, 0, 48'000'000, 1024);
void InitPumpDac()
{
pumpDac.Start();
// Set zero current to start - sensor can be damaged if current flowing
// while warming up
SetPumpCurrentTarget(0);
}
void SetPumpCurrentTarget(int32_t microampere)
{
// 47 ohm resistor
// 0.147 gain
// effective resistance of 317 ohms
2020-10-29 02:53:45 -07:00
float volts = 0.000321162f * microampere;
2020-10-27 16:33:32 -07:00
// offset by
volts += 1.65f;
pumpDac.SetDuty(volts / 3.3f);
}