CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
Trimmer.c
Go to the documentation of this file.
1
2
3#include "tutti_gli_header.h"
4
5
6/*****DOCUMENTAZIONE DOXYGEN (premi il - a sinistra per ridurla a icona) il manuale html \'e nella cartella************/
7/// \file
8
9/*!
10\page Trimmer_page Trimmer
11\brief <span style="color:red;"> <b> Trimmer managing </b> </span>
12*\tableofcontents
13
14 \b SUMMARY:
15*\arg \ref introduction_to_trimmer
16*\arg \ref a_bit_inside
17*\arg \ref Preamplifier_Slope_measure
18*\arg \ref Conclusion
19
20
21*\section introduction_to_trimmer Trimmer usage
22<hr width="90%" size="10" align="left">
23
24\n Trimmers are used for setting the detector bias, the preamplifier offset and the preamplifier thermal drift
25and the gain of the trimmer based PGA. The trimmer used is the
26<a href="./File_pdf/AD5263.pdf" target=_blank><b>AD5263 datasheet</b></a>, a quad trimmer whose schematic diagram is in figure \ref Figure_Trimmer_AD5263_trimmer.
27To manage the stuffs we have 3 main functions, quite similar: preamplifier_scrittura_lettura_trimmer(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_1_leggi_0 ),
28 detector_scrittura_lettura_trimmer_bias(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_1_leggi_0)
29 and trimmer_based_PGA().
30We have a sort of tree: it needs to identify the board, the channel, the trimmer and the value to write, if we need to write, otherwise we read the content; reading writing is established
31with the boolean \b scrivi_1_leggi_0.
32\n For detector and preamplifier the 4 trimmers of the chip have different functions. For what concern the preamplifier we have that
33(the bullet number is the addresss inside the chip):
34
35<ol start="0">
36 <li> #trimmer_CMRR_compensation;
37 <li> #trimmer_fine_offset;
38 <li> #trimmer_thermal_compensation;
39 <li> #trimmer_coarse_offset.
40 </li>
41</ol>
42
43Whereas for detector trimmer:
44
45<ol start="0">
46 <li> #Detector_trimmer_coarse_bias_pos
47 <li> #Detector_trimmer_coarse_bias_neg
48 <li> #Detector_trimmer_fine_bias_pos
49 <li> #Detector_trimmer_fine_bias_neg
50 </li>
51</ol>
52
53\n The content of every trimmer is stored in matrixes: #contenuto_trimmer_detector,
54#contenuto_trimmer_preamplifier and #contenuto_trimmer_PGA_a_trimmer.
55They are listed here with their default values:
56
57*\snippet Trimmer.c matrix_contenuto_trimmer_detector
58
59*\snippet Trimmer.c matrix_contenuto_trimmer_preamplifier
60
61For the caseof the trimmer based PGA the number of trimmers used for the 12 channles is 6, one every 2 channels:
62
63*\snippet Trimmer.c matrix_contenuto_trimmer_PGA_a_trimmer
64
65*\anchor Figure_Trimmer_AD5263_trimmer
66*\image html Trimmer_AD5263.png "FigureTrimmer_AD5263: simplified" width=30%
67*\image latex Trimmer_AD5263.png "FigureTrimmer_AD5263: simplified" width=30%
68
69\n Although not necessary for its direct usage, let's give a bit of further details. Every trimmer chip is selectd by mean of a constant struct with which it is possible to select
70both the I2C and its I2C address:
71
72*\snippet Trimmer.h fun_address_detector_bias_trimmer_type
73
74First of all the I2C, the I2C mux and which of the 4 I2C mux output channels must be selcted with
75I2C_mux_select_ch( uint8_t scheda_su_scheda_giu, uint8_t mainboard_postmainboard , uint8_t canale_da_abilitare)
76
77*\section a_bit_inside A few details about the functions
78<hr width="90%" size="10" align="left">
79
80\n We have the 2 constant structures for trimmer selection #address_detector_bias_trimmer and #address_preamplifier_trimmer.
81The structures are used within the functions
82preamplifier_scrittura_lettura_trimmer() and detector_scrittura_lettura_trimmer_bias(). Here an example:
83*\snippet Trimmer.c fun_detector_scrittura_lettura_trimmer_bias
84
85\anchor pre_trim_slope
86*\section Preamplifier_Slope_measure Preamplifier Slope measurement
87<hr width="90%" size="10" align="left">
88
89\n Offset regulation of preamplifier is based on 2 trimmers, a coarse and fine trimmer. The adjustment can be done
90by SAR tecnique or by setting the propoer value of the trimmers, if it is known their effects. The in-between
91solution is to set the value of the trimmers at a guess value, then use the SAR for a few bits.
92The function is quite long and reported here instr_offset_trimmer_calibration_function().
93
94
95\n Once that the slope has been measured it is stored in the preamplifier EPROM. The 2 slopes are stored at 2
96locations preceded by a location that says if the slopes have been characterized (the complete list is
97at \ref preamplifier_memory_location_list "Preamplifier EPROM location list"):
98
99<ol start="1">
100 <li> #Memory_preamplifier_slope_calibration_ON_0_OFF_ff;
101 <li> #Memory_preamplifier_address_fine_trimmer_slope_offset;
102 <li> #Memory_preamplifier_address_coarse_trimmer_slope_offset;
103 </li>
104</ol>
105
106
107\n Namely if #Memory_preamplifier_slope_calibration_ON_0_OFF_ff is 0xFF, the initial default, the following 2 locations are not usable
108because not set. If #Memory_preamplifier_slope_calibration_ON_0_OFF_ff is 0, then the 2 following location have been
109characterized and are usable. In this latter case the slopes stored could be either the actual value measured or
110the nominal value if, during characterizatin, the measured values resulted outside &plusmn; 20\% of tolerance
111with respect to the nominla value.
112
113*\section Conclusion Conclusion
114<hr width="90%" size="10" align="left">
115
116\n Refer to \ref Detector_Bias "Detector Bias" and \ref Preamplifier_Offset_Drift_Correcttion_page "Preamplifier Offset Drift Correcttion" for trimmer usage.
117
118 The code for mamnaging the trimmers is at:
119 - \ref Trimmer.c
120 - \ref Trimmer.h
121*/
122
123//static ARM_DRIVER_I2C * I2CBdrv ; // Viene inizializzata in I2C_B
124
125//INIZIO CROSS
127// uint8_t quale_I2C;
128// uint8_t indirizzo_I2C
134 I2C_mux_abilita_2,I2C_address_ch_pari}; ///< Detector trimmer addresses
135
137// uint8_t quale_I2C;
138// uint8_t indirizzo_I2C
142 I2C_mux_abilita_1, I2C_address_ch_pari-2, /*I2C_address_ch_pari-2*/
144 I2C_mux_abilita_2,I2C_address_ch_pari-2}; ///< Preamplifier trimmer addresses
145
147// uint8_t quale_I2C;
148// uint8_t indirizzo_I2C
152 I2C_mux_abilita_1, I2C_addres_trimmer_PGA, /*I2C_address_ch_pari-2*/
154 I2C_mux_abilita_2,I2C_addres_trimmer_PGA}; ///< Preamplifier trimmer addresses
155
156//! \brief Content of the trimmer for detector bias system
157/*
158*\snippet{lineno} Trimmer.c matrix_contenuto_trimmer_detector
159 */
160 //! <!-- [matrix_contenuto_trimmer_detector] -->
161uint8_t contenuto_trimmer_detector[12][4]={ 128, 128, 128, 128, //!< Scheda gi\'u
162 128, 128, 128, 128,
163 128, 128, 128, 128,
164 128, 128, 128, 128,
165 128, 128, 128, 128,
166 128, 128, 128, 128,
167 128, 128, 128, 128, ///< Scheda su
168 128, 128, 128, 128,
169 128, 128, 128, 128,
170 128, 128, 128, 128,
171 128, 128, 128, 128,
172 128, 128, 128, 128};///< Detetctor bias trimmer content. Default value is half scale
173//! <!-- [matrix_contenuto_trimmer_detector] -->
174
175/*
176*\snippet{lineno} Trimmer.c matrix_contenuto_trimmer_preamplifier
177 */
178 //! <!-- [matrix_contenuto_trimmer_preamplifier] -->
179uint8_t volatile contenuto_trimmer_preamplifier[12][4]={ 128, 128, 128, 128, //Scheda gi\'u
180 128, 128, 128, 128,
181 128, 128, 128, 128,
182 128, 128, 128, 128,
183 128, 128, 128, 128,
184 128, 128, 128, 128,
185 128, 128, 128, 128, //Scheda su
186 128, 128, 128, 128,
187 128, 128, 128, 128,
188 128, 128, 128, 128,
189 128, 128, 128, 128,
190 128, 128, 128, 128}; ///< Preamplifier trimmers contents
191 //! <!-- [matrix_contenuto_trimmer_preamplifier] -->
192
193
194//!< Trimmer are in default set at almost 1 gain
195//uint8_t volatile contenuto_trimmer_PGA_a_trimmer[6][4]={ 128, 128, 128, 128, //Scheda gi\'u
196// 128, 128, 128, 128,
197// 128, 128, 128, 128,
198// 128, 128, 128, 128, //Scheda su
199// 128, 128, 128, 128,
200// 128, 128, 128, 128}; ///< PGA a trimmer trimmers contents
201
202/*
203*\snippet{lineno} Trimmer.c matrix_contenuto_trimmer_PGA_a_trimmer
204 */
205 //! <!-- [matrix_contenuto_trimmer_PGA_a_trimmer] -->
206uint8_t volatile contenuto_trimmer_PGA_a_trimmer[6][4]={ 245, 245, 245, 245, //Scheda gi\'u
207 245, 245, 245, 245,
208 245, 245, 245, 245,
209 245, 245, 245, 245, //Scheda su
210 245, 245, 245, 245,
211 245, 245, 245, 245}; ///< PGA a trimmer trimmers contents
212 //! <!-- [matrix_contenuto_trimmer_PGA_a_trimmer] -->
213
214
215//!< State od attenuators at the PGA trimmer based inputs
216//!< A vlaue o 3 means attenuator ON, a value of 0 means attenuator OFF
217uint8_t volatile attenuatori_PGA_a_trimmer[12]={ 3,3,3,3, //Scheda gi\'u
218 3,3,3,3,
219 3,3,3,3}; ///< PGA a trimmer trimmers contents
220//uint8_t volatile attenuatori_PGA_a_trimmer[12]={ 0,0,0,0, //Scheda gi\'u
221// 0,0,0,0,
222// 0,0,0,0}; ///< PGA a trimmer trimmers contents
223
224
225 /*! \brief Setting the value of any trimmer for detector biasing, the contents of the trimmers are stored
226 in the matrix #contenuto_trimmer_detector[canale][trimmer]
227
228 *\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
229 *\param[in] canale the channel for which we need to manage the trimmer
230 *\param[in] trimmer the trimmer to select in the chip, from 0 to 3
231 *\param[in] valore the value to be written to.
232 *\param[in] scrivi_1_leggi_0 if 1 we write and read, if 0 we read only and the contenis in the global contenuto_trimmer_detector[canale][trimmer]
233 *\return No Parameters
234
235 *\snippet{lineno} Trimmer.c fun_detector_scrittura_lettura_trimmer_bias
236 */
237 //! <!-- [fun_detector_scrittura_lettura_trimmer_bias] -->
238void detector_scrittura_lettura_trimmer_bias(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_1_leggi_0 ){
239
240 //Attenzione: canale deve essere < 6
241
242 uint8_t spedizione[2]={ ( (trimmer << 5) & maschera_solo_bit_di_scrittura_trimmer), valore}; //The trimmer and what to write
243
244 if( scheda_su_scheda_giu) scheda_su_scheda_giu =6;
245
246
247 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, address_detector_bias_trimmer[canale].quale_I2C); //Select the I2C to be used
248
249 if (scrivi_1_leggi_0){
250
251 I2C_mux->MasterTransmit( (uint8_t) address_detector_bias_trimmer[canale].indirizzo_I2C , spedizione, 2,false); //Write to the selected trimmer of the selcted channel
252
253 }else{
254
255 I2C_mux->MasterTransmit( (uint8_t) address_detector_bias_trimmer[canale].indirizzo_I2C , spedizione, 1,false); //set the channel to read only
256 }
257
258 while( I2C_mux->GetStatus().busy){}; // Write transmission complete
260
261 I2C_mux->MasterReceive( address_detector_bias_trimmer[canale].indirizzo_I2C, &tappo, 1,false); //Read back, the trimmer value
262
263 while( I2C_mux->GetStatus().busy){};
264
265 contenuto_trimmer_detector[canale + scheda_su_scheda_giu][trimmer] = tappo; //Tappo is global
266}
267 //! <!-- [fun_detector_scrittura_lettura_trimmer_bias] -->
268
269
270 /*! \brief Setting the value of any trimmer for preamplifier trimmer, the contents of the trimmers are stored
271 in the matrix contenuto_trimmer_preamplifier[canale][trimmer]
272
273 *\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
274 *\param[in] canale the channel for which we need to manage the trimmer
275 *\param[in] trimmer the trimmer to select in the chip, from 0 to 3
276 *\param[in] valore the value to be written to.
277 *\param[in] scrivi_1_leggi_0 if 1 we write and read, if 0 we read only and the contenis in the global contenuto_trimmer_detector[canale][trimmer]
278 *\return No Parameters
279
280 *\snippetlineno Trimmer.c fun_preamplifier_scrittura_lettura_trimmer
281 */
282 //! <!-- [fun_preamplifier_scrittura_lettura_trimmer] -->
283void preamplifier_scrittura_lettura_trimmer(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, \
284 uint8_t valore, uint8_t scrivi_1_leggi_0 ){
285
286 if( scheda_su_scheda_giu >=1) scheda_su_scheda_giu=6;
287
288 uint8_t spedizione[2]={ ( (trimmer << 5) & maschera_solo_bit_di_scrittura_trimmer), valore}; //The trimmer and what to write
289
290 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, address_preamplifier_trimmer[canale].quale_I2C); //Select the I2C to be used
291
292 if (scrivi_1_leggi_0){
293
294 I2C_mux->MasterTransmit( (uint8_t) address_preamplifier_trimmer[canale].indirizzo_I2C , spedizione, 2,false); //Write to the selected trimmer of the selcted channel
295
296 }else{
297
298 I2C_mux->MasterTransmit( (uint8_t) address_preamplifier_trimmer[canale].indirizzo_I2C , spedizione, 1,false); //set the channel to read only
299 }
300
301 while( I2C_mux->GetStatus().busy){}; // Write transmission complete
302
303 I2C_mux->MasterReceive( address_preamplifier_trimmer[canale].indirizzo_I2C, &tappo, 1,false); //Read back, the trimmer value
304
305 while( I2C_mux->GetStatus().busy){};
307
308 contenuto_trimmer_preamplifier[canale + scheda_su_scheda_giu][trimmer] = tappo;
309}
310 //! <!-- [fun_preamplifier_scrittura_lettura_trimmer] -->
311
312
313 /*! \brief The fine and coarse trimmers for offset adjustment are calibrated here
314
315 *\return No Parameters
316
317 *\snippetlineno Trimmer.c fun_instr_offset_trimmer_calibration_function
318 */
319 //! <!-- [fun_instr_offset_trimmer_calibration_function] -->
321 uint8_t canale,internalADC_0_externalADC_1=(tx_data[4] & 1), canale_selezionato=10;
322 uint8_t trimmer_old[4], PGA_Gain_old[12], trimmer_fine_test, trimmer_coarse_test;
323 uint8_t *dati_da_scrivere,dati_da_leggere[]={0,0,0,0};
324 //convertiamo i valori di riferimento
325 int32_t pendenza_fine=0,pendenza_coarse=0,trimmer_riferimento_fine = (*(uint16_t *)&tx_data[0]);//fine trimmer in microV
326 int32_t ADC_misura_fatta_first,ADC_misura_fatta_last,trimmer_riferimento_coarse= (*(uint16_t *)&tx_data[2] ) *10;//Coarse trimmer in unit\'a di 10^5
327 ERROR_codifica_errore(0,0,0,0); //Reset_ch0 errori
328 //Detrminare il canale da calibrare
329 scheda_su_scheda_giu = ((tx_data[6] >> 7) & 1)*6;
331 for(canale=0;canale<6;canale++){
332 if((tx_data[6]>>canale)&1){
333 canale_selezionato=canale;
334 break;
335 }
336 }
337 //Memorizzare il valore dei trimmer, da poterer poi ristabilire
338 for(canale=0;canale<4;canale++){
339 trimmer_old[canale]=contenuto_trimmer_preamplifier[canale_selezionato+scheda_su_scheda_giu][canale];
340 }
341 //Impostare il gain a 1
342 for(canale=0;canale<6;canale++){
343 PGA_Gain_old[canale]=PGA_settled_gain[canale + scheda_su_scheda_giu];
344 PGA_GAIN_CROSS( scheda_su_scheda_giu, canale, 1 );
345 }
346 //Verificre che l'offset sia in una scala opportuna
347// if(internalADC_0_externalADC_1){
348// //lettura con ADC exsterno
349// ADC_misura_fatta_first = preamplifier_ADC_external_measured_node_function(scheda_su_scheda_giu ,node_voltage_PGA_ch_0 + \
350// canale_selezionato+scheda_su_scheda_giu);
351// ERROR_codifica_errore(scheda_su_scheda_giu, error_address_reg_ADC0 , ADC_external_fails , 1);
352// }else{
353// //lettura con adc interno
354// ADC_misura_fatta_first = ADC_lettura(scheda_su_scheda_giu, node_voltage_PGA_ch_0 + \
355// canale_selezionato+scheda_su_scheda_giu, 1);
356// ERROR_codifica_errore(scheda_su_scheda_giu, error_address_reg_ADC0 , ADC_internal_General_fails , 1);
357// }
358 ADC_misura_fatta_first = ADC_misura_differenziale_con_media_generico(scheda_su_scheda_giu,internalADC_0_externalADC_1,node_voltage_PGA_ch_0 + canale_selezionato, 1);
359 //se l'offset non \'e in scala non viene fatto nessun calcolo.
360 if( (ADC_misura_fatta_first > trimmer_max_voltage_per_trimmer_calibration) || \
361 (ADC_misura_fatta_first <-trimmer_max_voltage_per_trimmer_calibration)){
362 //Offset troppo grande
363 tx_data[5]=4;
364 }else{
365 //facciamo i conti
366 //loop per la calibrazione dei 2 trimmer
367 if(tx_data[5] & 1){//Calibrazione trimmer fine
368 // cambiare il trimmer fine di un po'
369 if(trimmer_old[trimmer_fine_offset] >128){
370 trimmer_fine_test= 0;
371 }else{
372 trimmer_fine_test =255;
373 }
374 preamplifier_scrittura_lettura_trimmer( scheda_su_scheda_giu, canale_selezionato, \
376 Aspetta_tanti_ms( 500);
377// if(internalADC_0_externalADC_1){
378// ADC_misura_fatta_last = preamplifier_ADC_external_measured_node_function(scheda_su_scheda_giu, node_voltage_PGA_ch_0 + \
379// canale_selezionato+scheda_su_scheda_giu);
380// }else{
381// ADC_misura_fatta_last = ADC_lettura(scheda_su_scheda_giu, node_voltage_PGA_ch_0 + canale_selezionato+scheda_su_scheda_giu, 1);
382// }
383 ADC_misura_fatta_last = ADC_misura_differenziale_con_media_generico(scheda_su_scheda_giu,internalADC_0_externalADC_1,node_voltage_PGA_ch_0 + canale_selezionato, 1);
384
385 pendenza_fine = (ADC_misura_fatta_first - ADC_misura_fatta_last) \
386 /(trimmer_old[trimmer_fine_offset] - trimmer_fine_test);
387 if( (pendenza_fine > ((trimmer_riferimento_fine *12)/10)) \
388 || (pendenza_fine <((trimmer_riferimento_fine *10)/12) )){
389 //Misura anadata a male, prendiamo il default
390 pendenza_fine = trimmer_riferimento_fine;
391 tx_data[5] -= 1; //Togliamo perch\'e non \'e andato bene
392 }
393 //memorizzare il valore nella eprom se \'e in tolleranza
394 dati_da_scrivere= (uint8_t *)&pendenza_fine;
395 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (Memory_preamplifier_address_fine_trimmer_slope_offset << 2) , dati_da_scrivere);
396 ADC_misura_fatta_first = ADC_misura_fatta_last; //Se si misura anche il coarse questa \'e l'ultima misura valida
397 EPROM_lettura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff << 2) , dati_da_leggere);
398 if(dati_da_leggere[0]>3){ //If it the first time it is read the content of the register is 0xff
399 dati_da_leggere[0]=1; //1 means that the fine slope is stored
400 }else{
401 dati_da_leggere[0] |=1; //It maybe that the coars was already measured. Here we add the information about this slope, the 1
402 }
403 dati_da_leggere[1]=0;dati_da_leggere[2]=0;dati_da_leggere[3]=0;
404 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff << 2) , dati_da_leggere);
405 }
406 if( tx_data[5] & 2){
407 // cambiare il trimmer coarse di 4 passi e misurare di nuovo, se si vuole calcolare questa
408 if(trimmer_old[trimmer_coarse_offset] >128){
409 trimmer_coarse_test= trimmer_old[trimmer_coarse_offset] -4;
410 }else{
411 trimmer_coarse_test =trimmer_old[trimmer_coarse_offset] +4;
412 }
413 preamplifier_scrittura_lettura_trimmer( scheda_su_scheda_giu, canale_selezionato, \
415 Aspetta_tanti_ms( 500);
416// if(internalADC_0_externalADC_1){
417// ADC_misura_fatta_last = preamplifier_ADC_external_measured_node_function(scheda_su_scheda_giu, node_voltage_PGA_ch_0 + \
418// canale_selezionato+scheda_su_scheda_giu);
419// }else{
420// ADC_misura_fatta_last = ADC_lettura(scheda_su_scheda_giu, node_voltage_PGA_ch_0 + canale_selezionato+scheda_su_scheda_giu , 1);
421// }
422 ADC_misura_fatta_last = ADC_misura_differenziale_con_media_generico(scheda_su_scheda_giu,internalADC_0_externalADC_1,node_voltage_PGA_ch_0 + canale_selezionato, 1);
423
424 pendenza_coarse = (ADC_misura_fatta_first - ADC_misura_fatta_last) \
425 /(trimmer_old[trimmer_coarse_offset] - trimmer_coarse_test);
426 if( (pendenza_coarse > ((trimmer_riferimento_coarse *12)/10)) \
427 || (pendenza_coarse <((trimmer_riferimento_coarse *10)/12) )){
428 //Misura anadata a male, prendiamo il default
429 pendenza_coarse = trimmer_riferimento_coarse;
430 tx_data[5] -= 2; //Togliamo perch\'e non \'e andato bene
431 }
432 //memorizzare il valore nella eprom se \'e in tolleranza
433 dati_da_scrivere= (uint8_t *)&pendenza_coarse;
434 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (Memory_preamplifier_address_coarse_trimmer_slope_offset <<2) , dati_da_scrivere);
435
436 EPROM_lettura_M24C32_64( scheda_su_scheda_giu,I2C_mainboard, canale_selezionato, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff << 2) , dati_da_leggere);
437 if(dati_da_leggere[0]>3){ //If it the first time it is read the content of the register is 0xff
438 dati_da_leggere[0]=2; //2 means that the fine slope is stored
439 }else{
440 dati_da_leggere[0] |=2; //It maybe that the coars was already measured. Here we add the information about this slope, the 2
441 }
442 dati_da_leggere[1]=0;dati_da_leggere[2]=0;dati_da_leggere[3]=0;
443 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff << 2) , dati_da_leggere);
444 }
445 }
446 EPROM_lettura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff << 2) , dati_da_leggere);
447 if(dati_da_leggere[0]==3){
448 dati_da_leggere[0]=0;
449 dati_da_leggere[1]=0;dati_da_leggere[2]=0;dati_da_leggere[3]=0;
450 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff << 2) , dati_da_leggere);
451 }
452 // ritornare il valore misurato nella istruzione can
453 pendenza_fine = pendenza_fine;
454 tx_data[0]= pendenza_fine & 0xff;
455 tx_data[1] =(pendenza_fine >> 8) & 0xff;
456 pendenza_coarse = pendenza_coarse /10 ;
457 tx_data[2]= pendenza_coarse & 0xff;
458 tx_data[3]= ( pendenza_coarse >> 8) & 0xff;
459 //ristabilire i trimmer.
460 for(canale=0;canale<4;canale++){
461 preamplifier_scrittura_lettura_trimmer( scheda_su_scheda_giu, canale_selezionato, \
462 canale, trimmer_old[canale], preamplifier_scrivi_il_trimmer );
463 }
464 //Ristabilire il guadagno
465 for(canale=0;canale<6;canale++){
466 PGA_GAIN_CROSS( scheda_su_scheda_giu, canale, PGA_Gain_old[canale] );
467 }
469}
470 //! <!-- [fun_instr_offset_trimmer_calibration_function] -->
471
472
473 /*! \brief The fine and coarse trimmers for Detector bias adjustment are calibrated here
474
475 *\return No Parameters
476
477 *\snippetlineno Trimmer.c fun_instr_DetBias_trimmer_calibration_function
478 */
479 //! <!-- [fun_instr_DetBias_trimmer_calibration_function] -->
481 uint8_t canale,internalADC_0_externalADC_1=(tx_data[4] & 1), canale_selezionato=10;
482 uint8_t trimmer_old[4], PGA_Gain_old[12], trimmer_fine_test, trimmer_coarse_test;
483 uint8_t *dati_da_scrivere,dati_per_switch[]={0,0,0,0}, delta_trimmer, divisore;
484 int32_t target_slope = *(int32_t *)tx_data, tampone;
485 //convertiamo i valori di riferimento
486 int32_t pendenza[]={0,0,0,0,},trimmer_riferimento_fine = (*(uint16_t *)&tx_data[0]);//fine trimmer in microV
487 int32_t ADC_misura_fatta_first[]={0,0,0,0},ADC_misura_fatta_last[]={0,0,0,0}, risul_vof;//Coarse trimmer in unit\'a di 10^5
489 //Detrminare il canale da calibrare
490 scheda_su_scheda_giu = ((tx_data[6] >> 7) & 1)*6;
491 for(canale=0;canale<6;canale++){
492 if((tx_data[6]>>canale)&1){
493 canale_selezionato=canale;
494 break;
495 }
496 }
497
498 //Vettori corrispondenze
499 typedef struct {
500 uint8_t trimmer; //Il trimmer da modificare
501 uint16_t memoria_trimmer; //la cella di memoria dove star\'a la pendenza
502 uint16_t memoria_switch_trimmer; //la cella di memoria che certifa la presenza della calibrazione
503 int32_t segno_uscita; //Coefficiente per la variazione del segnale di uscita
504 uint8_t nodo_lettura; //il nodo di tensione da leggere
505 }trimmer_da_lavorare_;
506
511
512//Preamplifier memory contents regarding detector trimmer slopes are copied in the mainboard memory or restored.
513//This is a patch: the storing of these data in the preamplifier memoery is unnecessary, but it was done.
514//So now the content of the preamplifier memory is done also in the mainboard memory at the time of the slopes measurements.
515//These data are restored in the preamplifier memory at startup so that if the preamplifier is changed the slopes are not lost.
516 trimmer_da_lavorare_ trimmer_da_lavorare_mainboard_CH0[]={
521
522 uint8_t ii, trimmer_coarse_o_fine=10; //inizializzazione ad un valore abnorme
523
524
525//L'offset da considerare in trimmer_da_lavorare per selezionare la coppia di trimmer giusti, i 2 coarse o i 2 fine.
526 if( tx_data[5]==1){
527 trimmer_coarse_o_fine=2;
528 delta_trimmer=100;
529 divisore=1;
530 }else if (tx_data[5]==2){
531 trimmer_coarse_o_fine=0;
532 delta_trimmer=10;
533 divisore=10;
534 }
535
536
537//Condizioni iniziale da ristabilire
538 //Memorizzare il valore dei trimmer, da poterer poi ristabilire ed impostiamo la met\'a scala
539 for(canale=0;canale<4;canale++){
540 trimmer_old[canale]=contenuto_trimmer_detector[canale_selezionato+scheda_su_scheda_giu][canale];
541 detector_scrittura_lettura_trimmer_bias(scheda_su_scheda_giu, canale_selezionato, canale, 128, 1);
542 }
543 //Impostare il gain a 1
544 for(canale=0;canale<6;canale++){
545 PGA_Gain_old[canale]=PGA_settled_gain[canale + scheda_su_scheda_giu];
546 PGA_GAIN_CROSS( scheda_su_scheda_giu, canale, 1 );
547 }
548
549 //Qui calibriamo
550 //Misuriamo a met\'a scala
551 Aspetta_tanti_ms(500);
552 for(ii= trimmer_coarse_o_fine; ii<(2+trimmer_coarse_o_fine);ii++){
553 ADC_misura_fatta_first[ii] = ADC_misura_differenziale_con_media_generico(scheda_su_scheda_giu,internalADC_0_externalADC_1,trimmer_da_lavorare[ii].nodo_lettura,0);
554
555 detector_scrittura_lettura_trimmer_bias(scheda_su_scheda_giu, canale_selezionato, trimmer_da_lavorare[ii].trimmer, \
556 128+trimmer_da_lavorare[ii].segno_uscita*delta_trimmer, 1);
557 }
558 Aspetta_tanti_ms(500);
559 for(ii= trimmer_coarse_o_fine; ii<(2+trimmer_coarse_o_fine);ii++){
560 ADC_misura_fatta_last[ii] = ADC_misura_differenziale_con_media_generico(scheda_su_scheda_giu,internalADC_0_externalADC_1,trimmer_da_lavorare[ii].nodo_lettura,0);
561 }
562 for(ii= trimmer_coarse_o_fine; ii<(2+trimmer_coarse_o_fine);ii++){
563 pendenza[ii]=( (ADC_misura_fatta_last[ii] - ADC_misura_fatta_first[ii]) * (trimmer_da_lavorare[ii].segno_uscita ) )/ ( (int)delta_trimmer) ;
564 tampone = ((int)100*pendenza[ii]) / target_slope;
565 if (target_slope){ //If target_slope is passed 0 there is no comparison
566 if ( (tampone >130) || (tampone<70)){
567 //valore non in tolleranza
568 pendenza[ii]=target_slope;
569 tx_data[5]=3 + ii -trimmer_coarse_o_fine;
570 }
571 }
572 }
573 //memorizzare il valore nella eprom se \'e in tolleranza
574 for(ii= trimmer_coarse_o_fine; ii<(2+trimmer_coarse_o_fine);ii++){
575 dati_da_scrivere= (uint8_t *)&pendenza[ii];
576 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu,I2C_mainboard, canale_selezionato, (trimmer_da_lavorare[ii].memoria_trimmer <<2) , dati_da_scrivere);
577 //We store also in the mainboard EPROM, to be restored in the preamplifier memory at startup
578 EPROM_scrittura_M24C32_64(scheda_su_scheda_giu,I2C_mainboard, Canale_Eprom_mainboard,\
579 ((trimmer_da_lavorare_mainboard_CH0[ii].memoria_trimmer+6*canale_selezionato) <<2), dati_da_scrivere);
580 dati_per_switch[0]=0;
581 if( tx_data[5] >2){
582 dati_per_switch[0]=0xFF;
583 }
584 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, canale_selezionato, (trimmer_da_lavorare[ii].memoria_switch_trimmer << 2) , dati_per_switch);
585 //We store also in the mainboard EPROM, to be restored in the preamplifier memory at startup
586 EPROM_scrittura_M24C32_64(scheda_su_scheda_giu,I2C_mainboard, Canale_Eprom_mainboard,\
587 ((trimmer_da_lavorare_mainboard_CH0[ii].memoria_switch_trimmer+6*canale_selezionato) <<2), dati_per_switch);
588 }
589 pendenza[ trimmer_coarse_o_fine] = (pendenza[ trimmer_coarse_o_fine] / divisore );
590 tx_data[0]= (pendenza[ trimmer_coarse_o_fine] )& 0xff;
591 tx_data[1] =(( pendenza[ trimmer_coarse_o_fine] )>>8)& 0xff;
592 pendenza[ trimmer_coarse_o_fine+1]= (pendenza[ trimmer_coarse_o_fine+1] / divisore );
593 tx_data[2]= (pendenza[ trimmer_coarse_o_fine+1] )& 0xff;
594 tx_data[3]=( ( pendenza[ trimmer_coarse_o_fine+1])>>8)& 0xff;
595 tx_data[4]= divisore;
596//E qui riportiamo tutto come prima
597 //ristabilire i trimmer.
598 for(canale=0;canale<4;canale++){
599 detector_scrittura_lettura_trimmer_bias( scheda_su_scheda_giu, canale_selezionato, \
600 canale, trimmer_old[canale], Detector_scrivi_il_trimmer );
601 }
602 //Ristabilire il guadagno
603 for(canale=0;canale<6;canale++){
604 PGA_GAIN_CROSS( scheda_su_scheda_giu, canale, PGA_Gain_old[canale] );
605 }
606
607}
608 //! <!-- [fun_instr_DetBias_trimmer_calibration_function] -->
609
610//Fine CROSS
611
612/******************************************************************************
613Variabili
614*******************************************************************************/
615struct trimmer_type /*{
616// signed short fine_thermal;
617 signed short JFET_Offset;
618 signed short fine_offset;
619 signed short coarse_thermal;
620 signed short coarse_offset;
621}*/ Trimmer_offset_preampli[]={0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80};
622
624 signed short JFET_COLD[2];
625 signed short CMRR[2];
626} */ Trimmer_CMRR_JFET_COLD={0x80,0x80,0x80,0x80};
627
628
629int coarse_Trimmer_offset_step_actual[]={coarse_Trimmer_offset_step,coarse_Trimmer_offset_step};
630int fine_Trimmer_offset_step_actual[]={fine_Trimmer_offset_step,fine_Trimmer_offset_step};
631int fine_Trimmer_thermal_step_actual[]={fine_Trimmer_thermal_step,fine_Trimmer_thermal_step};
632int coarse_Trimmer_thermal_step_actual[]={coarse_Trimmer_thermal_step,coarse_Trimmer_thermal_step};
633int reference_thermal_drift_actual=reference_thermal_drift;
634char numero_offset_per_impostazione_deriva[]= {17,17}; //Numero di impostazioni dell'offset per la deriva nella EPROM. Il default \'e 17
635char numero_temperature_impostazione_deriva[]= {9,9};
636unsigned char coefficiente_termico_trimmer_deriva[]= {200,200};
637signed char valori_offset_per_impostazione_deriva[2][20];
638unsigned char valori_temperature_impostazione_deriva[2][12];
639char temperatura_di_lavoro[2];
640char offset_di_lavoro[2];
641
642/******************************************************************************
643 Imposta_wiper_a_meta_scala_canale_0_I2CA
644*******************************************************************************/
645void Imposta_wiper_a_meta_scala_canale_0_I2CA( void )
646{
647 uint8_t addr = 0x2D; // 0101101 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
648 uint8_t dati_scrittura[2];
649 dati_scrittura[0] = 0<<5; // Viene impostato il trimmer 0
650 dati_scrittura[1] = 0x80; // Viene mandato il dato 128 che \'e met\'a scala
651
652 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
653 while (I2CAdrv->GetStatus().busy);
654
655 dati_scrittura[0] = 1<<5; // Viene impostato il trimmer 1
656 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
657 while (I2CAdrv->GetStatus().busy);
658
659 dati_scrittura[0] = 2<<5; // Viene impostato il trimmer 2
660 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
661 while (I2CAdrv->GetStatus().busy);
662
663 dati_scrittura[0] = 3<<5; // Viene impostato il trimmer 3
664 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
665 while (I2CAdrv->GetStatus().busy);
666}
667
668
669/******************************************************************************
670 Imposta_wiper_a_meta_scala_canale_1_I2CA
671*******************************************************************************/
672void Imposta_wiper_a_meta_scala_canale_1_I2CA( void )
673{
674 uint8_t addr = 0x2F; // 0101111 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
675 uint8_t dati_scrittura[2];
676 dati_scrittura[0] = 0<<5; // Viene impostato il trimmer 0
677 dati_scrittura[1] = 0x80; // Viene mandato il dato 128 che \'e met\'a scala
678
679 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
680 while (I2CAdrv->GetStatus().busy);
681
682 dati_scrittura[0] = 1<<5; // Viene impostato il trimmer 1
683 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
684 while (I2CAdrv->GetStatus().busy);
685
686 dati_scrittura[0] = 2<<5; // Viene impostato il trimmer 2
687 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
688 while (I2CAdrv->GetStatus().busy);
689
690 dati_scrittura[0] = 3<<5; // Viene impostato il trimmer 3
691 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
692 while (I2CAdrv->GetStatus().busy);
693}
694
695
696/******************************************************************************
697 Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA
698*******************************************************************************/
699void Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (uint8_t numero_canale, uint8_t numero_trimmer, uint8_t valore_dato)
700{
701 uint8_t addr;
702 uint8_t dati_scrittura[2];
703
704 if(numero_canale == 0) // 0101101 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
705 {
706 addr = I2C_addres_trimmer_pre_ch0;
707 }
708 if(numero_canale == 1)
709 {
710 addr = I2C_addres_trimmer_pre_ch1; // 0101111 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
711 }
712
713 dati_scrittura[0] = numero_trimmer<<5; // Viene usato il trimmer specificato
714 dati_scrittura[1] = valore_dato; // Viene mandato il dato
715
716 I2CAdrv->MasterTransmit (addr, dati_scrittura, 2, false);
717 while (I2CAdrv->GetStatus().busy);
718}
719
720
721void Imposta_trimmer_common_mode_I2CB ( uint8_t numero_trimmer, uint8_t valore_dato)
722{
723 uint8_t addr;
724 uint8_t dati_scrittura[2];
725
726
727 addr = I2C_addres_trimmer_common_mode_cold ;
728
729
730 dati_scrittura[0] = numero_trimmer<<5; // Viene usato il trimmer specificato
731 dati_scrittura[1] = valore_dato; // Viene mandato il dato
732
733 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
734 while (I2CBdrv->GetStatus().busy);
735}
736
737/******************************************************************************
738 Imposta_wiper_a_meta_scala_canale_0_I2CB
739*******************************************************************************/
740void Imposta_wiper_a_meta_scala_canale_0_I2CB( void )
741{
742 uint8_t addr = 0x2D; // 0101101 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
743 uint8_t dati_scrittura[2];
744 dati_scrittura[0] = 0<<5; // Viene impostato il canale del trimmer 0
745 dati_scrittura[1] = 0x80; // Viene mandato il dato 128 che \'e met\'a scala
746
747 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
748 while (I2CBdrv->GetStatus().busy);
749
750 dati_scrittura[0] = 1<<5; // Viene impostato il canale del trimmer 1
751 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
752 while (I2CBdrv->GetStatus().busy);
753
754 dati_scrittura[0] = 2<<5; // Viene impostato il canale del trimmer 2
755 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
756 while (I2CBdrv->GetStatus().busy);
757
758 dati_scrittura[0] = 3<<5; // Viene impostato il canale del trimmer 3
759 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
760 while (I2CBdrv->GetStatus().busy);
761}
762
763
764/******************************************************************************
765 Imposta_wiper_a_meta_scala_canale_1_I2CB
766*******************************************************************************/
767void Imposta_wiper_a_meta_scala_canale_1_I2CB( void )
768{
769 uint8_t addr = 0x2C; // 0101100 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
770 uint8_t dati_scrittura[2];
771 dati_scrittura[0] = 0<<5; // Viene impostato il trimmer 0
772 dati_scrittura[1] = 0x80; // Viene mandato il dato 128 che \'e met\'a scala
773
774 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
775 while (I2CBdrv->GetStatus().busy);
776
777 dati_scrittura[0] = 1<<5; // Viene impostato il trimmer 1
778 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
779 while (I2CBdrv->GetStatus().busy);
780
781 dati_scrittura[0] = 2<<5; // Viene impostato il trimmer 2
782 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
783 while (I2CBdrv->GetStatus().busy);
784
785 dati_scrittura[0] = 3<<5; // Viene impostato il trimmer 3
786 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
787 while (I2CBdrv->GetStatus().busy);
788}
789
790
791/******************************************************************************
792 Imposta_canale_del_trimmer_ennesimo_al_valore_I2CB
793*******************************************************************************/
794void Imposta_canale_del_trimmer_ennesimo_al_valore_I2CB (uint8_t numero_canale, uint8_t numero_trimmer, uint8_t valore_dato)
795{
796 uint8_t addr;
797 uint8_t dati_scrittura[2];
798
799 if(numero_canale == 0) // 0101101 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
800 {
801 addr = I2C_addres_trimmer_bias_ch0;
802 }
803 if(numero_canale == 1)
804 {
805 addr = I2C_addres_trimmer_bias_ch1; // 0101100 indirizzo a 7 bit (il bit di lettura e scrittura viene messo in automatico)
806 }
807
808 dati_scrittura[0] = numero_trimmer<<5; // Viene usato il trimmer specificato
809 dati_scrittura[1] = valore_dato; // Viene mandato il dato
810
811 I2CBdrv->MasterTransmit (addr, dati_scrittura, 2, false);
812 while (I2CBdrv->GetStatus().busy);
813}
814
815
816 /*****************************************************************************
817 Arrotonda
818 ******************************************************************************/
819long int Arrotonda(float temp)
820{
821 long int valore_finale;
822
823 if(temp>0)
824 {
825 if(temp - (long int) temp >=0.5)
826 {
827 valore_finale = (long int) temp + 1;
828 }
829 else
830 {
831 valore_finale = (long int) temp;
832 }
833 }
834 else
835 {
836 if(-(temp - (long int) temp )>=0.5)
837 {
838 valore_finale = (long int) temp - 1;
839 }
840 else
841 {
842 valore_finale = (long int) temp;
843 }
844 }
845return valore_finale;
846}
847
848
849 /****************************************************************************************
850 Trova_valori_trimmer_per_la_Vbias_del_rivelatore_per_la_tensione_in_uscita_uguale_a_vout
851 *****************************************************************************************/
852//void Trova_valori_trimmer_per_la_Vbias_del_rivelatore_per_la_tensione_in_uscita_uguale_a_vout (long int vout_, int16_t *Valori_per_i_trimmer, long int offset)
853//{
854// vout_ = vout_ - offset;
855//// float temp = -vout*128/1.03/5000;
856// float temp = -(float)vout_ / trimmer_bias_coarse_step;
857// long int x = Arrotonda(temp);
858//
859// int16_t Tr0, Tr1;
860// Tr0 = x + 128;
861
862//// summed because x is negated above.
863// temp = ( vout_ + x*trimmer_bias_coarse_step) / trimmer_bias_fine_step ;
864// Tr1 = Arrotonda(temp);
865// Tr1 = Tr1 + 128;
866
867//// long int tensione_out[1];
868//// tensione_out[0] = ( (Tr0-128) *(-1.03) + (Tr1-128)*(0.0117) )*5000/128;
869//
870// Valori_per_i_trimmer[0]= Tr0;
871// Valori_per_i_trimmer[1]= Tr1;
872// return;
873//}
874
875
876 /****************************************************************************************
877 Trova_valori_trimmer_per_offset_preamplificatore
878 *****************************************************************************************/
879void Trova_valori_trimmer_per_offset_preamplificatore (long int offset, struct trimmer_type *Valori_per_i_trimmer, int coarse_trimmer_step, int fine_trimmer_step)
880{
881// offset=offset;
882 int16_t Tr0, Tr1;
883
884 float temp = offset / coarse_trimmer_step;
885 Tr0 = Arrotonda(temp);
886
887
888 long int tensione_rimasta[1];
889 tensione_rimasta[0] = offset - coarse_Trimmer_offset_step * Tr0;
890
891 temp = tensione_rimasta[0] / fine_trimmer_step;
892 Tr1 = Arrotonda(temp);
893
894 Valori_per_i_trimmer->coarse_offset += Tr0;
895 if (Valori_per_i_trimmer->coarse_offset > 0xFF) Valori_per_i_trimmer->coarse_offset=0xFF;
896 if( Valori_per_i_trimmer->coarse_offset <0) Valori_per_i_trimmer->coarse_offset=0;
897 Valori_per_i_trimmer->fine_offset += Tr1;
898 if (Valori_per_i_trimmer->fine_offset > 0xFF) Valori_per_i_trimmer->fine_offset=0x80;
899 if(Valori_per_i_trimmer->fine_offset <0) Valori_per_i_trimmer->fine_offset=0x80;
900
901}
902
903
904
905
906 /****************************************************************************************
907 Trova_valori_trimmer_per_deriva_termica_preamplificatore
908 *****************************************************************************************/
909void Trova_valori_trimmer_per_deriva_termica_preamplificatore (long int deriva, int16_t *Valori_per_i_trimmer)
910{
911
912 float temp = deriva*2.7*256/5.1/2560*2;
913 long int x = Arrotonda(temp);
914
915 int16_t Tr0, Tr1;
916 Tr0 = x + 128;
917
918 long int tensione_rimasta[1];
919 tensione_rimasta[0] = deriva - 5.1*2560/2*x/2.7/256;
920
921 temp = tensione_rimasta[0]*470*256/5.1/2560*2;
922 x = Arrotonda(temp);
923
924 Tr1 = x;
925 Valori_per_i_trimmer[0] = Tr0;
926 Valori_per_i_trimmer[1]= Tr1+128;
927
928return;
929}
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 differenziale_1_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
volatile uint16_t ADC_medie_per_misura
the number of ADC readings to average, the maximum is 400
Definition: Adc.c:206
uint8_t tx_data[8]
Transmission data vector.
Definition: Can.c:321
void PGA_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t PGA_gain_to_set)
Here the 2 digital signals from the trimmer are exploited to set the gain of the input stage of the P...
Definition: DAC_PGA.c:109
uint8_t PGA_settled_gain[12]
PGA set gain.
Definition: DAC_PGA.c:95
#define Detector_trimmer_fine_bias_pos
#define Detector_trimmer_coarse_bias_pos
Definition: Detector_Bias.h:98
#define Detector_trimmer_fine_bias_neg
#define Detector_trimmer_coarse_bias_neg
Definition: Detector_Bias.h:99
#define Detector_scrivi_il_trimmer
Definition: Detector_Bias.h:94
void Error_imposta_la_istruzione(void)
Function to be located at the end of every instruction to mark the error, if any.
volatile uint32_t Error_bad_operation
exploited to mark the errors
void ERROR_codifica_errore(uint8_t scheda_su_scheda_giu, unsigned char error_addres, unsigned char code_to_shift, uint8_t reset_count_se_0)
If an error is found its flag is codified here.
@ I2C_error_trimmer_bias_0
trimmer_bias ch0
@ I2C_error_termometro_0
termometro ch0
@ error_address_I2C1_B
Error register B for I2C1
void I2C_mux_select_ch(uint8_t scheda_su_scheda_giu, uint8_t mainboard_postmainboard, uint8_t canale_da_abilitare)
The I2C mux.
Definition: I2C_mux.c:100
#define I2C_mux_abilita_2
Enable channel 2.
Definition: I2C_mux.h:27
#define I2C_mux_abilita_1
Enable channel 1.
Definition: I2C_mux.h:26
#define I2C_mux_abilita_0
Enable channel 0.
Definition: I2C_mux.h:25
@ node_voltage_PGA_ch_0
Node voltage selection of PGA differential or positive.
Definition: Istruzioni.h:58
void EPROM_lettura_M24C32_64(uint8_t scheda_su_scheda_giu_, uint8_t mainboard_postmainboard, uint8_t canale, short indirizzo_memoria, uint8_t *dati_letti)
Read from preamplifier and on-board flashes.
void EPROM_scrittura_M24C32_64(uint8_t scheda_su_scheda_giu, uint8_t mainboard_postmainboard, uint8_t canale, short indirizzo_memoria, uint8_t *dati_da_scrivere)
Wriring the EEPROM.
@ Memory_mainboard_det_coa_slope_cali_ON_0_OFF_ff_ch0
slope detector positive trimmer active if zero
@ Memory_mainboard_det_positive_ad_coarse_trim_slope_bias_ch0
coarse slope for detector positive trimmer bias
@ Memory_mainboard_det_fin_slope_cali_ON_0_OFF_ff_ch0
slope detector negative trimmer active if zero
@ Memory_mainboard_det_positive_ad_fine_trim_slope_bias_ch0
fine slope for detector positive trimmer bias
@ Memory_mainboard_det_negative_ad_coarse_trim_slope_bias_ch0
coarse slope for detector negative trimmer bias
@ Memory_mainboard_det_negative_ad_fine_trim_slope_bias_ch0
fine slope for detector negative trimmer bias
@ Memory_detector_negative_address_coarse_trimmer_slope_bias
coarse slope for detector negative trimmer bias
@ Memory_preamplifier_slope_calibration_ON_0_OFF_ff
slope trimmer active if zero
@ Memory_detector_positive_address_coarse_trimmer_slope_bias
coarse slope for detector positive trimmer bias
@ Memory_detector_negative_address_fine_trimmer_slope_bias
fine slope for detector negative trimmer bias
@ Memory_detector_fine_slope_calibration_ON_0_OFF_ff
slope detector negative trimmer active if zero
@ Memory_detector_coarse_slope_calibration_ON_0_OFF_ff
slope detector positive trimmer active if zero
@ Memory_preamplifier_address_fine_trimmer_slope_offset
fine slope for trimmer offset
@ Memory_preamplifier_address_coarse_trimmer_slope_offset
coarse slope for trimmer offset
@ Memory_detector_positive_address_fine_trimmer_slope_bias
fine slope for detector positive trimmer bias
@ node_voltage_Analog_Mux_0_offset
Starting Offset for this set of nodes, 32.
#define preamplifier_scrivi_il_trimmer
void Aspetta_tanti_ms(int millisecondi)
The timing function.
Definition: Timer.c:52
void instr_DetBias_trimmer_calibration_function(void)
The fine and coarse trimmers for Detector bias adjustment are calibrated here
Definition: Trimmer.c:480
void instr_offset_trimmer_calibration_function(void)
The fine and coarse trimmers for offset adjustment are calibrated here
Definition: Trimmer.c:320
const struct address_detector_bias_trimmer_type address_preamplifier_trimmer[6]
Preamplifier trimmer addresses
Definition: Trimmer.c:139
const struct address_detector_bias_trimmer_type address_PGA_a_trimmer[6]
Preamplifier trimmer addresses
Definition: Trimmer.c:149
const struct address_detector_bias_trimmer_type address_detector_bias_trimmer[6]
Detector trimmer addresses.
Definition: Trimmer.c:129
uint8_t contenuto_trimmer_detector[12][4]
Content of the trimmer for detector bias system.
Definition: Trimmer.c:161
void detector_scrittura_lettura_trimmer_bias(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_1_leggi_0)
Setting the value of any trimmer for detector biasing, the contents of the trimmers are stored in the...
Definition: Trimmer.c:238
uint8_t volatile attenuatori_PGA_a_trimmer[12]
Definition: Trimmer.c:217
uint8_t volatile contenuto_trimmer_PGA_a_trimmer[6][4]
Definition: Trimmer.c:206
uint8_t volatile contenuto_trimmer_preamplifier[12][4]
Definition: Trimmer.c:179
void preamplifier_scrittura_lettura_trimmer(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_1_leggi_0)
Setting the value of any trimmer for preamplifier trimmer, the contents of the trimmers are stored in...
Definition: Trimmer.c:283
#define trimmer_fine_offset
Definition: Trimmer.h:80
#define trimmer_coarse_offset
Definition: Trimmer.h:82
#define I2C_address_ch_pari
Definition: Trimmer.h:73
#define I2C_address_ch_dispari
I2C address of the detecor trimmers.
Definition: Trimmer.h:72
#define maschera_solo_bit_di_scrittura_trimmer
Mask for command of the trimmer.
Definition: Trimmer.h:76
#define I2C_addres_trimmer_PGA
Definition: Trimmer.h:74
Coordinates for the preamplifier and onboard EPROMs.
Definition: Trimmer.h:97