/***************************************************************************** * ADC ***************************************************************************** * FileName: adc.h * Dependencies: * Processor: PIC24 * Compiler: MPLAB C30 * Linker: MPLAB LINK30 * * * * Author Date Comment *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Michael Cecere 09/2006 *****************************************************************************/ #define ADC_CS LATBbits.LATB0 // ADC Select, out, active low #define ADC_CONV LATBbits.LATB2 // ADC Convert, out, active high #define ADC_BUSY PORTBbits.RB1 // ADC_BUSY, in, active high #define MUXA0 LATGbits.LATG12 // ADC MUX Addresses #define MUXA1 LATGbits.LATG13 // ADC MUX Addresses #define MUXA2 LATGbits.LATG14 // ADC MUX Addresses #define MUXA3 LATGbits.LATG15 // ADC MUX Addresses //MUX channel definitions #define Final_0_Int1 0 #define Final_0_Int2 1 #define Final_1_Int1 2 #define Final_1_Int2 3 #define Final_2_Int1 4 #define Final_2_Int2 5 #define Final_3_Int1 6 #define Final_3_Int2 7 #define Comp_External 8 #define Buf_Spare 9 #define Spare0 10 #define Spare1 11 #define Spare2 12 #define Volts_5 13 #define Ground 14 #define ADC_Temp 15 #define ADC_MAX 2.5 #define ADC_MIN 0.0 // ring buffer for averaging calibration constants over RINGBUFFERSIZE calibration cycles #define RINGBUFSIZE 10 ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // // Structure for storing data to EEPROM. // // CHANGING THIS STRUCTURE MIGHT CAUSE THE EEPROM TO BE UNREADABLE // // this structure holds the calibration and configuration data // for the ADC and such // starts at address EE_CONFIG_BASE IN THE eeprom //SEE EEPROM.C FOR EXAMPLES OF LOADING DATA INTO STRUCTURE // ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// typedef struct SYS_Config_type { char NumDataAvg; // # acquired points to average char NumCalAvg; // # of times calibration data is averaged int CalRingBufSize; // how many cals to average float Comp_ADC_Gain[2]; // two comparator channel ext inputs float Comp_ADC_Offset[2]; float Comp_DAC_Gain; // one comparator DAC chan float Comp_DAC_Offset; int Chan_ON[4]; // 1 = channel enabled int Chan_Faradaycup[4]; // 1 = Is Faradaycup unsigned int Cal_Delay[4]; // cal pulse delay unsigned int Cal_Pre_Trig[4]; // counts to pre-trigger by unsigned int INT1_Width[4]; // integrator #1 width unsigned int INT2_Width[4]; // integrator #2 width unsigned int Reset_Delay[4]; // Reset pulse delay float Calibrated_0pC[4]; // holds measured data from bench calib. float Calibrated_200pC[4]; float Calibrated_1000pC[4]; float LINm[8][RINGBUFSIZE]; // simple linear fit to three point cal float LINoff[8][RINGBUFSIZE]; // 8 channels by ringbuffer size float DAC_Err_Offset[8]; // correction factor to DAC outputs float DAC_Err_Gain[8]; // derived from values measured at 200pC and 1000pC float MPS_OC_Threshold[7][4]; // Determines channel over/under threshold float MPS_Comp_Threshold[7][4][2]; // Hold the two comparator threshold levels for ea. chan // both should be 0