123

Dependencies:   mbed

Fork of LG by igor Apu

DeviceISACS.h

Committer:
Diletant
Date:
2016-07-03
Revision:
177:672ef279c8e0
Parent:
173:7f938afb0447
Child:
183:c7a9c309086c

File content as of revision 177:672ef279c8e0:

#ifndef __DEVICE_ISACS_H__
#define __DEVICE_ISACS_H__

#include "DeviceISACSPotentiometers.h"

//Information signal amplitude control system
//  input(photodetector - amplifier - potentiometers - amplitude detector - ADC - low pass filter - code - voltage)
//  regulator
//  output(voltage - code - DAC - Amplifier - control unit - hfo)

//Information signal amplitude control system input ( = ADC - low pass filter - code - voltage) typedefs
typedef struct _DeviceISACSInputTransferFunction {
  uint32_t points;     //Number of actual control points (up to 16)
  int32_t V[16];       //Input voltage control points - V in signed 16.16 fixed point format
  int32_t raw[16];     //Input voltage control points - DAC code
} DeviceISACSInputTransferFunction;

typedef struct _DeviceISACSInputSettings {
  DeviceISACSInputTransferFunction transfer;
} DeviceISACSInputSettings;

typedef struct _DeviceISACSInputState {
  int32_t sum;         //Sum of cycle current measurements - ADC code - updates 32 times per cycle
  int32_t raw;         //Average input - ADC code - updates 1 time per cycle
  int32_t V;           //Average input - volts in 16.16 format - updates 1 time per cycle
} DeviceISACSInputState;

typedef struct _DeviceISACSInput {
  DeviceISACSInputSettings settings;
  DeviceISACSInputState state;
} DeviceISACSInput;

//Information signal amplitude control system output ( = DAC + amplifier + control unit + hfo) typedefs
typedef struct _DeviceISACSOutputTransferFunction {
  uint32_t points;     //Number of actual control points (up to 16)
  int32_t voltage[16]; //Output voltage control points - V in signed 16.16 fixed point format
  int32_t code[16];    //DAC code control points
} DeviceISACSOutputTransferFunction;

typedef struct _DeviceISACSOutputStart {
  int32_t voltage;    //Output - volts in 16.16 format
} DeviceISACSOutputStart;

typedef struct _DeviceISACSOutputReset {
  int32_t voltage;    //Output - volts in 16.16 format
} DeviceISACSOutputReset;

typedef struct _DeviceISACSOutputSettings {
  uint32_t max; //Maximum output voltage in 16.16 format. TODO: max(temperature
  uint32_t min; //Minimum output voltage in 16.16 format. TODO: max(temperature
  DeviceISACSOutputTransferFunction transfer;
  DeviceISACSOutputStart start;
  DeviceISACSOutputReset reset;
} DeviceISACSOutputSettings;

typedef struct _DeviceISACSOutputState {
  uint32_t max; //Maximum output voltage in 16.16 format
  uint32_t min; //Minimum output voltage in 16.16 format
  int32_t voltage;     //Output - volts in 16.16 format - updates 1 time per cycle
} DeviceISACSOutputState;

typedef struct _DeviceISACSOutput {
  DeviceISACSOutputSettings settings;
  DeviceISACSOutputState state;
} DeviceISACSOutput;

//Information signal amplitude control system regulator typedefs
typedef struct _DeviceISACSCorrectionTransferFunction {
  uint32_t points;        //Number of actual control points (up to 16)
  int32_t error[16];      //Regulator error - V in signed 16.16 fixed point format
  int32_t correction[16]; //Output correction - -1...+1 in signed 16.16 fixed point format
} DeviceISACSCorrectionTransferFunction;

typedef struct _DeviceISACSRegulatorConditionSettings {
  uint8_t enabled;
  int32_t reference;  //Reference input - volts in 16.16 format
  int32_t scale;      //Regulator scale factor - dimensionless units in signed 16.16 format
} DeviceISACSRegulatorConditionSettings;

typedef struct _DeviceISACSRegulatorSettings {
  DeviceISACSRegulatorConditionSettings start;    //Regulator settings for ISACS system in start condition
  DeviceISACSRegulatorConditionSettings regular;  //Regulator settings for ISACS system in normal condition
  DeviceISACSRegulatorConditionSettings reset;    //Regulator settings for ISACS system in reset condition
  DeviceISACSCorrectionTransferFunction transfer; //Regulator correction function
} DeviceISACSRegulatorSettings;

typedef struct _DeviceISACSRegulatorState {
  uint8_t enabled;
  int32_t reference; //Reference input - volts in 16.16 format
  int32_t error;     //Regulator error - volts in signed 16.16 format
  int32_t scale;     //Regulator scale factor - dimensionless units in signed 16.16 format
  int32_t correction; //Output correction - V in signed 16.16 fixed point format
} DeviceISACSRegulatorState;

typedef struct _DeviceISACSRegulator {
  DeviceISACSRegulatorSettings settings;
  DeviceISACSRegulatorState state;
} DeviceISACSRegulator;

//Information signal amplitude control system typedefs
//  Information signal amplitude ADC: device.controller.SSP.ADC[4]
//  Information signal amplitude control system DAC: device.controller.SSP.DAC[0]
typedef struct _DeviceISACS {
  DeviceISACSPotentiometers potentiometers;
  DeviceISACSInput input;
  DeviceISACSRegulator regulator;
  DeviceISACSOutput output;
} DeviceISACS;

//Information signal amplitude stabilizer functions
void InitISACSOutputDefaultSettings(void);
void InitISACSOutputState(void);
void DeviceStartISACSOutput(void);

void InitISACSRegulatorDefaultSettings(void);
void InitISACSRegulatorState(void);
void DeviceStartISACSRegulator(void);

void InitISACSDefaultSettings(void);
void InitISACSState(void);
void DeviceStartISACS(void);

void isacsProcess(void);

#endif  /* __DEVICE_ISACS_H__ */