Changes to PWR firmware to support removing shunt circuit

This commit is contained in:
OneFinityCNC
2021-12-19 23:43:43 -05:00
parent dbc9b0a38b
commit 10df5ada62

View File

@@ -76,6 +76,7 @@ static volatile uint8_t motor_overload = 0;
static volatile float shunt_joules = 0; static volatile float shunt_joules = 0;
static volatile bool initialized = false; static volatile bool initialized = false;
static volatile float vnom = 0; static volatile float vnom = 0;
static volatile bool rev4 = false;
void delay(uint16_t ms) { void delay(uint16_t ms) {
@@ -162,6 +163,8 @@ static float get_reg(int reg) {
static void update_shunt() { static void update_shunt() {
if (!initialized) return; if (!initialized) return;
if(!rev4) return;
static float joules = SHUNT_JOULES; // Power disipation budget static float joules = SHUNT_JOULES; // Power disipation budget
// Add power dissipation credit for the 1ms that elapsed // Add power dissipation credit for the 1ms that elapsed
@@ -176,6 +179,8 @@ static void update_shunt() {
static void update_shunt_power() { static void update_shunt_power() {
if (!initialized) return; if (!initialized) return;
if(!rev4) return;
float vout = get_reg(VOUT_REG); float vout = get_reg(VOUT_REG);
if (vnom + SHUNT_MIN_V < vout) { if (vnom + SHUNT_MIN_V < vout) {
@@ -412,8 +417,15 @@ void init() {
IO_DDR_CLR(LOAD1_PIN); // Tri-state IO_DDR_CLR(LOAD1_PIN); // Tri-state
IO_DDR_CLR(LOAD2_PIN); // Tri-state IO_DDR_CLR(LOAD2_PIN); // Tri-state
IO_PUE_SET(PWR_RESET); // Pull up reset line IO_PUE_SET(PWR_RESET); // Pull up reset line
IO_PORT_CLR(SHUNT_PIN); // Enable shunt
IO_DDR_SET(SHUNT_PIN); // Output //Rev 4 PCBs have a pull-up on the shunt pin
rev4 = IO_PIN_GET(SHUNT_PIN);
if(rev4)
{
IO_PORT_CLR(SHUNT_PIN); // Enable shunt
IO_DDR_SET(SHUNT_PIN); // Output
}
IO_PORT_CLR(PC2_PIN); // Disable cap precharge circuit IO_PORT_CLR(PC2_PIN); // Disable cap precharge circuit
IO_DDR_SET(PC2_PIN); //Output IO_DDR_SET(PC2_PIN); //Output
@@ -484,7 +496,7 @@ int main() {
init(); init();
adc_conversion(); // Start ADC adc_conversion(); // Start ADC
validate_input_voltage(); validate_input_voltage();
shunt_test(); if(rev4) shunt_test();
charge_caps(); charge_caps();
validate_measurements(); validate_measurements();
initialized = true; initialized = true;