added firmware section

This commit is contained in:
cpu
2026-05-18 21:55:20 +02:00
parent 6e62cb7b57
commit 68cb57af28
16 changed files with 22474 additions and 21132 deletions

View File

@@ -17,7 +17,7 @@ Designed in **KiCad v9**.
3. [Panel Design and GCode](#panel-design-and-gcode)
4. [Microcontroller Pin Mapping](#microcontroller-pin-mapping)
5. [Firmware Logic](#firmware-logic)
6. [Development & Programming](#development--programming)
6. [Firmware Build & Flashing](#firmware-build--flashing)
## Features
* **Microcontroller:** WCH CH32V003J4M6 (RISC-V).
@@ -36,24 +36,28 @@ Designed in **KiCad v9**.
The [scripts](scripts) folder contains a guide to panelize the board (`Flow_Controller_Panel.kicad_pcb`) and howto generate gcode.
## Microcontroller Pin Mapping (Per Schematic)
| Pin | Schematic Net | Function |
| :--- | :--- | :--- |
| 1 | `FLOW_PULSE_MCU` | Input: Pulse counter from Flow Sensor (via RC Filter) |
| 2 | `GND` | System Ground (VSS) |
| 3 | `ALARM_TRIGGER` | Output: Drives the Gate of the 2N7002 MOSFET |
| 4 | `+5V` | System Power (VDD) |
| 5 | `I2C_SDA` | I2C Data (OLED Display) |
| 6 | `I2C_SCL` | I2C Clock (OLED Display) |
| 7 | `BUTTON_ADC` | ADC Input: 2-Button Resistor Ladder |
| 8 | `SWIO` | WCH-LinkE Programming Interface |
| Pin | Schematic Net | Function | MCU Port (SOP8) |
| :--- | :--- | :--- | :--- |
| 1 | `FLOW_PULSE_MCU` | Input: Pulse counter from Flow Sensor | PD6 |
| 2 | `GND` | System Ground (VSS) | VSS |
| 3 | `ALARM_TRIGGER` | Output: Drives the Gate of the 2N7002 | PA2 |
| 4 | `+5V` | System Power (VDD) | VDD |
| 5 | `I2C_SDA` | I2C Data (OLED Display) | PC1 |
| 6 | `I2C_SCL` | I2C Clock (OLED Display) | PC2 |
| 7 | `BUTTON_ADC` | ADC Input: 2-Button Resistor Ladder | PC4 |
| 8 | `SWIO` | WCH-LinkE Programming Interface | PD1 |
## Firmware Logic (Overview)
1. **Interrupts:** Pin 1 counts falling edges from the flow sensor. Flow (L/min) is calculated every second.
1. **Interrupts:** Pin 1 (PD6) counts falling edges from the flow sensor. Flow (L/min) is calculated every second.
2. **Failsafe:** If `Current_Flow >= Threshold`, Pin 3 is driven **HIGH** (MOSFET ON, CNC OK). If `Current_Flow < Threshold`, Pin 3 is driven **LOW** (MOSFET OFF, CNC Alarm).
3. **UI:** ADC reads Pin 7 to detect button presses for adjusting the threshold.
3. **UI:** ADC reads Pin 7 (PC4) to detect button presses for adjusting the threshold.
4. **Storage:** User-defined threshold is saved to MCU flash memory.
## Development & Programming
To flash the CH32V003, you will need a **WCH-LinkE** programmer connected to the 3-pin SWIO header `J1` (+5V, SWIO, GND).
## Firmware Build & Flashing
The firmware is written in C using the lightweight `ch32fun` framework. All source files and toolchain documentation are located in the `firmware` folder.
**Step-by-step Setup:**
1. Follow the setup guide in [`firmware/Readme.md`](firmware/Readme.md) to install the RISC-V GCC toolchain and `minichlink`.
2. Connect your **WCH-LinkE** programmer to the 3-pin SWIO header `J1` (+5V, SWIO, GND).
3. Run `make` to compile the firmware.
4. Run `make flash` to upload the code to the CH32V003 microcontroller.