CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
DAC_PGA.c
Go to the documentation of this file.
1
2
3#include "tutti_gli_header.h"
4
5/*****DOCUMENTAZIONE DOXYGEN (premi il - a sinistra per ridurla a icona) il manuale html \'e nella cartella************/
6/// \file
7
8
9/*! \page DAC_PGA_page DAC_PGA
10\brief <span style="color:red;"> <b> PGA Managing </b> </span>
11*\tableofcontents
12
13 \b SUMMARY:
14*\arg \ref PGA_operation
15*\arg \ref functions_not_for_user
16*\arg \ref PGA_fw
17
18*\section PGA_operation User use of PGA
19<hr width="75%" size="10" align="left">
20
21\n PGA is based on the <a href="./File_pdf/AD5451.pdf" target=_blank><b>AD5451</b></a> a 10-bits DAC operated in feedback of
22an Operational Amplifier, OA. This stage is preceded by another OA that can work at a voltage gain of 1 V/V or 10 V/V
23with a relay switchable gain setting. The input OA is set to its lower gain or larger gain if the set is smaller or larger than 10 V/V.
24\n 3 functions have been developed, but only one is for the final user. The first function, PGA_set_reset_pre_PGA_gain(), sets the gain of the input stage,
25the second function sets the gain of the output stage only, PGA_DAC_GAIN_CROSS(), while the function for user, PGA_GAIN_CROSS(), set the gain of
26both stages according to to the value.
27If we refer to the user functionn an example is quite useful:
28
29<span style="color:orange;"> <I>
30\code {.c}
31PGA_GAIN_CROSS( scheda_su_scheda_giu, canale, PGA_gain_to_set );
32\endcode
33</I> </span>
34
35\note The minimum settable PGA gain is at #guadagno_minimo_PGA and now is "1 V/V", while the maximum settable PGA gain is at
36#massimo_guadagno_impostabile and now is "100 V/V". These limits are settable, but not from the user.
37
38\n
39\note PGA gain is stored at #PGA_settled_gain[12].
40
41*\section functions_not_for_user Functions not for user
42<hr width="75%" size="10" align="left">
43\n The 2 functions PGA_set_reset_pre_PGA_gain() and PGA_DAC_GAIN_CROSS() are not directely usable from the user and can be individually used to
44study each single stage of the PGA. They can be set in order to consider a gain of "1 V/V" for the input stage irrispectively of the stage with the DAC
45to study the noise constribution. Here an example of the atomic use of the 2 functions with an overal setting of 100 V/V, but with the input stage set at 1 V/V:
46
47<span style="color:orange;"> <I>
48\code {.c}
49 PGA_set_reset_pre_PGA_gain ( scheda_su_scheda_giu, canale_, PGA_set_pre_pga_low_gain ) ;
50 PGA_DAC_GAIN_CROSS(scheda_su_scheda_giu, canale_ , 1,100);
51\endcode
52</I> </span>
53
54*\section PGA_fw More details about PGA fw
55<hr width="75%" size="10" align="left">
56\n The user function is quite simple and obvious:
57\snippetlineno DAC_PGA.c fun_PGA_GAIN_CROSS
58
59\n For the setting of the first stage we need to set its relay. To implement the 2 signals we developed a
60pair of swithes MOS-based that are driven by the 2 available digital signal from the detector bias trimmer chip,
61<a href="./File_pdf/AD5263.pdf" target=_blank><b>AD5263 </b></a>, see the figure at
62\ref Figure_Trimmer_AD5263_per_relay, pin \b O1 and \b O2. The function PGA_set_reset_pre_PGA_gain() is given just below.
63Note that the input parameter \b set_2_reset_1_idle_0 is not the gain value. It is recommended to use the following definitions:
64- #PGA_set_pre_pga_high_gain
65- #PGA_set_pre_pga_low_gain
66- #set_pre_pga_idle
67
68*\snippetlineno DAC_PGA.c fun_PGA_set_reset_pre_PGA_gain
69
70\n I2C is used in the function to manage the trimmer at set / reset the relay that provides the gain.
71
72*\anchor Figure_Trimmer_AD5263_per_relay
73*\image html AD5263_for_relay.png "FigureTrimmer_AD5263_per_relay: the 2 digital signals into evidence" width=40%
74*\image latex AD5263_for_relay.png "FigureTrimmer_AD5263_per_relay: the 2 digital signals into evidence" width=40%
75
76\n The DAC that vsets the gain of the second stage is managed with SPI and the function PGA_DAC_GAIN_CROSS() is:
77\snippetlineno DAC_PGA.c fun_PGA_DAC_GAIN_CROSS
78
79\n The codes for mamnaging the PGA gain are:
80 - \ref DAC_PGA.c
81 - \ref DAC_PGA.h
82
83*/
84
85
86//Inizio CROSS
87
88uint8_t guadagno_minimo_PGA= 1; /*!< Minimum settable PGA gain, in V/V */
89uint8_t massimo_guadagno_impostabile= 100 ; /*!< Maximum settable PGA gain, in V/V */
90
91/*! \brief PGA set gain
92*\snippet DAC_PGA.c vec_PGA_settled_gain
93*/
94//! <!-- [vec_PGA_settled_gain] -->
95uint8_t PGA_settled_gain[12]={ 1, 1, 1, 1, 1,1,
96 1, 1, 1, 1, 1,1}; ///< PGA set gain
97//! <!-- [vec_PGA_settled_gain] -->
98
99 /*! \brief Here the 2 digital signals from the trimmer are exploited to set the gain of the input stage of the PGA
100
101*\param[in] scheda_su_scheda_giu One of the 2 boards that the postfrontend manages
102*\param[in] canale The channel for which we need to manage the trimmer
103*\param[in] PGA_gain_to_set The overal gain to set
104*\return No Parameters
105
106 *\snippetlineno DAC_PGA.c fun_PGA_GAIN_CROSS
107 */
108 //! <!-- [fun_PGA_GAIN_CROSS] -->
109void PGA_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t PGA_gain_to_set ){
110 uint8_t PGA_gain_for_second_stage=PGA_set_pre_pga_low_gain;
111 uint8_t offset_schdea=0;
112 if (scheda_su_scheda_giu){
113 offset_schdea =6;
114 scheda_su_scheda_giu=6;
115 }
116
117
118 PGA_settled_gain[canale + offset_schdea]= PGA_gain_to_set;
119 if( PGA_gain_to_set >= PGA_pre_PGA_max_gain){
120 PGA_set_reset_pre_PGA_gain ( scheda_su_scheda_giu, canale, PGA_set_pre_pga_high_gain );//first stage of PGA at max gain
121 PGA_gain_for_second_stage=PGA_pre_PGA_max_gain; //Communication of the gain set at first stega of PGA, to be used from PGA_DAC_GAIN_CROSS()
122 }else{
123 PGA_set_reset_pre_PGA_gain ( scheda_su_scheda_giu, canale, PGA_set_pre_pga_low_gain ); //First stage of PGA at small gain
124 }
125 PGA_DAC_GAIN_CROSS( scheda_su_scheda_giu, canale, PGA_gain_to_set, PGA_gain_for_second_stage);
126
127// int ciccia= ADC_lettura_registro(0,0,ADC_channel_conversion_time_FW_ch0_register);
128
129}
130 //! <!-- [fun_PGA_GAIN_CROSS] -->
131
132
133 /*! \brief Here the 2 digital signals from the trimmer are exploited to set the gain of the input stage of the PGA
134
135 *\param[in] scheda_su_scheda_giu one of the 2 boards that the postfrontend manages
136 *\param[in] canale the channel for which we need to manage the trimmer
137 *\param[in] set_2_reset_1_idle_0 if 1 the gain is at 10, if 0 the gain is 1
138 *\return No Parameters
139
140 *\snippetlineno DAC_PGA.c fun_PGA_set_reset_pre_PGA_gain
141 */
142 //! <!-- [fun_PGA_set_reset_pre_PGA_gain] -->
143void PGA_set_reset_pre_PGA_gain (uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t set_2_reset_1_idle_0 ){
144
145 uint8_t spedizione[2];
146 if( scheda_su_scheda_giu) scheda_su_scheda_giu=6;
147
148 spedizione[1] = contenuto_trimmer_detector[canale + scheda_su_scheda_giu][0] ; //The trimmer content has to be
149 //written each time the digital signals are set/reset
150
151 I2C_mux_select_ch( scheda_su_scheda_giu, I2C_mainboard, address_detector_bias_trimmer[canale].quale_I2C); //Select the I2C to be used
152
153 if( set_2_reset_1_idle_0) { //We operate only if we have to set
154
155 spedizione[0] = set_2_reset_1_idle_0 << 1 ; //The 2 bits are at position 1 and 2 of the byte
156
157
158 I2C_mux->MasterTransmit( (uint8_t) address_detector_bias_trimmer[canale].indirizzo_I2C , spedizione, 2,false); //Write the selected trimmer of the selcted channel
159
160 while( I2C_mux->GetStatus().busy); // White transmission complete
161
164 }
165
166 spedizione[0] =set_pre_pga_idle; // Both switches OFF, this operation is made always and can be made at the initialization
167
168 I2C_mux->MasterTransmit( (uint8_t) address_detector_bias_trimmer[canale].indirizzo_I2C , spedizione, 1,false); ///Set the trimmer to read
169
170 while( I2C_mux->GetStatus().busy); // White transmission complete
171
172 I2C_mux->MasterReceive( address_detector_bias_trimmer[canale].indirizzo_I2C, &tappo, 1,false); //Read back, the trimmer value
173
174 while( I2C_mux->GetStatus().busy){};
175
176 contenuto_trimmer_detector[canale + scheda_su_scheda_giu][0] = tappo;
177}
178 //! <!-- [fun_PGA_set_reset_pre_PGA_gain] -->
179
180
181/*! \brief It sets the PGA gain irrespective of the offset
182
183*\param[in] scheda_su_scheda_giu is the board up or down
184*\param[in] canale chi_aggiustiamo which channels to adjust
185*\param[in] guadagno_da_impostare the gain to set
186*\param[in] PGA_si_NO DAC PGA is not set if this parameter is 0
187
188*\return No Parameters.
189
190*\snippetlineno DAC_PGA.c fun_PGA_DAC_GAIN_CROSS
191*/
192//! <!-- [fun_PGA_DAC_GAIN_CROSS] -->
193void PGA_DAC_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t guadagno_da_impostare, uint8_t PGA_si_NO){
194// uint16_t valore_da_trasmettere;
195// char ii;
196// uint8_t PGA_si_NO=1;
197
198 //Attenzione: canale deve essere <6
199 uint8_t offset_scheda=0;
200 if (scheda_su_scheda_giu){
201 offset_scheda=6;
202 }
203// valore_da_trasmettere = vettore_istruzioni[byte_istr_dati_0] + ( vettore_istruzioni[byte_istr_dati_1]<< 8);
204 //Set the gain at the lower or maximum valued if the request is otside the limits
205 if( guadagno_da_impostare<=guadagno_minimo_PGA) guadagno_da_impostare=guadagno_minimo_PGA ;
206 if( guadagno_da_impostare > massimo_guadagno_impostabile ) guadagno_da_impostare =massimo_guadagno_impostabile ;
207 PGA_settled_gain[canale + offset_scheda]= guadagno_da_impostare;
208// for(ii=0;ii<2;ii++){
209// if ( (canale >> ii) & 1) {
210// if ( guadagno_da_impostare < gain_pre_PGA_x_2){
211// //Rele gain PGA a 1
212// Detector_PGA_Rele( ( (ii<<4) | 8));
213// }else{
214// //Rele gain PGA a 1 o 10
215// if ( vettore_istruzioni[istruzione_byte_3] ){
216// // Gain PGA rele a 10
217// Detector_PGA_Rele( ( (ii<<4) | 9));
218// PGA_si_NO=10;
219// }else{
220// // Gain PGA rele a 1
221// Detector_PGA_Rele( ( (ii<<4) | 8));
222// }
223// }
224//}
225//}
226
227 SPIdrv->Uninitialize(); // Al DAC servono dati di 16 bit
228 SPI_Inizialize_per_il_DAC(); //DAC operated at 16 bits
229
230 //IL guadagno minimo del PGA al momento \'e 4, sta nella variabile guadagno_minimo_PGA
231 uint16_t PGA_code =1+ (( (fondo_scala_DAC_PGA * guadagno_minimo_PGA) * PGA_si_NO) / guadagno_da_impostare); //Gain to be set at the second stage of pga
232 if ( PGA_code > 0x3ff) PGA_code=0x3ff;
233 PGA_code = (PGA_code<<4) & 0x3FFF ; //Il <<4 \'e la richiesat del dac
234
235// SPIdrv->Control(SPI_control_for_DAC, SPI_DAC_SPEED); // SPI fits DAC specs at 16 bits and speed
236
237
238
239// GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 0); // Viene abbassato il Chip Sel del DAC del canale 0
240// Dobbiamo aggiungere il chip select qui
241 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_scheda_giu, PGA_DAC_chip_select[canale].I2C_to_parallel_chip_num, \
242 PGA_DAC_chip_select[canale].I2C_to_parallel_chip__pin_num );
243 Aspetta_tanti_ms(10);
244// SPItx_16_per_il_DAC( (PGA_code<<4) & 0x3FFF); //Il <<4 \'e la richiesat del dac
245 SPIdrv->Send ( &PGA_code ,1); //send the 16 bits
246// while( SPIdrv->GetStatus().busy ){} //wait end of transmission
247 Aspetta_tanti_ms(10); // Bisogna aspettare almeno 5 ms prima di inviare un'altra istruzione
248
249 uint8_t troppa_attesa=0;
250 while( (SPIdrv->GetStatus().busy) && (troppa_attesa <250) ){
252 troppa_attesa++;
253 } //wait end of transmission ;
254 if((troppa_attesa>=250) || (Error_bad_operation)) ERROR_codifica_errore(scheda_su_scheda_giu, error_address_SPI, SPI_error_EVENT_DATA_LOST,1);
255
256
257// ERROR_codifica_errore( 0, error_address_SPI, Error_bad_operation, 1 );
258// GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 1); // Viene alzato il Chip Sel del DAC del canale 0
259// Dobbiamo aggiungere il chip un-select qui
260 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_scheda_giu, PGA_DAC_chip_select[canale].I2C_to_parallel_chip_num, \
261 I2C_to_Parallel_ini_set[PGA_DAC_chip_select[canale].I2C_to_parallel_chip_num] );
262 Aspetta_tanti_ms(10); // Bisogna aspettare almeno 5 ms prima di inviare un'altra istruzione
264
265// SPIdrv->Uninitialize(); // Si ritorna alla SPI a 8 bit
266// SPI_Inizialize();
267 //actual PGA gain
268// status = SPIdrv->Control(SPI_control_for_relay_driver,spi_clock_for_relais);
269 SPIdrv->Uninitialize(); // Si ritorna alla SPI a 8 bit
271}
272//! <!-- [fun_PGA_DAC_GAIN_CROSS] -->
273
274
275//Fine CROSS
276
277
278unsigned int PGA_Gain_code[2];
279unsigned int PGA_Gain_V_su_V[2];
280
281
282/*! \brief It sets the PGA gain irrespective of the offset
283
284*\param[in] scheda_su_scheda_giu is the board up or down
285*\param[in] canale chi_aggiustiamo which channels to adjust
286*\param[in] guadagno_da_impostare the gain to set
287*\return No Parameters.
288
289*\snippetlineno DAC_PGA.c fun_PGA_GAIN
290*/
291//! <!-- [fun_PGA_GAIN] -->
292void PGA_GAIN(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t guadagno_da_impostare){
293// uint16_t valore_da_trasmettere;
294// char ii;
295 uint8_t PGA_si_NO=1;
296
297
298// valore_da_trasmettere = vettore_istruzioni[byte_istr_dati_0] + ( vettore_istruzioni[byte_istr_dati_1]<< 8);
299 if( guadagno_da_impostare<=guadagno_minimo_PGA) guadagno_da_impostare=guadagno_minimo_PGA ;
300 if( guadagno_da_impostare > massimo_guadagno_impostabile ) guadagno_da_impostare =massimo_guadagno_impostabile ;
301
302// for(ii=0;ii<2;ii++){
303// if ( (canale >> ii) & 1) {
304// if ( guadagno_da_impostare < gain_pre_PGA_x_2){
305// //Rele gain PGA a 1
306// Detector_PGA_Rele( ( (ii<<4) | 8));
307// }else{
308// //Rele gain PGA a 1 o 10
309// if ( vettore_istruzioni[istruzione_byte_3] ){
310// // Gain PGA rele a 10
311// Detector_PGA_Rele( ( (ii<<4) | 9));
312// PGA_si_NO=10;
313// }else{
314// // Gain PGA rele a 1
315// Detector_PGA_Rele( ( (ii<<4) | 8));
316// }
317// }
318//}
319//}
320 //IL guadagno minimo del PGA al momento \'e 4, sta nella variabile guadagno_minimo_PGA
321 unsigned short PGA_code = ((fondo_scala_DAC_PGA * guadagno_minimo_PGA) * PGA_si_NO / guadagno_da_impostare) ;
322
323
324
325 SPIdrv->Uninitialize(); // Al DAC servono dati di 16 bit
326 SPI_Inizialize_per_il_DAC(); //DAC operated at 16 bits
327
328// GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 0); // Viene abbassato il Chip Sel del DAC del canale 0
329// Dobbiamo aggiungere il chip select qui
330 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_scheda_giu, PGA_DAC_chip_select[canale].I2C_to_parallel_chip_num, \
331 PGA_DAC_chip_select[canale].I2C_to_parallel_chip__pin_num );
333 SPItx_16_per_il_DAC( (PGA_code<<4) & 0x3FFF); //Il <<4 \'e la richiesat del dac
334 Aspetta_tanti_ms(10); // Bisogna aspettare almeno 5 ms prima di inviare un'altra istruzione
335// GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 1); // Viene alzato il Chip Sel del DAC del canale 0
336// Dobbiamo aggiungere il chip un-select qui
337 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_scheda_giu, PGA_DAC_chip_select[canale].I2C_to_parallel_chip_num, \
338 I2C_to_Parallel_ini_set[PGA_DAC_chip_select[canale].I2C_to_parallel_chip_num] );
339 Aspetta_tanti_ms(10); // Bisogna aspettare almeno 5 ms prima di inviare un'altra istruzione
340
341 SPIdrv->Uninitialize(); // Si ritorna alla SPI a 8 bit
343 //actual PGA gain
344}
345//! <!-- [fun_PGA_GAIN] -->
346
347
348/*! \brief The second stage gain is settable here.
349
350This instruction needs to know the gain to set and the channel to apply the setting. These informztion are
351at byte istruzione_byte_4_e_scelta_canale and at bytes byte_istr_dati_0 and byte_istr_dati_1 of the CAN message.
352*\return No Parameters, the actual result is sent to the CAN bus output throught \ref tx_data.
353
354
355*\snippetlineno DAC_PGA.c fun_instruction_for_PGA_GAIN_set
356*/
357//! <!-- [fun_instruction_for_PGA_GAIN_set] -->
359 //This function must be optimized as it must opetrate with the x1 / x10 pre pga gain
360 //vettore_istruzioni[1]=0 means channel 0, vettore_istruzioni[1]>0 means channel 1
361 // vettore_istruzioni[2] is the MS8bits, while vettore_istruzioni[3] are the LS8bits
362 //of the gain to set.
365
366 tx_data[byte_istr_dati_0] = PGA_Gain_V_su_V[0];
367 tx_data[byte_istr_dati_1] = PGA_Gain_V_su_V[1];
368}
369//! <!-- [fun_instruction_for_PGA_GAIN_set] -->
370
371
372/*! \brief It sets the new gain letting the output offset at the same level
373
374
375*\param[in] chi_aggiustiamo which channels to adjust
376*\param[in] guadagno_da_impostare the gain to set
377*\return No Parameters.
378
379*\snippetlineno DAC_PGA.c fun_PGA_preparation_to_gain_set
380*/
381//! <!-- [fun_PGA_preparation_to_gain_set] -->
382void PGA_preparation_to_gain_set(char chi_aggiustiamo, unsigned int guadagno_da_impostare){
383
384 int misura_finale[2], offset;
385 char nodo_di_misura_1[]={ADC_ADC_PGA_neg_out_ch0, ADC_ADC_PGA_neg_out_ch1};
386 char nodo_di_misura_2[]={ADC_ADC_PGA_pos_out_ch0, ADC_ADC_PGA_pos_out_ch1};
387 int coarse_trimmer_step[] ={ coarse_Trimmer_offset_step_actual[0] * guadagno_minimo_PGA,coarse_Trimmer_offset_step_actual[1] * guadagno_minimo_PGA} ; //*********************************************
388 int fine_trimmer_step[] = {fine_Trimmer_offset_step_actual[0] * guadagno_minimo_PGA, fine_Trimmer_offset_step_actual[1] * guadagno_minimo_PGA} ; //*********************************************
389 char canale;
390 if (guadagno_da_impostare<guadagno_minimo_PGA) guadagno_da_impostare=guadagno_minimo_PGA;
391 if( guadagno_da_impostare > massimo_guadagno_impostabile ) guadagno_da_impostare =massimo_guadagno_impostabile ;
392
393 for( canale=0;canale<2;canale++){
394 if( (chi_aggiustiamo >> canale) & 1){
395// offset=lettura_ADC( nodo_di_misura_1[canale]) - lettura_ADC( nodo_di_misura_2[canale]); //Il <<1 \'e per renderlo differenziale
396 valore_target_per_offset[canale]=correzione_misura_ADC(coeffcienti_misura_ADC_nodi[nodo_di_misura_1[canale]], offset);
397 //Voglim mantenere la tenione allo stesso livello se \'e in scala, altrimenti aggiustiamo a zero
398 if( (valore_target_per_offset[canale] >= saturazione_positiva) || ( valore_target_per_offset[canale] <= saturazione_negativa ) ) {
399 valore_target_per_offset[canale]=0;
400 }else{
401 //Se il nuovo gain
402 valore_target_per_offset[canale] = ( valore_target_per_offset[canale] * (int)guadagno_minimo_PGA ) / (int)guadagno_da_impostare ;
403 }
404
405 }
406 }
407
408PGA_GAIN_set(chi_aggiustiamo, 1);
409
410
411//offset_Adjust_core( chi_aggiustiamo, valore_target_per_offset, nodo_di_misura_1, nodo_di_misura_2, \
412// ((fine_trimmer_step[0]+fine_trimmer_step[1])>>1), coarse_trimmer_step, fine_trimmer_step, 10, misura_finale);
413
414PGA_GAIN_set(chi_aggiustiamo, guadagno_da_impostare);
415
416
417 for( canale=0;canale<2;canale++){
418 if( (chi_aggiustiamo >> canale) & 1){
419// offset=lettura_ADC( nodo_di_misura_1[canale]) - lettura_ADC( nodo_di_misura_2[canale]); //Il <<1 \'e per renderlo differenziale
420 offset=correzione_misura_ADC(coeffcienti_misura_ADC_nodi[nodo_di_misura_1[canale]], offset) * (int)guadagno_minimo_PGA / (int)guadagno_da_impostare ;
421 int correzione = ( valore_target_per_offset[canale] - offset ) / (( (fine_trimmer_step[0]+fine_trimmer_step[1])>>1) ) ;
422 Trimmer_offset_preampli[canale].fine_offset= Trimmer_offset_preampli[canale].fine_offset - correzione;
423 if (Trimmer_offset_preampli[canale].fine_offset >255) Trimmer_offset_preampli[canale].fine_offset=255;
424 if( Trimmer_offset_preampli[canale].fine_offset <0 ) Trimmer_offset_preampli[canale].fine_offset=0;
425 Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (canale, preampli_fine_offset_trimmer, Trimmer_offset_preampli[canale].fine_offset);
426 }
427 }
428
429}
430//! <!-- [fun_PGA_preparation_to_gain_set] -->
431
432
433/*! \brief It sets the new gain irrespective of the offset
434
435
436*\param[in] canale which channels to adjust
437*\param[in] guadagno_da_impostare the gain to set
438*\return No Parameters.
439
440*\snippetlineno DAC_PGA.c fun_PGA_GAIN_set
441*/
442//! <!-- [fun_PGA_GAIN_set] -->
443void PGA_GAIN_set(char canale, unsigned int guadagno_da_impostare){
444// uint16_t valore_da_trasmettere;
445 char ii;
446 signed char PGA_si_NO=1;
447 porta_pin_def local_pin_port;
448
449// valore_da_trasmettere = vettore_istruzioni[byte_istr_dati_0] + ( vettore_istruzioni[byte_istr_dati_1]<< 8);
450 if( guadagno_da_impostare<=guadagno_minimo_PGA) guadagno_da_impostare=guadagno_minimo_PGA ;
451 if( guadagno_da_impostare > massimo_guadagno_impostabile ) guadagno_da_impostare =massimo_guadagno_impostabile ;
452
453 for(ii=0;ii<2;ii++){
454 if ( (canale >> ii) & 1) {
455 if ( guadagno_da_impostare < gain_pre_PGA_x_2){
456 //Rele gain PGA a 1
457 Detector_PGA_Rele( ( (ii<<4) | 8));
458 }else{
459 //Rele gain PGA a 1 o 10
461 // Gain PGA rele a 10
462 Detector_PGA_Rele( ( (ii<<4) | 9));
463 PGA_si_NO=10;
464 }else{
465 // Gain PGA rele a 1
466 Detector_PGA_Rele( ( (ii<<4) | 8));
467 }
468 }
469}
470}
471
472
473 //IL guadagno minimo del PGA al momento \'e 4, sta nella variabile guadagno_minimo_PGA
474// unsigned short int PGA_code = (guadagno_da_impostare << 7) / guadagno_minimo_PGA;
475 unsigned short PGA_code = ((fondo_scala_DAC_PGA * guadagno_minimo_PGA) * PGA_si_NO / guadagno_da_impostare) ;
476
477
478 for(ii=0;ii<2;ii++){
479 if ( (canale >> ii) & 1) {
480 if (ii==1 ){
481 //Gain to set for channle 1
482 local_pin_port=PGA_DAC_pin_select_ch1;
483 PGA_Gain_code[1]= PGA_code;
484 PGA_Gain_V_su_V[1]=guadagno_da_impostare;
485 }else{
486 //Gain to set for channle 0
487 local_pin_port=PGA_DAC_pin_select_ch0;
488 PGA_Gain_code[0]= PGA_code;
489 PGA_Gain_V_su_V[0]=guadagno_da_impostare;
490 }
491
492 SPIdrv->Uninitialize(); // Al DAC servono dati di 16 bit
494
495 GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 0); // Viene abbassato il Chip Sel del DAC del canale 0
497 SPItx_16_per_il_DAC( (PGA_code<<4) & 0x3FFF); //Il <<4 \'e la richiesat del dac
498 Aspetta_tanti_ms(10); // Bisogna aspettare almeno 5 ms prima di inviare un'altra istruzione
499 GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 1); // Viene alzato il Chip Sel del DAC del canale 0
500 Aspetta_tanti_ms(10); // Bisogna aspettare almeno 5 ms prima di inviare un'altra istruzione
501
502 SPIdrv->Uninitialize(); // Si ritorna alla SPI a 8 bit
504 //actual PGA gain
505 }
506 }
507}
508//! <!-- [fun_PGA_GAIN_set] -->
509
uint8_t tx_data[8]
Transmission data vector.
Definition: Can.c:321
void instruction_for_PGA_GAIN_set(void)
The second stage gain is settable here.
Definition: DAC_PGA.c:358
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 massimo_guadagno_impostabile
Definition: DAC_PGA.c:89
uint8_t guadagno_minimo_PGA
Definition: DAC_PGA.c:88
void PGA_preparation_to_gain_set(char chi_aggiustiamo, unsigned int guadagno_da_impostare)
It sets the new gain letting the output offset at the same level.
Definition: DAC_PGA.c:382
uint8_t PGA_settled_gain[12]
PGA set gain.
Definition: DAC_PGA.c:95
void PGA_GAIN(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t guadagno_da_impostare)
It sets the PGA gain irrespective of the offset.
Definition: DAC_PGA.c:292
void PGA_set_reset_pre_PGA_gain(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t set_2_reset_1_idle_0)
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:143
void PGA_GAIN_set(char canale, unsigned int guadagno_da_impostare)
It sets the new gain irrespective of the offset.
Definition: DAC_PGA.c:443
void PGA_DAC_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t guadagno_da_impostare, uint8_t PGA_si_NO)
Definition: DAC_PGA.c:193
#define PGA_pre_PGA_max_gain
Definition: DAC_PGA.h:21
#define PGA_set_pre_pga_low_gain
Set the amplifier gain in front of the PGA to 1 V/V, it is left shifted once in the trimmer.
Definition: DAC_PGA.h:8
#define PGA_set_pre_pga_high_gain
Set the amplifier gain in front of the PGA to 10 V/V, it is left shifted once in the trimmer.
Definition: DAC_PGA.h:7
#define set_pre_pga_idle
The swirches are set both off.
Definition: DAC_PGA.h:9
#define wait_time_for_rele_setting
[ref_spi_clock_for_relais]
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_I2C_to_parallel_PCA9554_0
I2C to parallel conversion ch0.
@ I2C_Error_trimmer_0
trimmer ch0
@ error_address_I2C0
Error register A for I2C0.
@ error_address_SPI
Error register for SPI.
@ SPI_error_EVENT_DATA_LOST
This is ARM_SPI_EVENT_DATA_LOST.
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
void I2C_to_Parallel_set_PCA9554_outputs_values(uint8_t scheda_su_scheda_giu, uint8_t select_PCA, uint8_t value)
The function I2C_to_Parallel_set_PCA9554_outputs_values allow to set the output pin of the I2C to par...
const uint8_t I2C_to_Parallel_ini_set[4]
...
#define istruzione_byte_3
Definition: Istruzioni.h:23
#define byte_istr_dati_1
Definition: Istruzioni.h:26
#define byte_istr_dati_0
Definition: Istruzioni.h:25
#define istruzione_byte_4_e_scelta_canale
Definition: Istruzioni.h:24
void SPI_Inizialize_per_il_DAC(void)
SPI is initialized here for DAC. Remember to set the variable SPI_speed before the call....
Definition: Spi.c:237
void SPI_Inizialize(void)
SPI is initialized here. Its ise t at 8 bits and 100 KHz, as default.
Definition: Spi.c:205
void Aspetta_tanti_ms(int millisecondi)
The timing function.
Definition: Timer.c:52
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
volatile int8_t vettore_istruzioni[8]
This is a copy of the received 8 bytes from the CAN.
Definition: Gpio.h:13