Onboard software documentation
==============================


== EEPROM table

Source : link:/documents/SOURCES/mk_romtbl/mk_mea_rom.c[]

=== Energy tables

The MEA software defines 3 energy tables :

- T1 : 128 values [26000, 3] eV
- T2 : 128 values [ 3000, 3] eV
- T3 : 128 values [26000, 3000] eV

The EEPROM table contains 3 energy tables description :

- T1 : 32 ushort values
- T2 : 32 ushort values 
- T3 : 32 ushort values

Values are first averaged from 128 to 32 bins, then converted from energy (eV) to velocity (km/s),
and finally converted to ushort and normalized.

----
#define	d_Lcl_MEA_2qm		5.931e2		// sqrt (2*q/m) / 1000

#define	d_Lcl_MEA_MAX32		1.0273e5	// Normalization parameter (km/s) 30 keV
						// sqrt (30000) * d_Lcl_MEA_2qm

#define	SIZE			3*32		// 3 tables x 32 values = 96 values

float		f_e32 [SIZE];	// 32 energy table values x 3
float		f_v32 [SIZE];	// 32 velocity table values x 3 
unsigned short	us_v32 [SIZE];	// 32 velocity tables normalized ushort x 3

for (i = 0; i < SIZE; i++) {

	f_v32 [i] = sqrt (f_e32[i]) * d_Lcl_MEA_2qm;
	us_v32 [i] = f_v32[i] / d_Lcl_MEA_MAX32 * 0xffff;
}
----


== Onboard software

=== Global definitions and data structures 

Source : link:/documents/SOURCES/Applications/INC/app_MPPE-MEA.h[]

=== Spacecraft potential handling

Source : link:/documents/SOURCES/Applications/APP03/app03_MPPE-MEA.c[]

The part of code below is converting the spacecraft potential value given in global memory variables,
with a couple (A,B) parameters that can be selected by command, and displayed in MEA HK data.

----
#define d_Lcl_MEA_TBL_POT	0x7ff	// 2047

double	f_potA, f_potB, f_pot;

if (pCtrl->uc_pot_mode) {

	index = ?;	// Search value of potential for a given TI

	if (index < Gd_TRG_MAX) 
		f_pot = (double) Gs_TRG2_EFD_Pot [index]*d_Lcl_MAX_POT/0x7fff;	// Volt
	else	
		f_pot = 0.0;

	f_potA = (double) d_Lcl_MEA_MAX_POT *
		 (pCtl->us_pot_A - d_Lcl_MEA_TBL_POT) / d_Lcl_MEA_TBL_POT;

	f_potB = (double) d_Lcl_MEA_MAX_POT * 
		 (pCtl->us_pot_B - d_Lcl_MEA_TBL_POT) / d_Lcl_MEA_TBL_POT;

	f_pot = f_potA * f_pot + f_potB;	// Volt
}
----

==== Spacecraft potential for 2017/12/15 data

Currently, for the tests during 2017/12/15, the initial values of (A,B) were (2047,2047) that corresponds to (0,0) after normalization.

When entring in spacecraft potential mode for VM calculation, (A,B) becomes (0,2252) that can be converted in :

	A = 100 * (0 - 2047) / 2047 = -100
	B = 100 * (2252 - 2047) / 2047 = 10.01

So the value in Volt of spacecraft potential is -100 * f_pot + 10.01

With a value of 0.0, it gives -10.01 V