5.3.1 Trasmissione e ricezione con l’interfaccia di
controllo
La trasmissione dei dati che il firmware della SMU impacchetta per l’interfaccia si basa sull’utilizzo di una coda, in inglese queue. Il freeRTOS mette a disposizione del programmatore la struttura dati “queue”, insieme a tutte le funzioni necessarie per gestirla. All’avvio del sistema operativo, la coda viene creata in modo tale che possa contenere i messaggi da inviare via CAN-bus; gli viene assegnato anche un numero di elementi massimo che può contenere. Una volta creato, il task di invio entra in un ciclo infinito nel quale ciclicamente controlla se ci sono messaggi da trasmettere nella queue. In caso affermativo, viene estratto un messaggio dalla coda ed il task tenta di inviarlo tramite la periferica CAN, andando a vedere se almeno uno dei 3 buffer di invio della periferica è libero. Nel caso più fortunato in cui un buffer della periferica è libero viene riempito dal messaggio estratto dalla coda e la periferica, appena possibile, lo trasmetterà. Altrimenti il task si sospende per 1 ms, eliminando le attese attive. Nel caso in cui, invece, non ci siano messaggi nella queue da trasmettere il task di trasmissione, anche stavolta, si sospende per 1 ms, lasciando libera la CPU per altri task.
La ricezione dei messaggi dal CAN-bus dell’interfaccia di controllo è affidata ad un task dedicato, che svolge l’operazione di un parcer: riceve i dati, li spacchetta e ne acquisisce il contenuto. Generalmente i messaggi ricevuti dall’interfaccia esterna sono comandi che servono a far eseguire una determinata operazione alla SMU. Partendo dall’inizio del processo di ricezione, la periferica CAN viene settata per generare un interrupt ogni volta che un messaggio viene ricevuto. L’handler dell’interrupt, quando entra in
esecuzione, verifica che ci sia stata effettivamente la ricezione di un messaggio e su quale delle due periferiche CAN. In caso affermativo il messaggio viene acquisito dall’handler che prova ad inserirlo in una queue dedicata ai messaggi ricevuti dall’interfaccia: se la queue non è piena, il messaggio vi viene inserito e l’handler termina. A questo punto entra in gioco il task di ricezione che, ciclicamente, controlla se ci sono elementi nella coda di ricezione sopra citata, altrimenti si sospende per 1 ms per evitare le attese attive. Se la queue contiene dei messaggi, il task ne estrae uno alla volta e, per ognuno di essi, viene verificata la sua provenienza: se il messaggio arriva dall’interfaccia (o dalla PMU) allora viene spacchettato, altrimenti viene scartato. Se ho ricevuto un comando dall’interfaccia, allora viene controllato il destinatario del comando, informazione contenuta del primo byte del payload del messaggio. Per ogni destinatario del comando c’è una funzione specifica che spacchetta il comando e lo trasmette ai vari task che dovranno attuarlo.
Per mettere in atto questo tipo di comunicazione con l’interfaccia di controllo, sono stati creati una serie di messaggi customizzati per questa specifica applicazione e sono elencati di seguito.
Signal name Bit pos.
Msb-Lsb Size (bit) Scale Note
RX_STRING_ID 7-0 8 Unsigned
0bxSSMMMM With:
SS=3, MMMM=0 -> all MMU of SMU0 SS=3, MMMM=1 -> all MMU of SMU1 SS=3, MMMM=2 -> all MMU of SMU2 SS=3, MMMM=3 -> all MMU SS=3, MMMM=4 ->SMU0 SS=3, MMMM=5 ->SMU1 SS=3, MMMM=6 ->SMU2 SS=3, MMMM=7 ->PMU SS=0,1,2 -> MMUMMMM of SMUSS
ID: 0x100 + id Name: COMMAND
ID_CMD 15-8 8 Unsigned See table XXX Params [0] 23-16 8 Params [1] 31-24 8 Params [2] 39-32 8 Params [3] 47-40 8 Params [4] 55-48 8 Params [5] 63-56 8 Table XXX
Command CMD_TYPE NUM
PARAMS CMD_PARAM_0 – CMD_PARAM_5 PARAM DESCRIPTION: Select / deselect manual balance for all
cell 0x01 1 CMD_PARAM_0 = 0 -> Deselect all cell CMD_PARAM_0 = 1 -> Select all cell Select / deselect manual balance for
cell 1 to cell 16
0x02 2 CMD_PARAM_0 = 0 -> Deselect the cell CMD_PARAM_0 = 1 -> Select the cell CMD_PARAM_1 -> Number of single interested cell (0 to 15)
Automatic balance (target is module or
string) 0x03 1 CMD_PARAM_0 = 0 -> Stop the automatic balancing process if it is running, otherwise it has no effect
CMD_PARAM_0 = 1 -> Start the automatic balancing process if the target needs it, otherwise it has no effect
String switch: open, charge, discharge 0x04 1 CMD_PARAM_0 = 0 -> Switch open in ready CMD_PARAM_0 = 1 -> Switch close in charge
CMD_PARAM_0 = 2 -> Switch close in discharge
String SoC Correction 0x05 1 CMD_PARAM_0 = 0 -> Correction Disabled CMD_PARAM_0 = 1 -> Correction Enabled
Debug Mode settings 0x06 1 CMD_PARAM_0 = 0 -> Debug disabled
CMD_PARAM_0 = 1 -> Debug enabled for all tasks
CMD_PARAM_0 = 2 -> Debug enabled only for peripheral tasks
CMD_PARAM_0 = 3 -> Debug enabled only for processing tasks
CMD_PARAM_0 = 4 -> Debug enabled only for sending and receiving tasks
Stack Monitor Shutdown 0x07 1 CMD_PARAM_0 = 0 -> Power ON
CMD_PARAM_0 = 1 -> Shutdown Current sensor status update 0x08 0
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 1 voltage 15-0 16 Unsigned 16b
∙ 5𝑉 65535
0 Right aligned, LSB first
Cell 2 voltage 31-16 16 Unsigned 16b 0 Right aligned, LSB first
Cell 3 voltage 47-32 16 Unsigned 16b 0 Right aligned, LSB first
Cell 4 voltage 63-48 16 Unsigned 16b 0 Right aligned, LSB first
ID: 0x200 + id Name: CELL_VOLTAGE_1
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 5 voltage 15-0 16 Unsigned 16b
∙ 5𝑉 65535
0 Right aligned, LSB first
Cell 6 voltage 31-16 16 Unsigned 16b 0 Right aligned, LSB first
Cell 7 voltage 47-32 16 Unsigned 16b 0 Right aligned, LSB first
Cell 8 voltage 63-48 16 Unsigned 16b 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 9 voltage 15-0 16 Unsigned 16b
∙ 5𝑉 65535
0 Right aligned, LSB first
Cell 10 voltage 31-16 16 Unsigned 16b 0 Right aligned, LSB first
Cell 11 voltage 47-32 16 Unsigned 16b 0 Right aligned, LSB first
Cell 12 voltage 63-48 16 Unsigned 16b 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 13 voltage 15-0 16 Unsigned 16b
∙ 5𝑉 65535
0 Right aligned, LSB first
Cell 14 voltage 31-16 16 Unsigned 16b 0 Right aligned, LSB first
Cell 15 voltage 47-32 16 Unsigned 16b 0 Right aligned, LSB first
Cell 16 voltage 63-48 16 Unsigned 16b 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Aux ch 1 15-0 16 Unsigned 16b
∙ 5𝑉 65535= 𝑉
0 Right aligned, LSB first
Aux ch 2 31-16 16 Unsigned 16b 0 Right aligned, LSB first
Aux ch 3 47-32 16 Unsigned 16b 0 Right aligned, LSB first
Aux ch 4 63-48 16 Unsigned 16b 0 Right aligned, LSB first
Signal name Bit pos. Msb-Lsb
Size (bit) Type Scale Offset Note
Aux ch 5 15-0 16 Unsigned 16b
∙ 5𝑉 65535= 𝑉
0 Right aligned, LSB first
Aux ch 6 31-16 16 Unsigned 16b 0 Right aligned, LSB first
Aux ch 7 47-32 16 Unsigned 16b 0 Right aligned, LSB first
ID: 0x240 + id Name: CELL_VOLTAGE_2
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x280 + id Name: CELL_VOLTAGE_3
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x2C0 + id Name: CELL_VOLTAGE_4
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x300 + id Name: CELL_TEMPERATURE_1
Length:8 Byte Type:Periodic Refresh Time: 500 ms
ID: 0x340 + id Name: CELL_TEMPERATURE_2
Aux ch 8 63-48 16 Unsigned 16b 0 Right aligned, LSB first
Nota: la legge di conversione dal dato ricevuto alla temperatura è la seguente: B = 3390 K T0 = 300 K VP1 = 5,33 V R0 = 10 kΩ 𝑇 = 1 1 𝐵ln 𝑅 𝑅 + 1 𝑇 − 273,15 [°𝐶] 𝑅 =(𝑅 + 10)𝑉 − 10𝑉 𝑉 − 𝑉 []
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Current string 31-0 32 Signed 32b (mA) 0 Right aligned, LSB first
Voltage U1 63-32 32 Signed 32b (mV) 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Voltage U2 31-0 32 Signed 32b (mV) 0 Right aligned, LSB first
Voltage U3 63-32 32 Signed 32b (mV) 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Module
warning UV 15-0 16 Unsigned 16b 0 Right aligned, LSB first
Module warning OV
31-16 16 Unsigned 16b 0 Right aligned, LSB first
Module
warning UT 39-32 8 Unsigned 8b 0 Right aligned, LSB first
Module
warning OT 47-40 8 Unsigned 8b 0 Right aligned, LSB first
ID: 0x380 + id Name: CURRENT_SENSOR_DATA_1
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x3C0 + id Name: CURRENT_SENSOR_DATA_2
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x400 + id Name: MODULE_WARNINGS
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Module alarm
UV 15-0 16 Unsigned 16b 0 Right aligned, LSB first
Module alarm OV
31-16 16 Unsigned 16b 0 Right aligned, LSB first
Module alarm
UT 39-32 8 Unsigned 8b 0 Right aligned, LSB first
Module alarm
OT 47-40 8 Unsigned 8b 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
N_Module_voltage 15-0 16 Unsigned 16b (Note 1) 0 Right aligned, LSB first
N_Chip_analog_temperature 31-16 16 Unsigned 16b (Note 2) 0 Right aligned, LSB first
N_Chip_digital_temperature 47-32 16 Unsigned 16b (Note 3) 0 Right aligned, LSB first
Module balance status 63-48 16 Unsigned 16b 0 Right aligned, LSB
first Note 1) 𝑀𝑜𝑑𝑢𝑙𝑒 𝑣𝑜𝑙𝑡𝑎𝑔𝑒 =𝑁_𝑀𝑜𝑑𝑢𝑙𝑒_𝑣𝑜𝑙𝑡𝑎𝑔𝑒 65535 ∙ 25 ∙ 5𝑉 [𝑉] Note 2) 𝐶ℎ𝑖𝑝 𝑎𝑛𝑎𝑙𝑜𝑔 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 = 𝑁_𝐶ℎ𝑖𝑝_𝑎𝑛𝑎𝑙𝑜𝑔_𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 65535 ∙ 5𝑉 − 1,8078 ∙ 147,514 [°𝐶] Note 3) 𝐶ℎ𝑖𝑝 𝑑𝑖𝑔𝑖𝑡𝑎𝑙 𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 = 𝑁_𝐶ℎ𝑖𝑝_𝑑𝑖𝑔𝑖𝑡𝑎𝑙_𝑡𝑒𝑚𝑝𝑒𝑟𝑎𝑡𝑢𝑟𝑒 65535 ∙ 5𝑉 − 2,287 ∙ 131,944 [°𝐶]
ID: 0x440 + id Name: MODULE_ALARMS
Length:6 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x480 + id Name: MODULE_STATUS_1
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Module status 1 7-0 8 Unsigned 8b 0 Right aligned, LSB first
STATUS DEFINITION
Byte name Bit Name Description
Module status 1 [1:0] BALANCE_MODE
Balance mode: 0 = Balance disabled 1 = Manual Balance 2 = Automatic Balance
Signal name Bit pos. Msb-Lsb
Size (bit)
Type Scale Offset Note
Status_0 7-0 8 Unsigned 8b 0 Right aligned, LSB first
Status_1 15-8 8 Unsigned 8b 0 Right aligned, LSB first
Status_2 23-16 8 Unsigned 8b 0 Right aligned, LSB first
Min voltage cell 39-24 16 Unsigned 16b 0 Right aligned, LSB first Max voltage cell 55-40 16 Unsigned 16b 0 Right aligned, LSB first
STATUS DEFINITION Byte
name
Bit Name Description
Status_0
[7] SOC_CORRECTION
Enabling of SoC correction by OCV:
0= Correction disabled; the SoC is calculated using the Coulomb counting algorithm
1 = OCV correction; the SoC is corrected by reading the cell voltage [5:4] RCVD_SW_COMM
Command received for control of the switch in charge and discharge: 0 = No command received
1 = Standby command 2 = Charge command 3 = Discharge command [3] SW_STATE State of the string switch: 0 = Open
1 = Close
[2:0] STRING_STATE
State of the string:
0 = Initialization status, the string waits for the connection with the acquisition devices
1 = Waiting status, the string is ready to be connected
2 = Error status, the string is blocked by the activation of an alarm 3 = String in charge
4 = String in discharge
For all warning and alarm flags: 0 = Not active, 1 = Active
Status_1
[7] WAR_IVT_CONN This warning is activated when the connection errors counter is over a warning threshold for the sensor current [6] WAR_MOD_CONN This warning is activated when the connection errors counter is over a warning threshold for the stack monitor [5] WAR_OC_MINUS This warning is activated when the current exceeds the preset warning threshold.
ID: 0x4C0 + id Name: MODULE_STATUS_2
Length:1 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x500 + id Name: STRING_STATUS_1
[4] WAR_OC_PLUS This warning is activated when the current exceeds the preset warning threshold. [3] WAR_UT This warning is activated when the temperature of at least one aux input exceeds the preset warning threshold. [2] WAR_OT This warning is activated when the temperature of at least one aux input exceeds the preset warning threshold. [1] WAR_UV This warning is activated when the voltage of at least one cell exceeds the preset warning threshold. [0] WAR_OV This warning is activated when the voltage of at least one cell exceeds the preset warning threshold.
Status_2
[7] ALARM_IVT_CONN This alarm is activated when the connection errors counter is over a alarm threshold for the sensor current [6] ALARM_MOD_CONN This alarm is activated when the connection errors counter is over a alarm threshold for the stack monitor [5] ALARM_OC_MINUS This alarm is activated when the current exceeds the preset alarm threshold. [4] ALARM_OC_PLUS This alarm is activated when the current exceeds the preset alarm threshold. [3] ALARM_UT This alarm is activated when the temperature of at least one aux input exceeds the preset alarm threshold. [2] ALARM_OT This alarm is activated when the temperature of at least one aux input exceeds the preset alarm threshold. [1] ALARM_UV This alarm is activated when the voltage of at least one cell exceeds the preset alarm threshold. [0] ALARM_OV This alarm is activated when the voltage of at least one cell exceeds the preset alarm threshold.
Signal name Bit pos. Msb-Lsb
Size (bit)
Type Scale Offset Note
String_SoC 15-0 16 Unsigned 16b (‰) 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 1 SoC 15-0 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 2 SoC 31-16 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 3 SoC 47-32 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 4 SoC 63-48 16 Unsigned 16b (‰) 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 5 SoC 15-0 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 6 SoC 31-16 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 7 SoC 47-32 16 Unsigned 16b (‰) 0 Right aligned, LSB first
ID: 0x540 + id Name: STRING_STATUS_2
Length:2 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x580 + id Name: CELL_SOC_1
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x5C0 + id Name: CELL_SOC_2
Cell 8 SoC 63-48 16 Unsigned 16b (‰) 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 9 SoC 15-0 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 10 SoC 31-16 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 11 SoC 47-32 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 12 SoC 63-48 16 Unsigned 16b (‰) 0 Right aligned, LSB first
Signal name Bit pos. Msb-Lsb
Size (bit)
Type Scale Offset Note
Cell 13 SoC 15-0 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 14 SoC 31-16 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 15 SoC 47-32 16 Unsigned 16b (‰) 0 Right aligned, LSB first Cell 16 SoC 63-48 16 Unsigned 16b (‰) 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 1 dQbal 15-0 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 2 dQbal 31-16 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 3 dQbal 47-32 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 4 dQbal 63-48 16 Unsigned 16b mAh 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 5 dQbal 15-0 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 6 dQbal 31-16 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 7 dQbal 47-32 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 8 dQbal 63-48 16 Unsigned 16b mAh 0 Right aligned, LSB first
Signal name Bit pos.
Msb-Lsb Size (bit) Type Scale Offset Note
Cell 9 dQbal 15-0 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 10 dQbal 31-16 16 Unsigned 16b mAh 0 Right aligned, LSB first
ID: 0x600 + id Name: CELL_SOC_3
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x640 + id Name: CELL_SOC_4
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x680 + id Name: CELL_DQBAL_1
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x6C0 + id Name: CELL_DQBAL_2
Length:8 Byte Type:Periodic Refresh Time: 100 ms
ID: 0x700 + id Name: CELL_DQBAL_3
Cell 11 dQbal 47-32 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 12 dQbal 63-48 16 Unsigned 16b mAh 0 Right aligned, LSB first
Signal name Bit pos. Msb-Lsb
Size (bit)
Type Scale Offset Note
Cell 13 dQbal 15-0 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 14 dQbal 31-16 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 15 dQbal 47-32 16 Unsigned 16b mAh 0 Right aligned, LSB first Cell 16 dQbal 63-48 16 Unsigned 16b mAh 0 Right aligned, LSB first
5.3.2 Trasmissione e ricezione con il sensore di
corrente
La gestione del sensore di corrente è suddivisa in 3 task, due dei quali si occupano della sola comunicazione del sensore con la SMU. Il terzo task è quello che gestisce il settaggio del sensore e che trasmette i comandi di trigger ma lo vediamo più in dettaglio nel paragrafo successivo.
Dunque, la comunicazione comincia dai task strettamente legati alla periferica CAN-bus alla quale è collegato il sensore. La struttura base della trasmissione e della ricezione è identica a quella utilizzata per il CAN-bus verso l’interfaccia di controllo: in trasmissione abbiamo un task abbinato ad una queue dalla quale preleva i messaggi da trasmettere e li deposita nei buffer di trasmissione liberi della periferica CAN, altrimenti resta sospeso per evitare attese attive. In ricezione abbiamo un interrupt che segnala l’arrivo di un messaggio, il gestore dell’interruzione si occupa di verificare l’evento di ricezione e di prendere il messaggio ricevuto e metterlo in una queue specifica per i messaggi inviati dal sensore di corrente. L’unica differenza sta nel parcer dei messaggi, che ovviamente è in grado di riconoscere tutti i messaggi scambiati con il sensore di corrente. Una funzione specifica prende il messaggio ricevuto dal sensore e lo spacchetta, ricavandone il contenuto
ID: 0x740 + id Name: CELL_DQBAL_4
informativo. Infine, il task aggiorna le strutture dati globali con i nuovi dati ricevuti e conclude il suo ciclo di operazioni. Anche il task di ricezione del sensore di corrente implementa un meccanismo di auto-sospensione in caso di assenza di messaggi ricevuti, per evitare attese attive.
Adesso andiamo più nel dettaglio a vedere in che modo viene gestito il sensore di corrente e come è organizzato il task che provvede a questo compito.