/* * File: LCCV_Operations.h * Author: NM * * Created on 9 février 2015, 16:12 */ #ifndef LCCV_OPERATIONS_H #define LCCV_OPERATIONS_H #ifdef __cplusplus extern "C" { #endif #if defined(__32MX350F256L__) #include #else #error Unknown processor! #endif // Sensor type #define SENSOR_GENERIC (10) #define SENSOR_SURFACE (20) // SSR serie ON resistance : limitation resistance // estimation for resistance measurment (i ~ 10mA) #define SSR_ON_RESISTOR (12) // Coil 1 : limitation resistance #define COIL_1_LIMITING_RESISTOR (220 + SSR_ON_RESISTOR) // Coil 2 : limitation resistance #define COIL_2_LIMITING_RESISTOR (220 + SSR_ON_RESISTOR) //---------------------------------------------------------------- // MODE 1 constants // Resistance measurement #define MODE1_M1_GAIN ((float)12) #define MODE1_M1_GAIN_TOLERANCE ((float)1) // Maximum admissible coil voltage #define MAX_COIL_VOLTAGE ((float)1.2) // Minimum admissible coil voltage #define MIN_COIL_VOLTAGE ((float)0.6) // Default resistor values #define COIL_RESISTOR_OPEN_CIRCUIT ((float)10000) #define COIL_RESISTOR_SHORT_CIRCUIT ((float)0) //---------------------------------------------------------------- // MODE 2 constants : impuslive damped mode // Constant gain value for mode 2 operation #define MODE2_GAIN_VALUE_1_COIL (400) #define MODE2_GAIN_VALUE_2_COILS (300) // Starting center frequency (in Hz) #define MODE2_FREQUENCY_START (600) // Interval of frequency around the center frequency #define MODE2_FREQUENCY_DRIFT_FACTOR (0.3) // Factor between fo and fp (M2 filter) // Interval of frequency between 2 sets of measurements (in Hz) #define MODE2_FREQUENCY_SWEEP_FACTOR (1.25) // Interval of frequency between 2 sets of measurements (in Hz) #define MODE2_FREQUENCY_SWEEP_MAX (3000) // Minimum required intial amplitude to start the acquisition #define MODE2_INITAL_AMPLITUDE (0.20) // Number of measurements for the moving average #define MODE2_MEASURES_NB (1) //---------------------------------------------------------------- // MODE 3 constants : modulated damped mode // Define the high pass filter frequency #define MODE3_HPF_FREQUENCY (50) // Starting center frequency (in Hz) #define MODE3_FREQUENCY_START ((float)400) // Maximum center frequency during sweep (in Hz) #define MODE3_FREQUENCY_SWEEP_MAX (3000) // Interval of frequency around the center frequency #define MODE3_FREQUENCY_DRIFT_FACTOR (0.1) // Frequency sweep constants #define MODE3_PHASE1_FREQUENCY_SWEEP_FACTOR (1.02) #define MODE3_PHASE1_PULSES_NUMBER_BY_SET (40) #define MODE3_PHASE1_WAIT_AFTER_SET_ms (10) #define MODE3_PHASE1_MIN_AMPLITUDE (0.20) #define MODE3_PHASE1_GAIN_VALUE (250) // Interval of frequency around the center frequency #define MODE3_PHASE2_FREQUENCY_DRIFT_FACTOR (0.3) // Factor between fo and fp (M2 filter) #define MODE3_PHASE2_GAIN_VALUE (250) #define MODE3_PHASE2_PERIOD_SWEEP_FINE_STEP (1) // in us #define MODE3_PHASE2_PULSES_NUMBER_BY_SET (100) #define MODE3_PHASE2_WAIT_AFTER_SET_ms (10) #define MODE3_PHASE2_MIN_AMPLITUDE (0.5) //---------------------------------------------------------------- // MODE 4 constants : sustained mode // Target amplitude of oscillation stabilisation #define LOOPBACK_TARGET_AMPLITUDE ((float)0.300) // Number of frequency ranges #define MODE4_FREQUENCY_RANGE_NB (5) // Phase 1 : interval of frequency around the center frequency #define MODE4_FREQUENCY_DRIFT_FACTOR (0.15) // Phase 1 : maximum number of frequency measurements #define MODE4_PHASE1_MAX_MEASURE_NB (300) // Phase 1 : deviation ratio for oscillation stabilisation #define MODE4_PHASE1_DEVIATION_STABILISATION ((float)0.05) // Phase 1 : number of deviation inside the stabilisation limit #define MODE4_PHASE1_STABILISATION_NB (30) // Phase 1 : amplitude to reach to considered that an oscillation is possible #define MODE4_PHASE1_MIN_AMPLITUDE ((float)0.1) // Phase 1 : number of measurements to reach the minimum amplitude #define MODE4_PHASE1_MIN_TURN (30) // Phase 1 : max gain for the controller #define MODE4_PHASE1_MAX_GAIN (400) // Phase 1 : min gain for the controller #define MODE4_PHASE1_MIN_GAIN (6) // Phase 1 : max gain slope for the controller #define MODE4_PHASE1_MAX_GAIN_SLOPE_DRIFT (0.1) // Phase 2 : number of deviation savings for gain optimisation #define MODE4_PHASE2_DEV_SAVINGS (5) // Phase 2 : interval of time between 2 frequency measurements (in ms) #define MODE4_PHASE2_MEASURE_INTERVAL (10) // Phase 2 : number of elements in the moving average #define MODE4_PHASE2_MA_FREQUENCY_ELEMENTS (10) // Gain reduction in case of voltage saturation #define MODE4_SATURATION_GAIN_REDUCTION (0.3) //----------------------------------------------------------------------------- // Type //----------------------------------------------------------------------------- // Gain control data structure typedef struct { float previousDeviation; float currentDeviation; float targetGain; float previousTargetGain; float amplitude; float frequency; float deviation[MODE4_PHASE2_DEV_SAVINGS]; int mostRecentDeviationIdx; float maxGain; } ST_GAIN_CONTROL; extern const float highPassFilterFrequency[ MODE4_FREQUENCY_RANGE_NB ]; extern const float lowPassFilterFrequency[ MODE4_FREQUENCY_RANGE_NB ]; //----------------------------------------------------------------------------- // Global functions //----------------------------------------------------------------------------- // Measurement of the coils resistances (MODE 1) int LCCV_CoilsResistanceMeasure( float *aCoil1Resistance, float *aCoil2Resistance ); // Measurement mode with sustained oscillation (MODE 4) int LCCV_SustainedMode( void ); // Measurement mode with modulated stimulation int LCCV_ModulatedDampedMode( float* aFrequency ); // Measurement mode with high voltage impulsion stimulation int LCCV_ImpulsiveDampedMode( float* aFrequency ); //----------------------------------------------------------------------------- // Local functions //----------------------------------------------------------------------------- // Try to make the coil enter in auto oscillation int lccv_InitialiseSustainedOscillation( float* aCurrentGain, float* aFrequency, int* aFrequencyRange); int lccv_RecenterFrequency( float* aM1TargetGain, float aFrequencyMean, float* aCenterFrequency ); // Compute the gain target to reach the voltage order int lccv_GainController( ST_GAIN_CONTROL* aGainData ); int lccv_TestM2Filter( void ); // Terminate the measurment, keep the LCCV in idle state int lccv_EndOfOperation( void ); // Check the number of present coils int lccv_CheckCoilsPresence( unsigned int* aCoilToUse ); #ifdef __cplusplus } #endif #endif /* LCCV_OPERATIONS_H */