VCC undervoltage check module
parent
260c933c36
commit
ba86dbd806
|
|
@ -42,6 +42,14 @@ static constexpr const uint16_t buttonADCLimits[buttonCount][2] = { { 0, 50 }, {
|
||||||
static constexpr const uint16_t buttonADCMaxValue = 1023; ///< used in unit tests
|
static constexpr const uint16_t buttonADCMaxValue = 1023; ///< used in unit tests
|
||||||
static constexpr const uint8_t buttonsADCIndex = 5; ///< ADC index of buttons input
|
static constexpr const uint8_t buttonsADCIndex = 5; ///< ADC index of buttons input
|
||||||
|
|
||||||
|
// VCC measurement setup
|
||||||
|
static constexpr const uint8_t VCCADCIndex = 30; ///< ADC index of scaled VCC input
|
||||||
|
static constexpr const uint16_t VCCADCThreshold = 274; ///< ADC value for triggering the UV_VCC error
|
||||||
|
/// We are measuring the bandgap voltage, Vb=1.1V.
|
||||||
|
/// To compute the threshold value: `VAL = 1125.3 / AVCC`
|
||||||
|
/// So for AVCC=4.1V, you get VAL=274.46
|
||||||
|
static constexpr const uint8_t VCCADCReadCnt = 10; ///< Number of ADC reads to perform, only the last one being used
|
||||||
|
|
||||||
// Motion and planning
|
// Motion and planning
|
||||||
|
|
||||||
/// Do not plan moves equal or shorter than the requested steps
|
/// Do not plan moves equal or shorter than the requested steps
|
||||||
|
|
|
||||||
|
|
@ -118,4 +118,6 @@ enum class ErrorCode : uint_fast16_t {
|
||||||
/// Unfixable possible cause: bad or cracked solder joints on the PCB, failed shift register, failed driver.
|
/// Unfixable possible cause: bad or cracked solder joints on the PCB, failed shift register, failed driver.
|
||||||
MMU_SOLDERING_NEEDS_ATTENTION = 0xC200,
|
MMU_SOLDERING_NEEDS_ATTENTION = 0xC200,
|
||||||
|
|
||||||
|
/// MCU VCC rail undervoltage.
|
||||||
|
MCU_UNDERVOLTAGE_VCC = 0xC400,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "modules/timebase.h"
|
#include "modules/timebase.h"
|
||||||
#include "modules/motion.h"
|
#include "modules/motion.h"
|
||||||
#include "modules/usb_cdc.h"
|
#include "modules/usb_cdc.h"
|
||||||
|
#include "modules/undervoltage_check.h"
|
||||||
|
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
|
||||||
|
|
@ -167,6 +168,7 @@ void loop() {
|
||||||
}
|
}
|
||||||
hal::cpu::Step();
|
hal::cpu::Step();
|
||||||
mu::cdc.Step();
|
mu::cdc.Step();
|
||||||
|
muv::uv_vcc.Step();
|
||||||
|
|
||||||
application.Step();
|
application.Step();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ target_sources(
|
||||||
serial.cpp
|
serial.cpp
|
||||||
speed_table.cpp
|
speed_table.cpp
|
||||||
timebase.cpp
|
timebase.cpp
|
||||||
|
undervoltage_check.cpp
|
||||||
usb_cdc.cpp
|
usb_cdc.cpp
|
||||||
user_input.cpp
|
user_input.cpp
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
/// @file undervoltage_check.cpp
|
||||||
|
#include "undervoltage_check.h"
|
||||||
|
#include "../hal/adc.h"
|
||||||
|
#include "../logic/error_codes.h"
|
||||||
|
#include "../panic.h"
|
||||||
|
|
||||||
|
namespace modules {
|
||||||
|
namespace undervoltage_check {
|
||||||
|
|
||||||
|
Undervoltage_check uv_vcc;
|
||||||
|
|
||||||
|
void Undervoltage_check::Step() {
|
||||||
|
uint16_t vcc_val;
|
||||||
|
|
||||||
|
// dummy reads are so that the final measurement is valid
|
||||||
|
for (uint8_t i = 0; i < config::VCCADCReadCnt; i++) {
|
||||||
|
vcc_val = hal::adc::ReadADC(config::VCCADCIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vcc_val > config::VCCADCThreshold) {
|
||||||
|
Panic(ErrorCode::MCU_UNDERVOLTAGE_VCC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace undervoltage_check
|
||||||
|
} // namespace modules
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
/// @file undervoltage_check.h
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "../config/config.h"
|
||||||
|
|
||||||
|
/// The modules namespace contains models of MMU's components
|
||||||
|
namespace modules {
|
||||||
|
namespace undervoltage_check {
|
||||||
|
|
||||||
|
class Undervoltage_check {
|
||||||
|
public:
|
||||||
|
inline constexpr Undervoltage_check() = default;
|
||||||
|
|
||||||
|
/// Reads the ADC, checks the value
|
||||||
|
void Step();
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The one and only instance of Undervoltage_check in the FW
|
||||||
|
extern Undervoltage_check uv_vcc;
|
||||||
|
|
||||||
|
} // namespace undervoltage_check
|
||||||
|
} // namespace modules
|
||||||
|
|
||||||
|
namespace muv = modules::undervoltage_check;
|
||||||
Loading…
Reference in New Issue