Firmware API Reference
This section documents the C firmware modules that make up the AddVantage PPG controller.
Core Modules
ProcessorExpert.c - Main Application
The main application loop and state machine for the PPG controller.
Main module. This module contains user’s application code.
- Version
01.01
Events.c - Calculation Engine
All fuel calculation functions including timing, pressure compensation, and map lookups.
This is user’s event module. Put your event handler code here.
- Version
01.00
Key Functions:
calculatePeriod()- Compute injector pulse width from fuel mapcalculateBaseTiming()- Determine base injection timingapplyDiffPressInt()- Apply differential pressure correctionapplyMapCorrection()- Apply manifold pressure correctionapplyTempCorrection()- Apply coolant temperature correctionupdatePPG()- Update pulse generator outputs
CAN Bus Interface
can.c - J1939 Protocol Handler
Parses J1939 CAN messages from the engine ECU.
Supported PGNs:
EEC1 (61444) - Engine RPM, Actual Torque
ET1 (65262) - Coolant Temperature
LFE (65266) - Fuel Economy (diesel rate)
ETC2 (61445) - Transmission data
Storage and I/O
flash.c - EEPROM Emulation
Flash memory driver for configuration persistence.
Functions
-
void flash_default(uint8_t Comms_Flag)
-
void flash_erase()
-
uint8_t flash_get(int Addr)
-
uint16_t flash_get_16(int Addr)
-
void flash_init()
-
void flash_put(int Addr, uint8_t Data)
-
void flash_put_16(int Addr, uint16_t Data)
-
void flash_read(LDD_TData *pData, LDD_FLASH_TDataSize Size)
-
void flash_wait()
-
void flash_write(LDD_TData *pData, LDD_FLASH_TDataSize Size)
-
bool flash_written()
-
void flash_set_data(int addr, uint8_t data)
-
void flash_commit()
Key Operations:
Read/write configuration parameters
Fuel map storage and retrieval
Temperature correction tables
serial_io.c - UART Interface
Serial communication for telemetry and configuration.
Functions
-
uint16_t elapsed_ms()
-
void print_Telemetry_Boot()
-
void print_Telemetry_old()
-
void print_Telemetry()
-
void print_debug_data(char **variable_names, long *debugdata, int num_variables)
-
void print_config_data(char **variable_names, int *addresses, int num_variables)
-
char get_char_no_wait()
-
void print(char *pStr)
-
void print_adc(uint8_t ADC_No, float Factor)
-
void print_chr(char Char)
-
void print_data()
-
void print_en(bool Var)
-
void print_en2(bool Var)
-
void print_flt(int16_t Value, uint8_t Places)
-
void print_headers()
-
void print_hex(uint8_t Value)
-
void print_int(int Value)
-
void print_word(uint16_t Value)
-
void reset_timer()
-
void print_reset_source(void)
-
void sleep(uint16_t mS)
-
bool wait_password()
Features:
Telemetry output (1Hz)
VT100 terminal display
Password-protected configuration menu
Hardware Control
solenoids.c - Actuator Control
Control of gas injectors and solenoid valves.
Functions
-
bool get_isolator()
-
void init_power()
-
void init_reducer()
-
void init_new_tr()
-
void injector_set(int Injector_No, int State)
-
void isolator_set(int State)
-
void power_set(int State)
-
void reducer_set(int State)
-
void init_ppg()
-
void ppg1_set_period_us(uint16_t ppg_period)
-
void ppg2_set_period_us(uint16_t ppg_period)
-
void ppg_set_period_us(uint16_t ppg_period)
-
void ppg1_set_duty_us(uint16_t ppg_duty)
-
void ppg2_set_duty_us(uint16_t ppg_duty)
-
void ppg_set_duty_us(uint16_t ppg_duty)
Outputs:
PPG1/PPG2 - Gas injector pulse generators
Tank solenoid - LPG tank shutoff
Reducer solenoid - Pressure reducer control
adc.c - Analog Input Processing
ADC driver for pressure and level sensing.
Functions
-
void init_adc()
-
void check_adc()
-
uint16_t get_adc_fsd(uint8_t ADC_No)
-
void measure_adc()
-
uint16_t read_adc(uint8_t ADC_No)
Channels:
Channel 0: Gas pressure sensor
Channel 1: Manifold pressure sensor
Channel 2: Tank level sensor
Header Files
flash.h - Flash Memory Constants
Flash address definitions and configuration constants.
Defines
-
FLASH_BASE
-
FLASH_SIZE
-
FLASH_CUTOFF_LSB
-
FLASH_CUTOFF_MSB
-
FLASH_COMMS_ADDR
-
FLASH_GAS_ADDR
-
FLASH_LAMBDA_ENABLE
-
FLASH_LAMBDA_AUTH
-
FLASH_LAMBDA_TIME
-
FLASH_LAMBDA_SOURCE
-
FLASH_AFR_TARGET
-
FLASH_AFR_1
-
FLASH_AFR_2
-
HALFDUTYTHRESH
-
OPERATIONMODEADDR
-
OFFSET_EEC_LSB
-
OFFSET_EEC_MSB
-
SOFTWARE_REV_MAJOR
-
DUTYMULTA
-
DUTYMULTB
-
DUTYMULTC
-
DUTYMULTD
-
DUTYMULTE
-
DUTYMULTF
-
DUTYMULTG
-
DUTYMULTH
-
DUTYMULTI
-
DUTYMULTJ
-
DUTYMULTK
-
DUTYMULTL
-
DUTYMULTM
-
DUTYMULTN
-
INJECTORDEADTIME
-
INJECTORBASEMULT
-
RPM_OFFSET
-
PROFILE_SELECT
-
TELEMETRY_PERSIST_START
-
TELEMETRY_PERSIST_END
-
TELEMETRY_PERSIST_SIZE
-
ENABLE_INTERRUPTS
-
DISABLE_INTERRUPTS
Generated Code
The Generated_Code/ directory contains ProcessorExpert-generated drivers.
These files should not be edited directly.
Key Generated Modules:
CAN1.c/h - MSCAN peripheral driver
AS1.c/h - Asynchronous serial (UART)
AD1.c/h - ADC peripheral driver
PPG1.c/h, PPG2.c/h - Pulse generators
FLASH1.c/h - Flash programming interface
WDog1.c/h - Watchdog timer