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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@
}
}
]
}
}
14 changes: 7 additions & 7 deletions can_library/configs/nodes/PDU.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"unit": "mV"
}
],
"msg_period": 500,
"msg_period": 100,
"msg_priority": 4
},
{
Expand All @@ -52,7 +52,7 @@
"unit": "mA"
}
],
"msg_period": 500,
"msg_period": 100,
"msg_priority": 4
},
{
Expand Down Expand Up @@ -82,7 +82,7 @@
"length": 12
}
],
"msg_period": 500,
"msg_period": 100,
"msg_priority": 4
},
{
Expand All @@ -102,7 +102,7 @@
"length": 12
}
],
"msg_period": 500,
"msg_period": 100,
"msg_priority": 4
},
{
Expand Down Expand Up @@ -140,7 +140,7 @@
"length": 12
}
],
"msg_period": 500,
"msg_period": 100,
"msg_priority": 4
},
{
Expand Down Expand Up @@ -197,7 +197,7 @@
"unit": "LPM"
}
],
"msg_period": 200,
"msg_period": 100,
"msg_priority": 5
},
{
Expand All @@ -211,7 +211,7 @@
"unit": "C"
}
],
"msg_period": 500,
"msg_period": 100,
"msg_priority": 5
},
{
Expand Down
2 changes: 1 addition & 1 deletion source/pdu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ add_firmware_component(
NAME pdu
LINKER_SCRIPT "STM32F407VGTx_FLASH"
LIBS "can_node_PDU;CMSIS_F407;PHAL_F407;FREERTOS_F407;BANGBANG;HEARTBEAT;WATCHDOG"
)
)
87 changes: 85 additions & 2 deletions source/pdu/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,85 @@
## PDU
PDU is responsible for controlling and monitoring critical power rails and cooling loops.
# PDU Firmware

PDU controls and monitors low-voltage power rails and cooling hardware for the car.

## Responsibilities

- Control switchable rails (GPIO outputs).
- Sample ADC channels for rail voltage/current telemetry.
- Scan rail nFAULT lines and report/latch faults.
- Control fan/pump/hxfan outputs and fan PWM duty cycles.
- Publish PDU telemetry and coolant output status over CAN.

## Module Layout

- `main.c`
- Board init, peripheral init, task definitions, task startup order.
- No business logic beyond orchestration.

- `state.h/.c`
- Shared runtime state (`g_pdu_state`) for all PDU logic.

- `switches.h/.c`
- Switch command/read API.
- ADC and mux measurement pipeline.
- Rail current/voltage conversions.
- Default-rail enable sequence.

- `faults.h/.c`
- Table-driven nFAULT polling.
- One-fault-slot-per-cycle update cadence.
- Rail fault LED behavior.

- `cooling.h/.c`
- Cooling policy computation.
- Cooling actuation (switches + fan PWM).
- Cooling CAN output publication.

- `cooling_bangbang.h/.c`
- Optional bang-bang policy backend.
- Compiled in but disabled by default.

- `telemetry.h/.c`
- Power/thermal telemetry CAN publication.
- Flowrate telemetry CAN publication.

- Hardware adapter modules (kept separate):
- `led/`
- `fan_control/`
- `flow_rate/`

## Runtime State (`g_pdu_state`)

The shared state contains:

- `rail_voltage_mv` for 24V/5V/3V3 measurements.
- `switch_current_ma[]` for sensed currents (switch and rail channels).
- `mux_adc_counts[]` and `next_mux_channel` for mux-sampled inputs.
- `next_rail_fault_index` for staggered rail fault scanning.
- `cooling_command` for requested/applied cooling outputs.

## Task Model

Defined in `main.c`:

- `CAN_rx_update` (0 ms)
- `CAN_tx_update` (5 ms)
- `switches_periodic` (15 ms)
- `cooling_periodic` (100 ms)
- `faults_periodic` (100 ms)
- `fault_library_periodic` (100 ms)
- `telemetry_flow_periodic` (200 ms)
- `LED_periodic` (500 ms)
- `telemetry_power_periodic` (500 ms)
- Heartbeat task (LED sweep callback)

## Cooling Backend: Bang-Bang (Disabled by Default)

The bang-bang backend is present for future policy work, but disabled to preserve current behavior.

- Toggle: `COOLING_ENABLE_BANGBANG` in `cooling_bangbang.h`
- `0` (default): backend is a no-op.
- `1`: motor temp based bang-bang updates are applied.

Current non-bangbang behavior remains the active policy path.

Loading
Loading