Skip to content

Sensors I/O

The sensors layer ties the physical inputs to the board's runtime objects. It is where the CAN-Gateway decides which sensors exist on a given variant, how they are initialized, and which periodic or interrupt-driven hooks keep them updated.

The core implementation is found in repos/CAN-Gateway/Core/Src/App/SensorsIO/sensors.c with header definitions in repos/CAN-Gateway/Core/Inc/App/SensorsIO/sensors.h.


Compile-Time Board Variants

The same codebase compiles for both the front and rear physical PCB instances. The active variant is configured in repos/CAN-Gateway/Core/Inc/App/system_var.h by setting the DEVICE_TYPE preprocessor macro:

c
#define DEVICE_FRONT_GATEWAY 1
#define DEVICE_REAR_GATEWAY  2
#define DEVICE_TYPE DEVICE_FRONT_GATEWAY  // Change here to toggle compiled variant

Variant compilation alters sensor initialization lists and updates how signals map to the FDCAN structures.


Sensor Mapping Matrix

The board supports a wide range of analog and digital inputs, routed based on the compile-time configuration:

Sensor NameFront Gateway VariantRear Gateway VariantDriver Class / HeaderInput Hardware Peripheral
Wheel SpeedFront Right & Front LeftRear Right & Rear LeftMX5051TIM4 period update / TIM2 input capture
Suspension TravelFront Right & Front LeftRear Right & Rear LeftKPM12JADC1 (DMA conversion)
APPSAPPS 1 & APPS 2N/AAPPSADC2 (DMA conversion)
Steering AngleSteering displacementN/AsteeringADC2 (DMA conversion)
Brake PressureN/ABrake line sensorPU8702ADC2 (DMA conversion)
Current SensorN/AJB Current (50A & 200A)DHAB_S134ADC2 (DMA conversion)
Coolant TempN/ATemp 1 & Temp 2GE1935ADC2 (DMA) & ADC1 (DMA)
Coolant FlowN/AFlow rate sensordebit_2061EXTI Interrupt (GPIO pulse counter)
Digital InputsReady-To-Drive (R2D) buttonShutdown Circuit (SDC)debouncerGPIO Digital Input

NMOS Output Control & Hysteresis

The board manages high-side/low-side switching via on-board NMOS transistors (repos/CAN-Gateway/Core/Src/App/SensorsIO/nmos_vars.c):

  • Front Gateway Variant: Controls the R2D button LED (NMOS1_Pin) blinking period configured via CAN command.
  • Rear Gateway Variant:
    • Brake LED Output (NMOS1_Pin): Automatically driven based on PU8702 brake pressure with hysteresis to prevent output chatter:
      • Turn ON Threshold: Brake pressure 2.3 bar
      • Turn OFF Threshold: Brake pressure 1.7 bar
      • Hysteresis Band (1.7 bar<P<2.3 bar): Retains the previous output state.
    • R2D Buzzer Output (NMOS2_Pin): Controlled directly by incoming CAN message state.

Sensor Calibration & NVM Storage

Critical analog sensors require on-the-fly range calibration (such as APPS and steering sensors). The calibration sequences automatically register raw min/max voltages and save them to internal flash using the nimaltd/ee EEPROM Emulation Library.

For deep-dives into NVM configuration and calibration drivers, see:

Released under the MIT License.