Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions Core/Src/u_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,48 @@ static volatile uint16_t _mux_buffer[MUX_SIZE] = { 0 };

/* Manage muxs and updates the mux buffer. */
typedef enum { HIGH, LOW } _mux_state_t;
static _mux_state_t mux_state_debug = LOW;
int adc_switchMuxState(void) {
static _mux_state_t mux_state = LOW;

if(mux_state == LOW) {
/* Mux is currently LOW, so update LOW values. */
_mux_buffer[SEL1_LOW] = _adc1_buffer[ADC1_CHANNEL0];
_mux_buffer[SEL2_LOW] = _adc1_buffer[ADC1_CHANNEL15];
_mux_buffer[SEL3_LOW] = _adc1_buffer[ADC1_CHANNEL5];
_mux_buffer[SEL4_LOW] = _adc1_buffer[ADC1_CHANNEL9];

/* Mux is currently LOW, so switch to HIGH. */
HAL_GPIO_WritePin(MUX_SEL1_GPIO_Port, MUX_SEL1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(MUX_SEL2_GPIO_Port, MUX_SEL2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(MUX_SEL3_GPIO_Port, MUX_SEL3_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(MUX_SEL4_GPIO_Port, MUX_SEL4_Pin, GPIO_PIN_SET);

tx_thread_sleep(1); // Sleep for 1 tick so the mux settles.
tx_thread_sleep(10); // Sleep for 10 ticks so the mux settles.
mux_state = HIGH; // Update the mux state

/* We are now in the HIGH state, so set the associated indexes in the buffer. */
PRINTLN_INFO("Switched mux_state to HIGH.");
}
else if(mux_state == HIGH) {

/* Mux is currently HIGH, so update HIGH values. */
_mux_buffer[SEL1_HIGH] = _adc1_buffer[ADC1_CHANNEL0];
_mux_buffer[SEL2_HIGH] = _adc1_buffer[ADC1_CHANNEL15];
_mux_buffer[SEL3_HIGH] = _adc1_buffer[ADC1_CHANNEL5];
_mux_buffer[SEL4_HIGH] = _adc1_buffer[ADC1_CHANNEL9];

PRINTLN_INFO("Switched mux_state to HIGH.");
}
else if(mux_state == HIGH) {
/* Mux is currently HIGH, so switch to LOW. */
HAL_GPIO_WritePin(MUX_SEL1_GPIO_Port, MUX_SEL1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(MUX_SEL2_GPIO_Port, MUX_SEL2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(MUX_SEL3_GPIO_Port, MUX_SEL3_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(MUX_SEL4_GPIO_Port, MUX_SEL4_Pin, GPIO_PIN_RESET);

tx_thread_sleep(1); // Sleep for 1 tick so the mux settles.
tx_thread_sleep(10); // Sleep for 10 ticks so the mux settles.
mux_state = LOW; // Update the mux state

/* We are now in the LOW state, so set the associated indexes in the buffer. */
_mux_buffer[SEL1_LOW] = _adc1_buffer[ADC1_CHANNEL0];
_mux_buffer[SEL2_LOW] = _adc1_buffer[ADC1_CHANNEL15];
_mux_buffer[SEL3_LOW] = _adc1_buffer[ADC1_CHANNEL5];
_mux_buffer[SEL4_LOW] = _adc1_buffer[ADC1_CHANNEL9];

PRINTLN_INFO("Switched mux_state to LOW.");
}
serial_monitor("lv_efuse", "mux_state (0=HIGH, 1=LOW)", "%d", mux_state);
mux_state_debug = mux_state;

PRINTLN_INFO("Ran adc_switchMuxState()");

Expand Down Expand Up @@ -145,6 +147,10 @@ raw_efuse_adc_t adc_getEFuseData(void) {
efuses.data[EFUSE_BATTBOX] = _mux_buffer[SEL1_LOW];
efuses.data[EFUSE_MC] = _adc1_buffer[ADC1_CHANNEL18];

serial_monitor("brake_efuse", "mux_state_debug (0=HIGH, 1=LOW)", "%d", mux_state_debug);
serial_monitor("brake_efuse", "_adc1_buffer[ADC1_CHANNEL0]=", "%d", _adc1_buffer[ADC1_CHANNEL0]);
serial_monitor("brake_efuse", "_mux_buffer[SEL1_HIGH]", "%d", _mux_buffer[SEL1_HIGH]);

return efuses;
}

Expand Down
31 changes: 18 additions & 13 deletions Core/Src/u_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void vTest(ULONG thread_input) {
PRINTLN_ERROR("Failed to call ethernet1_init() (Status: %d/%s).", status, nx_status_toString(status));
}

efuse_enable(EFUSE_DASHBOARD);
efuse_disable(EFUSE_BRAKE);
efuse_disable(EFUSE_DASHBOARD);
efuse_enable(EFUSE_BRAKE);
efuse_disable(EFUSE_SHUTDOWN);
efuse_disable(EFUSE_LV);
efuse_disable(EFUSE_RADFAN);
Expand Down Expand Up @@ -451,7 +451,7 @@ static thread_t efuses_thread = {
.threshold = 0, /* Preemption Threshold */
.time_slice = TX_NO_TIME_SLICE, /* Time Slice */
.auto_start = TX_AUTO_START, /* Auto Start */
.sleep = 500, /* Sleep (in ticks) */
.sleep = 100, /* Sleep (in ticks) */
.function = vEFuses /* Thread Function */
};
void vEFuses(ULONG thread_input) {
Expand Down Expand Up @@ -481,11 +481,11 @@ void vEFuses(ULONG thread_input) {
data.faulted[EFUSE_DASHBOARD],
data.enabled[EFUSE_DASHBOARD]
);
serial_monitor("dashboard_efuse", "raw", "%d", data.raw[EFUSE_DASHBOARD]);
serial_monitor("dashboard_efuse", "voltage", "%f", data.voltage[EFUSE_DASHBOARD]);
serial_monitor("dashboard_efuse", "current", "%f", data.current[EFUSE_DASHBOARD]);
serial_monitor("dashboard_efuse", "faulted?", "%d", data.faulted[EFUSE_DASHBOARD]);
serial_monitor("dashboard_efuse", "enabled?", "%d", data.enabled[EFUSE_DASHBOARD]);
// serial_monitor("dashboard_efuse", "raw", "%d", data.raw[EFUSE_DASHBOARD]);
// serial_monitor("dashboard_efuse", "voltage", "%f", data.voltage[EFUSE_DASHBOARD]);
// serial_monitor("dashboard_efuse", "current", "%f", data.current[EFUSE_DASHBOARD]);
// serial_monitor("dashboard_efuse", "faulted?", "%d", data.faulted[EFUSE_DASHBOARD]);
// serial_monitor("dashboard_efuse", "enabled?", "%d", data.enabled[EFUSE_DASHBOARD]);


/* Send brake eFuse message. */
Expand All @@ -496,11 +496,11 @@ void vEFuses(ULONG thread_input) {
data.faulted[EFUSE_BRAKE],
data.enabled[EFUSE_BRAKE]
);
// serial_monitor("brake_efuse", "raw", "%d", data.raw[EFUSE_BRAKE]);
// serial_monitor("brake_efuse", "voltage", "%f", data.voltage[EFUSE_BRAKE]);
// serial_monitor("brake_efuse", "current", "%f", data.current[EFUSE_BRAKE]);
// serial_monitor("brake_efuse", "faulted?", "%d", data.faulted[EFUSE_BRAKE]);
// serial_monitor("brake_efuse", "enabled?", "%d", data.enabled[EFUSE_BRAKE]);
serial_monitor("brake_efuse", "raw", "%d", data.raw[EFUSE_BRAKE]);
serial_monitor("brake_efuse", "voltage", "%f", data.voltage[EFUSE_BRAKE]);
serial_monitor("brake_efuse", "current", "%f", data.current[EFUSE_BRAKE]);
serial_monitor("brake_efuse", "faulted?", "%d", data.faulted[EFUSE_BRAKE]);
serial_monitor("brake_efuse", "enabled?", "%d", data.enabled[EFUSE_BRAKE]);

/* Send shutdown eFuse message. */
send_shutdown_efuse(
Expand Down Expand Up @@ -562,6 +562,11 @@ void vEFuses(ULONG thread_input) {
data.faulted[EFUSE_PUMP1],
data.enabled[EFUSE_PUMP1]
);
// serial_monitor("pumpone_efuse", "raw", "%d", data.raw[EFUSE_PUMP1]);
// serial_monitor("pumpone_efuse", "voltage", "%f", data.voltage[EFUSE_PUMP1]);
// serial_monitor("pumpone_efuse", "current", "%f", data.current[EFUSE_PUMP1]);
// serial_monitor("pumpone_efuse", "faulted?", "%d", data.faulted[EFUSE_PUMP1]);
// serial_monitor("pumpone_efuse", "enabled?", "%d", data.enabled[EFUSE_PUMP1]);

/* Send pump2 eFuse message. */
send_pumptwo_efuse(
Expand Down