From fb66c03ac7f5e1bbbcb65237e861a283e615b4e3 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Tue, 15 Dec 2020 14:58:39 -0800 Subject: [PATCH] api to get pump duty --- firmware/pump_dac.cpp | 5 +++++ firmware/pump_dac.h | 1 + firmware/pwm.cpp | 7 +++++++ firmware/pwm.h | 2 ++ 4 files changed, 15 insertions(+) diff --git a/firmware/pump_dac.cpp b/firmware/pump_dac.cpp index 8a820db..43bc03e 100644 --- a/firmware/pump_dac.cpp +++ b/firmware/pump_dac.cpp @@ -36,3 +36,8 @@ void SetPumpCurrentTarget(int32_t microampere) pumpDac.SetDuty(volts / VCC_VOLTS); } + +uint16_t GetPumpOutputDuty() +{ + return pumpDac.GetLastDuty(); +} diff --git a/firmware/pump_dac.h b/firmware/pump_dac.h index c5123d7..1d3be24 100644 --- a/firmware/pump_dac.h +++ b/firmware/pump_dac.h @@ -4,3 +4,4 @@ void InitPumpDac(); void SetPumpCurrentTarget(int32_t microamperes); +uint16_t GetPumpOutputDuty(); diff --git a/firmware/pwm.cpp b/firmware/pwm.cpp index 13e2a65..e61300b 100644 --- a/firmware/pwm.cpp +++ b/firmware/pwm.cpp @@ -45,5 +45,12 @@ float clampF(float min, float clamp, float max) { void Pwm::SetDuty(float duty) { pwmcnt_t highTime = m_counterPeriod * clampF(0, duty, 1); + m_lastDuty = highTime; + pwm_lld_enable_channel(m_driver, m_channel, highTime); } + +uint16_t Pwm::GetLastDuty() const +{ + return m_lastDuty; +} diff --git a/firmware/pwm.h b/firmware/pwm.h index adbd9b9..7a910d3 100644 --- a/firmware/pwm.h +++ b/firmware/pwm.h @@ -11,9 +11,11 @@ public: void Start(); void SetDuty(float duty); + uint16_t GetLastDuty() const; private: PWMDriver* const m_driver; const uint8_t m_channel; const uint32_t m_counterFrequency; const uint16_t m_counterPeriod; + uint16_t m_lastDuty; };