CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
Adc.h
Go to the documentation of this file.
1
2#include "stdint.h"
3#include <stdbool.h>
4/*! \file
5
6
7*/
8
9
10
11// CROSS INIZIO
12
13//Registri/comandi per ADC
14#define ADC_communication_reg 0 //It is a NOP operation
15
16#define ADC_to_be_added_to_read 0x40 //This must be added to the address below for reading
17#define ADC_data_reg 0x08 // Conversione is read from this 24 bit register
18#define ADC_range_reg 0x28 //set-up register for input range and single/continuous conversion
19#define ADC_Conversion_time_reg 0x30
20#define ADC_mode_reg 0x38 //Conversion mode, resolution, dumpp
21#define ADC_mode_reg_ch0 0x38 //Conversion mode, resolution, dumpp for ADC CH0
22#define ADC_mode_reg_ch1 ADC_mode_reg_ch0 + 2 //Conversion mode, resolution, dumpp for ADC CH1
23#define ADC_channel_data_reg 0x08 //Conversion mode, resolution, dumpp
24#define ADC_full_scale_correction_register 0x18
25#define ADC_offset_correction_register 0x10
26#define ADC_channel_conversion_time_FW_ch0_register 0x30
27#define ADC_channel_conversion_time_FW_ch1_register ADC_channel_conversion_time_FW_ch0_register + 2
28
29#define ADC_max_resolution 0xFF
30#define ADC_ZeroScaleCalibration_com 0x82 //ADC Zero-Scale Self-Calibration, Need to wait for end of calibration at RDY
31#define ADC_Channel_zero_scale_calibration 12
32#define ADC_Channel_full_scale_calibration 14
33#define ADC_idle_com 0x02 //Single conversion mode, 24 bit, waiting to measure
34#define ADC_mode_reg_set_single_24bit 0x42 //0x40: single conversion, 0x02: 24 bit resolution
35#define read_from_CH0 0x48
36#define read_from_CH1 (read_from_CH0+2)
37
38/*! Coefficients for reading nodes.
39Ri is in series to the source noise to measure and to RA, that is in series to the buffer and connected to RB from buffer to GND.
40We now use the LMP7702 as input buffer. It is a MOS input OA and does not show inpt current. Its input offset is quite negligible,
41but we measure it since the ADC contribution sums to it. Let's call it Vof.
42The voltage Vi to mesure is therefore:
43Vi= (Ri +RA+RB)/RB (Vm - Vof), where Vm is the voltage read from the ADC when the input is connected.
44Vi= Vm - Vof + (Ri +RA)/RB (Vm - Vof). So the numerator to consider is Ri+RA while the denominator RB.
45A special case is when the detector bias is read since a further attenuator is put before RA: RAp in series
46to the source node to read and connected to RBp, from Rap to GND.
47If we call Ri'=RAp||RBp, then:
48Vb= (RAp+RBp)/RBp (Vm-Vof + (Ri'+RA)/RB(Vm-Vof))
49*/
50#define ADC_numeratore_PGA 1 /*!< Partizione 8.2k con 82k all'ingresso del buffer: 8.2 /82 =1 /10 */
51#define ADC_denominatore_PGA 10 /*!< .. */
52#define ADC_numeratore_PreOut 91 /*!< Partizione 10k + 8.2k con 82k all'ingresso del buffer: (18.2)/82=91 /410 */
53#define ADC_denominatore_PreOut 410 /*!< .. */
54#define ADC_numeratore_PowerSupply 91 /*!< Partizione 10k + 8.2k con 82k all'ingresso del buffer: (18.2)/82=91 /410 */
55#define ADC_denominatore_PowerSupply 410 /*!< .. */
56#define ADC_numeratore_Vreg 33 /*!< Partizione 62 + 8.2k con 82k all'ingresso del buffer: (0062+8.2)/82=8250 / 82000 =33 /328 */
57#define ADC_denominatore_Vreg 328 /*!< .. */
58#define ADC_numeratore_Bias_p 29 /*!< Abbiamo che RAp \'e 100k mentre RBp 16K, quindi (100+16)/16=58/8=29/4*/
59#define ADC_denominatore_Bias_p 4 /*!< ... */
60#define ADC_numeratore_Bias 11 /*!< Partizione 16k||100K + 8.2k con 82k all'ingresso del buffer: (8.2+(16||100))/82=21.99 /82=22/82=11/41 12/41 */
61#define ADC_denominatore_Bias 41 /*!< .. */
62#define ADC_numeratore_Res_fisse 10 /*!< Partizione 20k con 82k all'ingresso del buffer: 20/(82)=10 /41 */
63#define ADC_denominatore_Res_fisse 41 /*!< .. */
64#define ADC_molteplicita_node_to_read 6 /*!< .. */
65
66/*!
67*\snippetlineno Adc.h struct_ADC_coefficiente_type
68*/
69//! <!-- [struct_ADC_coefficiente_type] -->
71 int16_t numeratore;
72 int16_t denominatore;
73};
74//! <!-- [struct_ADC_coefficiente_type] -->
75
76extern int32_t volatile ADC_misura_fatta;
77extern int32_t volatile ADC_external_measurement;
78extern uint8_t volatile ADC_external_measured_node;
79extern const struct ADC_coefficiente_type ADC_coefficiente[];
80extern volatile uint8_t ADC_sleep_off; //if 0 ADC in sleep, ADC>1 ADC never sleep
81extern volatile uint16_t ADC_medie_per_misura; //< the number of ADC readings to average, the maximum is 400
82extern volatile bool ADC_non_leggi_lo_offset_se_true;
83
85int32_t ADC_lettura(uint8_t scheda_su_scheda_giu, uint8_t node_to_read, uint8_t cosa_fare);
86
87void ADC_Sleep_fun(uint8_t up_down);
88void ADC_selfcal_zero_scale(uint8_t up_down);
89void ADC_Wakeup(uint8_t up_down);
90signed long int ADC_lettura_24bit(char ADC_0_o_1, uint8_t up_down, uint8_t cosa_fare);
91uint32_t ADC_lettura_registro(char ADC_0_o_1 /*0=ADC0, 1=ADC1*/, uint8_t up_down, uint8_t registro_ch0);
92void ADC_scrittura_registro(char ADC_0_o_1 /*0=ADC0, 1=ADC1*/, uint8_t up_down, uint8_t registro_ch0, int32_t value_to_write);
93int ADC_compensazione_al_nodo(uint8_t line_to_read , int32_t lettura_ADC , int32_t lettura_offset);
94//int32_t ADC_misura_differenziale(uint8_t scheda_su_scheda_giu , uint8_t nodo_da_leggere );
95void ADC_sleep_ON_OFF(uint8_t up_down , uint8_t ON_OFF_NOP);
96//int32_t ADC_misura_differenziale_con_media_at_PGA(uint8_t scheda_su_scheda_giu_, uint8_t preamplifier_externalADC_1_onboardADC_0, uint8_t indice, int32_t *preamplifier_error_voltage_at_the_moment);
97int32_t ADC_misura_differenziale_con_media_generico(uint8_t scheda_su_scheda_giu_, uint8_t preamplifier_externalADC_1_onboardADC_0, uint8_t nodo_da_misurare, uint8_t differenziale1_single_0);
98static int32_t ADC_misura_differenziale_single_ended(uint8_t scheda_su_scheda_giu , uint8_t nodo_da_leggere, uint8_t differenziale_1_single_0 );
99
100
101
102//CROSS FINE
103
104
105// ***********************ooOO Registers and most common registers contents for the used ADC AD7732 OOoo*****************
106
107//SPI Registers for channel 0 of ADC
108//Write register, add 0x40 for reading
109extern unsigned int Radc_internal;
110extern unsigned int Rmultiplexer;
111extern unsigned char medie_ADC;
112
113
114
115
116// More frequent ADC commands
117
118//At register "ADC_mode_reg"
119#define ADC_power_down_com 0x70 //Shut down: power down and clock disabled
120//#define ADC_power_down_com 0x02 //Disable ADC power down
121
122#define ADC_idle 0
123
124
125
126
127
128//At register "ADC_range_reg"
129
130#define ADC_max_input_range_minus_10_to_10 0 //Range to +/- 10 V
131
132//At register "ADC_Conversion_time_reg"
133
134#define indice_Vbias 0
135#define indice_PoerSupply 1
136#define indice_100_ohm 2
137#define indice_10_Kohm 3
138#define indice_Vbias_extern 4
139#define indice_default 5
140
141#define ADC_Conversion_time_chop_e_max_filter 0xFF // Best resolution
142#define ADC_Conversion_time_500micros_per_conversion 0x96 // Medium resolution
143#define ADC_Conversion_time_200micros_per_conversion 0x88 // Medium resolution
144#define ADC_Conversion_time_80micros_per_conversion 0x82 // Low resolution
145
146#define ADC_reference_voltage 2.5e6 /*Voltage in microV*/
147#define R_ref_10k 10e6 /* Resistance in mOhm*/
148#define R_series_for_Vbias_extern 1800.0*18000.0/(1800.0+18000.0)*1000
149#define R_series_for_Vbias 1500.0*8200.0/(1500.0+8200.0)*1000
150#define R_series_for_PowerSupply 1e6
151
152#define RADC_tot 8*Radc_internal
153
154#define Coefficiente_Vref_Vbias Rmultiplexer + R_series_for_Vbias
155#define Coefficiente_Vmeas_Vbias RADC_tot + Coefficiente_Vref_Vbias
156
157#define Coefficiente_Vref_Vbias_extern Rmultiplexer + R_series_for_Vbias_extern
158#define Coefficiente_Vmeas_Vbias_extern RADC_tot + Coefficiente_Vref_Vbias_extern
159
160#define Coefficiente_Vref_PowerSupply Rmultiplexer + R_series_for_PowerSupply
161#define Coefficiente_Vmeas_PowerSupply RADC_tot + Coefficiente_Vref_PowerSupply
162
163#define Coefficiente_Vref_default Rmultiplexer + 100e3
164#define Coefficiente_Vmeas_deafult RADC_tot + Coefficiente_Vref_default
165
166#define Coefficiente_Vref_100_ohm Rmultiplexer + 100e3
167#define Coefficiente_Vmeas_100_ohm RADC_tot + Coefficiente_Vref_100_ohm
168
169#define Coefficiente_Vref_10k_ohm Rmultiplexer + 10000e3
170#define Coefficiente_Vmeas_10k_ohm RADC_tot + Coefficiente_Vref_10k_ohm
171
172
174 unsigned int coefficiente_Vmeas;
175 unsigned int coefficiente_Vref;
176 unsigned int partizione_per_1000;
177} ;
178
179extern struct coeffcienti_misura_ADC_type coeffcienti_misura_ADC[indice_default+1];
180extern unsigned char coeffcienti_misura_ADC_nodi[];
181
182// ADC.h
183
184
185
186void calibrazione_Resistenze_sterne_ADC(void);
187
188int correzione_misura_ADC(char quali_coefficienti, int misura);
189long long int divisione_di_gianlu( long long int Numeratore, long long int denominatore);
190
191
int32_t ADC_lettura(uint8_t scheda_su_scheda_giu, uint8_t node_to_read, uint8_t cosa_fare)
This function allows to read the voltage of any of the selectable nodes.
Definition: Adc.c:710
int32_t ADC_misura_differenziale_con_media_generico(uint8_t scheda_su_scheda_giu_, uint8_t preamplifier_externalADC_1_onboardADC_0, uint8_t nodo_da_misurare, uint8_t differenziale1_single_0)
This function sets the original gain when a few LSb have to be determined. The umber of bits is bit_t...
Definition: Adc.c:899
int ADC_compensazione_al_nodo(uint8_t line_to_read, int32_t lettura_ADC, int32_t lettura_offset)
This function allows to read a whatver regsiter of the ADC.
Definition: Adc.c:568
void ADC_Sleep_fun(uint8_t up_down)
ADC is sent to sleep mode.
Definition: Adc.c:262
long long int divisione_di_gianlu(long long int Numeratore, long long int denominatore)
The division operator on 32 or 64 bit, positive/negative integers.
Definition: Adc.c:1096
void instr_ADC_LETTURA_function(void)
All the posible nodes voltages can be read with this instruction. Either the internal or an external ...
Definition: Adc.c:761
uint32_t ADC_lettura_registro(char ADC_0_o_1, uint8_t up_down, uint8_t registro_ch0)
This function allows to read a whatver regsiter of the ADC.
Definition: Adc.c:592
void ADC_scrittura_registro(char ADC_0_o_1, uint8_t up_down, uint8_t registro_ch0, int32_t value_to_write)
This function allows to read a whatver regsiter of the ADC.
Definition: Adc.c:654
volatile uint16_t ADC_medie_per_misura
the number of ADC readings to average, the maximum is 400
Definition: Adc.c:206
signed long int ADC_lettura_24bit(char ADC_0_o_1, uint8_t up_down, uint8_t cosa_fare)
ADC Wakeup and 24 bits reading.
Definition: Adc.c:433
void ADC_Wakeup(uint8_t up_down)
ADC Wakeup and 24 bits reading.
Definition: Adc.c:388
unsigned char medie_ADC
The number of averages done is 1 << medie_ADC, or 2^medie_ADC.
Definition: Adc.c:985
const struct ADC_coefficiente_type ADC_coefficiente[]
Node normalizing coeficinets used in ADC_lettura_24bit()
Definition: Adc.c:210
volatile uint8_t ADC_sleep_off
if 0 ADC in sleep when not working, ADC>1 ADC never sleep
Definition: Adc.c:205
volatile bool ADC_non_leggi_lo_offset_se_true
if not necessary, the ADC input offset from buffer is not read
Definition: Adc.c:200
void ADC_selfcal_zero_scale(uint8_t up_down)
ADC self-calibration. ADC needs to be pre-selected.
Definition: Adc.c:296
unsigned int Radc_internal
Definition: Adc.c:980
void ADC_sleep_ON_OFF(uint8_t up_down, uint8_t ON_OFF_NOP)
ADC is set to sleep or awake.
Definition: Adc.c:350
unsigned int Rmultiplexer
This is the multiplexer resistor and the series resistor connected in series to it.
Definition: Adc.c:981