...
To support this, here’s a module breakdown of the project. Note that there are 2 solar boards, one of which has 5 MPPTs and one of which has 6, so firmware must support both.
Hardware schematic: https://university-of-waterloo-solar-car-team.365.altium.com/designs/589A49F1-9DE6-4FB1-B369-12387D122AA0#design
Modules
Generating data:
sense is a generic module that encapsulates the pattern of “periodically, read X and store the data, then tell the data store that we’re done.”
The
sense_register()
function takes a callback. All of the callbacks passed into this function will be periodically called (at a configurable interval), followed by a call todata_store_done()
.The callback passed to
sense_register()
should read voltage/current/temperature (and maybe PWM) data from hardware, then store it in the data store.
sense_current, sense_voltage, sense_temperature, and sense_mppt provide the callbacks passed to
sense_register()
. Each callssense_register()
in theirinit
function.sense_current reads the current output of the solar array through an MCP3427 ADC over I2C (via ACS722 current sense, though that shouldn’t be relevant for firmware).
sense_voltage reads the voltage from each of the MPPTs via 5-6 MCP3427s over I2C.
sense_temperature reads temperature data from GPIO pins PA0-4 (5 MPPTs) or PA0-5 (6 MPPTs) from thermistors.
sense_mppt communicates with the (presumably) SPV1020 MPPTs over SPI and reads their current and input voltage (and possibly PWM). It also reads the status register and raises fault events if an MPPT has an overcurrent/overvoltage/overtemperature bit set.
...
data_store provides an abstraction layer between reading the data and doing something with it. It stores all of the data collected by sense et al., then raises a “data ready” event. Consumers of the data (logger, fault_monitor, etc) can retrieve the data directly from data_store to avoid overloading the event queue. All data is stored as
uint16_t
.To store and retrieve data, we’ll likely we use a
SolarData
DataPoint
enum with one entry for each data entry point we need (e.g.SOLARDATA_DATAPOINT_VOLTAGE_1
,SOLARDATA_DATAPOINT_MPPT_CURRENT_3
, etc.).The
data_store_enter()
function (not sold on the name) takes aSolarData
DataPoint
parameter to identify which data point it is, as well as the data point as auint16_t
. It’ll overwrite that data point in the module’s storage.The
data_store_done()
function is called by sense when a batch of data is read. It raises a “data ready” event which is received by the consumers of the data.The
data_store_get()
function will take aSolarData
DataPoint
parameter and auint16_t*
and will set the pointer to the value of the data point.
...
solar_fsm keeps track of the state of the module. It transitions on fault events (and possibly commands from centre console, if those exist) and dispatches “action” events to interface with relay and calls the SPV1020 driver calls the DRV120 driver to open/close the relay and mppt to turn on/off the MPPTs. (This could be split off into multiple FSMs to handle specific fault sequences. Also, we could just call relay from solar_fsm instead of raising an action event if the relay logic is simple enough.)relay will handle opening and closing the relay when it receives an appropriate action event. It will interface with the DRV120 driver)
Other:
mppt is a thin wrapper over the spv1020_mppt driver which handles dealing with the demux to support addressing multiple SPV1020s. It should provide the same functions as spv1020_mppt, but with an extra argument specifying which MPPT the command should go to; it’ll then set the demux to address that MPPT, then call the corresponding spv1020_mppt function. It should use the existing generic
mux
driver.This isn’t a driver because the fact that our SPV1020s are behind a demux is an implementation detail of the board which isn’t appropriate for a generic driver to deal with. This module encapsulates the interaction between the MPPTs and the demux.
Drivers
mcp3427_adc - driver for the MCP3427 analog-digital converter. Reportedly already exists in the MSXII codebase (project
solar_slave
) and can be reused.spv1020_mppt - driver for the SPV1020 maximum power point tracker and DC-DC converter. Communicates over SPI with the SPV1020s and issues commands (a list can be found in the SPV1020 datasheet). Should provide a separate function for calling each command.
Datasheet: https://media.digikey.com/pdf/Data Sheets/ST Microelectronics PDFS/SPV1020.pdf, more info: https://media.digikey.com/PDF/Application Notes/ST Microelectronics Application Notes/SPV1020 AN3392.pdf
mc74lvx_demux - driver for the MC74LVX138 3:8 demultiplexer (decoder).
drv120_relay or similar - driver for the DRV120PWR relay driver, also used in BMS Carrier.
Comments
We will have three types of events.
Action events will cause something to physically happen - like opening the relay or shutting down an MPPT. They have
EVENT_PRIORITY_HIGHEST
.Fault events are raised when a fault is detected. They have
EVENT_PRIORITY_HIGH
.Data ready events are raised by data_store when new data is available. They have
EVENT_PRIORITY_NORMAL
.
ICs we don’t need drivers for include:
ACS722 current sense: nothing configurable, hidden behind an MCP3427
MC74LVX138 decoder: we can use the existing generic
mux
driver.
From a separation-of-concerns standpoint it might make sense to move the MPPT fault detection logic out of sense_mppt to its own module since it isn’t strictly related to data collection, but that would be more complex and would require duplicating the soft timer logic (though that could be desired if we wanted to check faults more or less frequently). We could do it either way.
...