CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches
inizializzazione.c
Go to the documentation of this file.
1
2/// \file
3
4#include "tutti_gli_header.h"
5
6
7/// \file system_LPC17xx.c
8/// \file core_cm3.h
9/*!
10\page Inizializzazione_
11*\brief <span style="color:red;"> <b> System start-up </b> </span>
12*\tableofcontents
13
14 \b SUMMARY:
15*\arg \ref microcontroller
16*\arg \ref System_Startup
17*\arg \ref Clock_setup
18*\arg \ref CAN_speed
19*\arg \ref STARTUP_OVER_THE_CAN
20
21*\section microcontroller Adopted &micro;-controller
22<hr width="75%" size="10" align="left">
23\n The &micro;-controller adopted to manage the board sis a \b LPC1768 from NXP (here its user manual: <a href="./File_pdf/LPC1768_UM10360.pdf" target=_blank><b>LPC1768 UM</b></a>).
24The \b LPC1768 is a 32-bit ARM Cortex-M3.
25
26*\section System_Startup System start-up
27<hr width="75%" size="10" align="left">
28\n At power-up it is very important that the system start properly and we have
29\n the function instr_inizializza_tutto_da_zero_function().
30This function can be called from remote in order to apply for a system reset.
31\n The list of the action done at start-up is evolving; here the actual list:
32- clock setup (SystemCoreClockUpdate());
33- fw code determination (#__INT_DATE__) (more on this at \ref date_construction), the fw versione can be determined via CAN bus by the instruction
34#instr_NO_operation;
35- generation of the pointer to the instruction functions (Setting_of_the_pointer_for_command_parser());
36- CAN initialization (CAN_Inizialize());
37- SPI initialization (SPI_Inizialize());
38- I2C0 and I2C1 initialization (I2C_0_Initialize(), I2C_1_Initialize());
39- configure the I2C_mux (Configure_Reset_I2C_mux());
40- configure to idle the relay driver of the first stage of the PGA (PGA_set_reset_pre_PGA_gain());
41- configure to idle the relay driver of the preamplifier gain; <------------- da fare
42- set to off all the chip select pins (I2C_to_Parallel_ini_PCA9554());
43- set the PGA gain to 1 V/V (PGA_GAIN_CROSS());
44- set the preamplifier gain to high; <------------------------------------- da fare
45- reset all the relay drivers (use of I2C_to_Parallel_set_PCA9554_outputs_values());
46- disconnect the detector (use of Relays_driver_set_reset_channel());
47- set the detector bias to 0 V (trimmer at half scale, 128) (detector_scrittura_lettura_trimmer_bias());
48- set all the preamplifier trimmers at half scale (128) (preamplifier_scrittura_lettura_trimmer()).
49
50
51*\section Clock_setup Clock setup
52<hr width="75%" size="10" align="left">
53The easier way to configure theCPU clock is by the "configuration wizard" that can be managed opening the "system_LPC17xx.c" file.
54The parameters to select is the clock source that, in our case, is suggested to be "Main Oscillator", tyhat is, our \b 12 \b Mz crystal.
55Then, 3 parameters are necessary to select.
56\n In case the PLL is used PLL0 must be selected together with \b MSEL and \n NSEL and \b CCLKSEL according to the following formula:
57
58\f$ f_{cpu} = Main Osc \frac {2 MSEL}{NSEL \; CCLKSEL} \f$
59
60Note that the frequency at the PLL output, i.e. after \b MSEL and \b NSEL must be between \b 275 \b MHz and \b 550 \b MHz.
61\n As an example: MainOsc = 12 MHz, MSEL=100, NSEL=6 and CCLKSEL=4 gives: 100 MHz.
62\n In case PLL is not used it must be unselected and:
63
64\f$ f_{cpu} = \frac {Main Osc }{CCLKSEL} \f$ .
65
66\note System clock frequency is at #SystemCoreClock
67
68
69*\section CAN_speed CAN speed
70<hr width="75%" size="10" align="left">
71
72\n Can speed is selectable in 2 different locations. Within the "configuration wizard" of the "system_LPC17xx.c" the CAN clock
73is configurable as a function of the CPU clock. It seems that the CAN does not operates correctely if this parameter if different than \b 4.
74So, unless the reason for this is not clear, it is suggested to leave this parameter to \b 4.
75The bit rate, or CAN frequency, is as it follows:
76
77\f$ bit \; rate = \frac {CAN Clk}{P \; N} \f$
78
79where \b P is the prescaler that is determined by the compiler and \b N:
80
81\f$ N = 1 + PROP\_SEG + PHASE\_SEG1 + PHASE\_SEG2 \f$
82
83and these parameters are withn the function CANdrv->SetBitrate() (CAN1_SetBitrate()) located in CAN_LPC17xx.c.
84\n Note that the parameter \b P must results an integer and an error happens and the CAN does not work if this does not result.
85It is suggested to adjust N in such a way \b P results an integer.
86\n As an example if the CPU clock is 100 MHz and CAN bit rate must be 125 KHz, from CAN clock = 25 MHz and N=8 (=1+5+1+1) we get P=25.
87If the CPU clock is 12 MHz (no PLL used), and N=8 (=1+5+1+1) it results P=12.
88
89*\section STARTUP_OVER_THE_CAN Startup over the CAN bus
90<hr width="75%" size="10" align="left">
91\n The initialization function, or rest, can be called via CAN bus by the
92<a href="file:///D:/ownCloud/Laboratorio/FW_CROSS/FW_CROSS_POSTFRONTEND/html/_instruction_set.html#instr_inizializza_tutto_da_zero_option">instr_inizializza_tutto_da_zero</a>.
93\n Take care that the boards respond on a common address at \b 0xAAAAAAA with the own address.
94\n There are 2 way to set the CAN address depending on the value of the postfrontend memory content at address #Memory_postmainboard_CAN_from_hw_switch_1_from_EPROM_0 of the postfronend board.
95If the content of this memory location is read &ge;1 at startup the address is read from the switches \b SW3 on board (only the first 6 switches are active and the address
96can be set from 0 to 0x3f (63)). Switch high corresponds to \b 1.
97\n if the content of #Memory_postmainboard_CAN_from_hw_switch_1_from_EPROM_0 is 0 the address is read from the memory location #Memory_postmainboard_address_CAN_own_filter of the postfrontend board.
98Changing the content of #Memory_postmainboard_CAN_from_hw_switch_1_from_EPROM_0, by <a href=_instruction_set.html#instr_EPROM_read_write_option>instr_EPROM_read_write</a> instrucion, allows to change the address from one modality to the other. This need to re-initialize the board, by the
99<a href=_instruction_set.html#instr_Shut_Down_ON_OFF_option>instr_Shut_Down_ON_OFF</a> instruction.
100
101\sa <a href=_instruction_set.html#instr_EPROM_read_write_option>instr_EPROM_read_write</a> and <a href=_instruction_set.html#instr_Shut_Down_ON_OFF_option>instr_Shut_Down_ON_OFF</a> instrucions.
102
103*/
104/*! <!-- Commenti per le CMSIS -->
105\fn SystemCoreClockUpdate (void)
106\return no parameters
107\brief Configuring the clock, frequency, PLL, etc
108
109\var SystemCoreClock
110\brief The clock frequency
111*/
112//INIZIO CROSS
113
114 int32_t mio_SCS_Val ;
115 int32_t mio_CCLKCFG_Val;
116 int32_t mio_PCLKSEL0_Val;
117 int32_t mio_PCLKSEL1_Val;
118 int32_t mio_CLKSRCSEL_Val;
119 int32_t mio_PLL0CFG_Val;
120 int32_t mio_PLL0_SETUP;
121
122
123/*! \brief Start-up function
124
125*\return No Parameters
126\showrefby
127\showrefs
128*\snippet{lineno} inizializzazione.c fun_startup
129 */
130//! <!-- [fun_startup] -->
132 uint8_t canale_, trimmer_,dati_letti[4];
133
134
135 // Configurazione del LED
136 // Configure_Led_rosso(); // Viene configurato il Led rosso
137 // Configure_Led_verde(); // Viene configurato il Led verde
138 // Accendi_led_verde(); // Viene acceso il Led verde
139
140
141 // Configurazione del Timer
142 SystemCoreClockUpdate(); // Viene aggiornato il system core clock
143 SysTick_Config(SystemCoreClock/1000); // Viene generato l'interrupt ogni 1 ms
144
145// TIMER0_setup();
146// TIMER1_setup();
147 LED_remote_control=false; //LEDs controlled by micro
148
149 if(rx_data[6]) NVIC_SystemReset();
150
151
153 scheda_su_scheda_giu=0; //.........................................Bisogner\'a specificare per la eprom del solo per il postfrontend, poi
154
155 //Definizione puntatore sitruzioni
157 LPC_SC->PCONP |= 1 <<15 ; //Accensione GPIO
161
162 // Configurazione delle Periferiche
163 // Configure_Bit_Address_for_CAN();
164
165 I2C_1_Initialize(); // Viene inizializzata la periferica I2C_A
166 I2C_0_Initialize(); // Viene inizializzata la periferica I2C_B
167
168 Configure_Reset_I2C_mux(); //< configuration of reset pin of the I2C_mux, reset it an turn into in idle state, waiting to operate
169// ADC_noding_map();
170
171 Configure_Reset_selection_port_analog_mux_ResIn_ADC_buffer(); //< configuration of reset pin of the 8 analog mux, reset it an turn into in idle state, waiting to operate
173
174
176 CAN_Inizialize(); // Viene inizializzata la periferica CAN
177 SPI_Inizialize(); // Viene inizializzata la periferica SPI
178 EPROM_scrittura_M24C32_64( scheda_su_scheda_giu, I2C_mainboard, Canale_Eprom_mainboard, Memory_mainboard_address_fw << 2 , (uint8_t *) &FW_version);
179
180
183
184 //Risoluzione max, lentezza maggiore
185 ADC_scrittura_registro(0 /*0=ADC0, 1=ADC1*/, 0, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
186 ADC_scrittura_registro(1 /*0=ADC0, 1=ADC1*/, 0, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
187 ADC_scrittura_registro(0 /*0=ADC0, 1=ADC1*/, 1, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
188 ADC_scrittura_registro(1 /*0=ADC0, 1=ADC1*/, 1, ADC_channel_conversion_time_FW_ch0_register, ADC_max_resolution);
189
190
192 ADC_selfcal_zero_scale(I2C_mux_Scheda_su); //selfcal manda in sleep
193
194 ADC_sleep_ON_OFF(0 , 2); //Acendiamo gli ADC
195 ADC_sleep_ON_OFF(1 , 2);
196 EPROM_lettura_M24C32_64(0, I2C_postmainboard, Canale_EPROM_postmainboard_down, Memory_postmainboard_ADCs_always_ON_0_powerdown_1 << 2 , dati_letti);
197 ADC_sleep_off =dati_letti[0];
198 ADC_sleep_ON_OFF(0 , 0 + ADC_sleep_off); //Spegnamo gli ADC se non vanno tenuti sempre ON
200
201
202// int risultato;
203// risultato= ADC_lettura_24bit(0, I2C_mux_Scheda_su,1);
204// risultato= ADC_lettura_24bit(1, I2C_mux_Scheda_giu,1);
205// risultato= ADC_lettura_24bit(0, I2C_mux_Scheda_su,3);
206// risultato= ADC_lettura_24bit(1, I2C_mux_Scheda_giu,3);
207// risultato= ADC_lettura_24bit(0, I2C_mux_Scheda_giu,2);
208// risultato= ADC_lettura_24bit(1, I2C_mux_Scheda_su,2);
209//
210// uint8_t ii;
211// for (ii=32; ii<32+8;ii++){
212// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 1 );
213// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 0 );
214// }
215// for (ii=40; ii<41+8;ii++){
216// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 1 );
217// Analog_mux_line_to_select_deselect_for_postmainboard ( 1, ii, 0 );
218// }
219//preamplifier_determina_trimmer_therma_comp( 1, 1, 180, 0);
220//preamplifier_determina_trimmer_therma_comp( 1, 0, 180, 0);
221
222 // The ouputs of the I2C to parallel, the chip selects, mainly, are all set high
224 I2C_to_Parallel_ini_PCA9554( 0, I2C_to_Parallel_name_2 ); //< swithces are active High
225 I2C_to_Parallel_ini_PCA9554( 0, I2C_to_Parallel_name_3 ); //< swithces are active High
227 I2C_to_Parallel_ini_PCA9554( 1, I2C_to_Parallel_name_2 ); //< swithces are active High
228 I2C_to_Parallel_ini_PCA9554( 1, I2C_to_Parallel_name_3 ); //< swithces are active High
229
230 Aspetta_tanti_ms(500);
231
232 // Set the PGA gain at its minimum (pga input stage at gain 1, DAC pre at gain 1)
233 for( canale_=0; canale_ <6; canale_ ++ ){
234// PGA_set_reset_pre_PGA_gain ( 0, canale_, PGA_set_pre_pga_low_gain ) ;
235// PGA_DAC_GAIN_CROSS( 0, canale_ , 1,1);
236 PGA_GAIN_CROSS( 0, canale_, 1 );
237 PGA_GAIN_CROSS( 1, canale_, 1 );
238 }
239
240
241 //Detector Relays Drivers reset
242 I2C_to_Parallel_set_PCA9554_outputs_values( 0, detector_reset_all_relays_driver.I2C_to_parallel_chip_num, \
243 detector_reset_all_relays_driver.I2C_to_parallel_chip__pin_num); // one pin connect all the 6 driver reset inputs and is fired now
244 //to switch off all the ouputs.
245 Aspetta_tanti_ms(10); //wait_for_ADC_setting for stability
246 I2C_to_Parallel_set_PCA9554_outputs_values( 1, detector_reset_all_relays_driver.I2C_to_parallel_chip_num, \
247 I2C_to_Parallel_ini_set[detector_reset_all_relays_driver.I2C_to_parallel_chip_num]); //Te reset pin is put inactive
248
249 //Dis-Connect the detector
250 for( canale_=0; canale_ <6; canale_ ++ ){
253 }
254 //Detector bias at zero
255 for( canale_=0; canale_ <6; canale_ ++ ){
256 for(trimmer_=0; trimmer_<4;trimmer_++){
257 detector_scrittura_lettura_trimmer_bias( 0, canale_, trimmer_, 128, 1);
258 detector_scrittura_lettura_trimmer_bias( 1, canale_, trimmer_, 128, 1);
259 }
260 }
261//Detectro large resistors
262 for( canale_=0; canale_ <6; canale_ ++ ){
265 }
266//Bias diretto e non invertito
267 for( canale_=0; canale_ <6; canale_ ++ ){
270 }
271
272//Trimmer preamplif a met\'a scala
273 for( canale_=0; canale_ <6; canale_ ++ ){
274 for( trimmer_=0; trimmer_ <4; trimmer_ ++ ){
275//void preamplifier_scrittura_lettura_trimmer(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t trimmer, uint8_t valore, uint8_t scrivi_leggi_1_leggi_0 )
278 }
279}
280
281
282//Trimmer based PGA at attenuator 0.5 and gain almost 1
283 for( canale_=0; canale_ <6; canale_ ++ ){
284 PGA_trimmer_gain (scheda_su, canale_); //Done for the first 6 channels
285 PGA_trimmer_gain (scheda_giu, canale_); //Done for the second 6 channels
286 }
287
288//Termometri in shut down
289 for( canale_=0; canale_ <6; canale_ ++ ){
290 termometro_sht_down( 0, canale_ );
291 termometro_sht_down( 1, canale_ );
292 }
293
294 //Inizializzazione parametri pendenza offset, se impostati
295 uint8_t scheda_su_scheda_giu_;
296 for(scheda_su_scheda_giu_=0;scheda_su_scheda_giu_ <2;scheda_su_scheda_giu_++){
297 for (canale_=0; canale_<6;canale_++){
298 EPROM_lettura_M24C32_64(scheda_su_scheda_giu_ ,I2C_mainboard, canale_, (Memory_preamplifier_slope_calibration_ON_0_OFF_ff <<2), dati_letti);
299 if( *(uint32_t *)dati_letti == 0){//Solo se questa cella ha tutti zeri la calibrazione \'e stata fatta
300 EPROM_lettura_M24C32_64(scheda_su_scheda_giu_ ,I2C_mainboard, canale_, (Memory_preamplifier_address_fine_trimmer_slope_offset <<2), dati_letti);
301 preamplifier_fine_step_trimmer[canale_ + scheda_su_scheda_giu_ *6] = *(int32_t *)dati_letti;
302 EPROM_lettura_M24C32_64(scheda_su_scheda_giu_ ,I2C_mainboard, canale_, (Memory_preamplifier_address_coarse_trimmer_slope_offset <<2), dati_letti);
303 preamplifier_coarse_step_trimmer[canale_ + scheda_su_scheda_giu_ *6] = *(int32_t *)dati_letti;
304 }
305
306 }
307 }
308
309 //Restoring of the detector slopes into the preamplifiers EPROM
310 for( canale_=0; canale_ <6; canale_ ++ ){
313 }
314
315 //Punto di lavoro iniziale, eventuale
318
319// GPIO_PinWrite(LED_Red.porta_num, LED_Red.pin_num, 0); //!< now the red LED is switched ON at startup
320// GPIO_PinWrite(LED_Green.porta_num, LED_Green.pin_num, 1); //!< now the red LED is switched ON at startup
321
322 //Questi serviranno solo per la re-imnizializzazione, dopo powerdown--powerup
323 mio_SCS_Val = LPC_SC->SCS;
324 mio_CCLKCFG_Val= LPC_SC->CCLKCFG;
325 mio_PCLKSEL0_Val=LPC_SC->PCLKSEL0;
326 mio_PCLKSEL1_Val=LPC_SC->PCLKSEL1;
327 mio_CLKSRCSEL_Val=LPC_SC->CLKSRCSEL;
328 mio_PLL0CFG_Val=LPC_SC->PLL0CFG;
329 mio_PLL0_SETUP=LPC_SC->PLL0CON;
330
331 //Powerwon da attivare o no
332 EPROM_lettura_M24C32_64(0, I2C_postmainboard, Canale_EPROM_postmainboard_down, Memory_postmainboard_micro_powdown_active_1_alwaysON_0 << 2 , dati_letti);
333 flag_power_down=dati_letti[0];
334 //Lettura wait time per reset micro
335 EPROM_lettura_M24C32_64(0, I2C_postmainboard, Canale_EPROM_postmainboard_down, Memory_postmainboard_micro_PD_wait_time_in_sec << 2 , dati_letti);
336 if ( (dati_letti[0]>0) || (dati_letti[0]<=60)) POWER_DOWN_MAX_ATTESA = dati_letti[0]*1000; //Il default \'e 5000
337// flag_power_down=0;
338}
339//! <!-- [fun_startup] -->
340
341/*! \brief I2C, SPI and CAN can be rest
342
343*\return No Parameters
344\showrefby
345\showrefs
346\snippet{lineno} inizializzazione.c fun_instr_periferal_reset_function
347 */
348//! <!-- [fun_instr_periferal_reset_function] -->
350 uint8_t chi_resettare=vettore_istruzioni[6];
351
352 if( chi_resettare & 1) CAN_Inizialize();
353 if( chi_resettare & 2){
354 I2C_1_Initialize(); // Viene inizializzata la periferica I2C_A
356 }
357 if( chi_resettare & 4) SPI_Inizialize();
358
359}
360//! <!-- [fun_instr_periferal_reset_function] -->
361
362//fine CROSS
363
364//void instruction_measure_pre_bias_coefficients(void) {
365// #define solo_lettura 0x80
366// #define restore_coefficients 0x40
367// char vettore_istruzioni_byte_3=vettore_istruzioni[istruzione_byte_3];
368// struct canale_ADC_type{
369// unsigned char att_pos;
370// unsigned char att_neg;
371// }canale_ADC[]={ADC_Misura_bias_10_att_ch0_p,ADC_Misura_bias_10_att_ch0_n,ADC_Misura_bias_10_att_ch1_p,ADC_Misura_bias_10_att_ch1_n} ;
372// char chi_misuro= vettore_istruzioni[istruzione_byte_4_e_scelta_canale],canale,ii,PGA_Gain_V_su_V_old,fine_offset,coarse_offset;
373// int coefficiente_in_mV,offset_ini,offset_fin, fine_offset_da_dividere;
374// int attesa= vettore_istruzioni[istruzione_byte_2]*100;
375// if (attesa <1000) attesa=1000;
376// char nodo_di_misura_1[]={ADC_ADC_PGA_neg_out_ch0, ADC_ADC_PGA_neg_out_ch1};
377// char nodo_di_misura_2[]={ADC_ADC_PGA_pos_out_ch0, ADC_ADC_PGA_pos_out_ch1};
378// for( ii=0; ii<2;ii++){
379// if ( (chi_misuro >> ii) & 1){
380// canale=ii;
381// }
382// }
383// chi_misuro=chi_misuro & 0xFE ;
384//if( ((chi_misuro & solo_lettura) ==0 ) && ((chi_misuro & restore_coefficients) ==0 ) ){ //Se 0x8x si chiede solo la stampa, se 0x4x il restoring
385// if( vettore_istruzioni_byte_3 ==1){
386// //Detector bias coefficients
387// //fine
388// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CB (canale, trimmer_bias_fine_pos, 0);
389// Aspetta_tanti_ms(attesa);
390//// offset_ini = lettura_ADC( canale_ADC[canale].att_pos); // Viene misurato l'offset per uscita neg e valutato il nuovo valore dei trimmer
391// offset_ini = correzione_misura_ADC(indice_Vbias, offset_ini);
392// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CB (canale, trimmer_bias_fine_pos, 0xFF);
393// Aspetta_tanti_ms(attesa);
394//// offset_fin = lettura_ADC( canale_ADC[canale].att_pos); // Viene misurato l'offset per uscita neg e valutato il nuovo valore dei trimmer
395// offset_fin = correzione_misura_ADC(indice_Vbias, offset_fin);
396// trimmer_bias_fine_step_actual[canale] = abs( offset_fin - offset_ini ) / 0xFF;
397//// scrivi_mem_EPROM( Memory_address_fine_trimmer_slope_bias, trimmer_bias_fine_step_actual[canale], canale);
398//
399// //coarse
400// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CB (canale, trimmer_bias_coarse_pos,0x80);
401// Aspetta_tanti_ms(attesa);
402//// offset_ini = lettura_ADC( canale_ADC[canale].att_pos); // Viene misurato l'offset per uscita neg e valutato il nuovo valore dei trimmer
403// offset_ini = correzione_misura_ADC(indice_Vbias, offset_ini);
404// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CB (canale, trimmer_bias_coarse_pos, 0x85);
405// Aspetta_tanti_ms(attesa);
406//// offset_fin = lettura_ADC( canale_ADC[canale].att_pos); // Viene misurato l'offset per uscita neg e valutato il nuovo valore dei trimmer
407// offset_fin = correzione_misura_ADC(indice_Vbias, offset_fin);
408// trimmer_bias_coarse_step_actual[canale] = abs( offset_fin - offset_ini ) / 5 ;
409//// scrivi_mem_EPROM( Memory_address_coarse_trimmer_slope_bias, trimmer_bias_coarse_step_actual[canale],canale);
410//
411// }else{
412// PGA_Gain_V_su_V_old = PGA_Gain_V_su_V[canale];
413// PGA_GAIN_set( canale, 1);
414// Aspetta_tanti_ms(attesa);
415//// offset_ini=lettura_ADC( nodo_di_misura_1[canale]) - lettura_ADC( nodo_di_misura_2[canale]); //Il <<1 \'e per renderlo differenziale
416// offset_ini=correzione_misura_ADC(coeffcienti_misura_ADC_nodi[nodo_di_misura_1[canale]], offset_ini);
417//
418// if (vettore_istruzioni_byte_3 ==0){
419//
420// //Preamplifier coefficients
421// if( (offset_ini < saturazione_positiva ) && (offset_ini > saturazione_negativa) ){
422// //Facciamo la misura
423// if (offset_ini >0){//Cerchiamo di andare dalla parte opposta per non avere probemi di dinamica
424// // fine_offset= Trimmer_offset_preampli[canale].fine_offset += (1<<4 );
425// fine_offset= 0xff;
426// coarse_offset=Trimmer_offset_preampli[canale].coarse_offset += 1 << 1 ;
427// }else{
428// // fine_offset=Trimmer_offset_preampli[canale].fine_offset -= (1<<4 );
429// fine_offset=0;
430// coarse_offset=Trimmer_offset_preampli[canale].coarse_offset -= 1 << 1 ;
431// }
432// //Facciamo prima il test con fine offset
433// if ( Trimmer_offset_preampli[canale].fine_offset > 0x80){
434// fine_offset_da_dividere= Trimmer_offset_preampli[canale].fine_offset * guadagno_minimo_PGA; // <<2 perch\'e la misura \'e fatta all'uscita del pga,
435// //che ha guadagno 4, ovvero 2^2
436// fine_offset=0;
437// }else{
438// fine_offset_da_dividere=( 0xff - Trimmer_offset_preampli[canale].fine_offset) *guadagno_minimo_PGA; // <<2 perch\'e la misura \'e fatta all'uscita del pga,
439// //che ha guadagno 4, ovvero 2^2
440// fine_offset= 0xFF;
441// }
442// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (canale, preampli_fine_offset_trimmer, fine_offset);
443// Aspetta_tanti_ms(attesa);
444//// offset_fin=lettura_ADC( nodo_di_misura_1[canale]) - lettura_ADC( nodo_di_misura_2[canale]); //Il <<1 \'e per renderlo differenziale
445// offset_fin=correzione_misura_ADC(coeffcienti_misura_ADC_nodi[nodo_di_misura_1[canale]], offset_fin);
446// if ( (offset_fin < saturazione_positiva ) && (offset_fin >saturazione_negativa)){
447// fine_Trimmer_offset_step_actual[canale] = abs( offset_fin - offset_ini ) / fine_offset_da_dividere; //diviso 2^4 e diviso per 4 perch\'e all'uscita del pga
448// //Scrittura in memoria
449//// scrivi_mem_EPROM( Memory_preamplifier_address_fine_trimmer_slope_offset, fine_Trimmer_offset_step_actual[canale], canale);
450// }else{
451// tx_data[istruzione_byte_4_e_scelta_canale]=0xFF;
452// }
453
454// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (canale, preampli_fine_offset_trimmer, Trimmer_offset_preampli[canale].fine_offset);
455// //Adesso facciamo col coarse offset
456// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (canale, preampli_corse_offset_trimmer, coarse_offset);
457// Aspetta_tanti_ms(attesa);
458//// offset_fin=lettura_ADC( nodo_di_misura_1[canale]) - lettura_ADC( nodo_di_misura_2[canale]); //Il <<1 \'e per renderlo differenziale
459// offset_fin=correzione_misura_ADC(coeffcienti_misura_ADC_nodi[nodo_di_misura_1[canale]], offset_fin);
460// if ( (offset_fin < saturazione_positiva ) && (offset_fin >saturazione_negativa)){
461// coarse_Trimmer_offset_step_actual[canale] = abs( offset_fin - offset_ini ) /2/guadagno_minimo_PGA; //diviso 2 e diviso per 4 perch\'e all'uscita del pga
462// //Scrittura in memoria
463//// scrivi_mem_EPROM( Memory_preamplifier_address_coarse_trimmer_slope_offset, coarse_Trimmer_offset_step_actual[canale],canale);
464// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (canale, preampli_corse_offset_trimmer, Trimmer_offset_preampli[canale].coarse_offset);
465// }else{
466// tx_data[istruzione_byte_4_e_scelta_canale]=0xFF;
467// }
468
469// }else{
470// //La misura non si pu\'o fare perch\'e in saturazione e lo segnaliamo
471// tx_data[istruzione_byte_4_e_scelta_canale]=0xFF;
472// }
473// }else if(vettore_istruzioni_byte_3 ==2){
474// //trimmer termico
475// unsigned short trimmer_variato= Trimmer_offset_preampli[canale].coarse_thermal +4;
476// if (trimmer_variato > 0xFF){
477// trimmer_variato = Trimmer_offset_preampli[canale].coarse_thermal - 4;
478// }
479// if( (offset_ini < saturazione_positiva ) && (offset_ini > saturazione_negativa) ){
480// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (canale, preampli_coarse_thermal_trimmer, trimmer_variato);
481// Aspetta_tanti_ms(attesa);
482//// offset_fin=lettura_ADC( nodo_di_misura_1[canale]) - lettura_ADC( nodo_di_misura_2[canale]); //Il <<1 \'e per renderlo differenziale
483// offset_fin=correzione_misura_ADC(coeffcienti_misura_ADC_nodi[nodo_di_misura_1[canale]], offset_fin);
484// if ( (offset_fin < saturazione_positiva ) && (offset_fin >saturazione_negativa)){
485// coarse_Trimmer_thermal_step_actual[canale] = abs( offset_fin - offset_ini ) /4/guadagno_minimo_PGA; //diviso 4, che \'e la variazione,
486// // e diviso per 4 perch\'e all'uscita del pga
487// //Scrittura in memoria
488//// scrivi_mem_EPROM( Memory_address_coarse_trimmer_temp_slope_compensation, coarse_Trimmer_thermal_step_actual[canale],canale);
489// Imposta_canale_del_trimmer_ennesimo_al_valore_I2CA (canale, preampli_coarse_thermal_trimmer, Trimmer_offset_preampli[canale].coarse_thermal);
490// }else{
491// tx_data[istruzione_byte_4_e_scelta_canale]=0xFF;
492// }
493// }else{
494// tx_data[istruzione_byte_4_e_scelta_canale]=0xFF;
495// }
496// }
497// PGA_GAIN_set( canale, PGA_Gain_V_su_V_old); //Ristabiliamo il guadagno+
498// Aspetta_tanti_ms(attesa);
499// }
500// }
501
502//if( (chi_misuro & restore_coefficients) ){
503// if( vettore_istruzioni_byte_3 ==1){
504// //restore dei parametri del dettector bias
505// trimmer_bias_fine_step_actual[canale]= trimmer_bias_fine_step;
506//// scrivi_mem_EPROM( Memory_address_fine_trimmer_slope_bias, trimmer_bias_fine_step_actual[canale],canale);
507// trimmer_bias_coarse_step_actual[canale]=trimmer_bias_coarse_step;
508//// scrivi_mem_EPROM( Memory_address_coarse_trimmer_slope_bias, trimmer_bias_coarse_step_actual[canale],canale);
509// }else if (vettore_istruzioni_byte_3 ==0){
510// //restore dei parametri per l'offset
511// fine_Trimmer_offset_step_actual[canale] =fine_Trimmer_offset_step;
512//// scrivi_mem_EPROM( Memory_preamplifier_address_fine_trimmer_slope_offset, fine_Trimmer_offset_step_actual[canale],canale);
513// coarse_Trimmer_offset_step_actual[canale] = coarse_Trimmer_offset_step;
514//// scrivi_mem_EPROM( Memory_preamplifier_address_coarse_trimmer_slope_offset, coarse_Trimmer_offset_step_actual[canale],canale);
515// }else if (vettore_istruzioni_byte_3 == 2){
516// //restore dei parametri per la deriva termica
517// fine_Trimmer_thermal_step_actual[canale]= fine_Trimmer_thermal_step;
518//// scrivi_mem_EPROM( Memory_address_fine_trimmer_temp_slope_compensation, fine_Trimmer_thermal_step_actual[canale],canale);
519// coarse_Trimmer_thermal_step_actual[canale]=coarse_Trimmer_thermal_step;
520//// scrivi_mem_EPROM( Memory_address_coarse_trimmer_temp_slope_compensation, coarse_Trimmer_thermal_step_actual[canale],canale);
521// }
522//}
523
524
525// //Stampa coefficineti in uso
526// if( vettore_istruzioni_byte_3 ==1){
527// //Detector bias coefficients
528// coefficiente_in_mV =trimmer_bias_coarse_step_actual[canale] / 1000;
529// tx_data[0] = coefficiente_in_mV & 0xFF;
530// tx_data[1] = (coefficiente_in_mV >> 8) & 0xFF;
531// coefficiente_in_mV =trimmer_bias_fine_step_actual[canale] ;
532// tx_data[2] = coefficiente_in_mV & 0xFF;
533// tx_data[3] = (coefficiente_in_mV >> 8) & 0xFF;
534// }else if (vettore_istruzioni_byte_3 ==0 ){
535// //Preamplifier coefficients
536// coefficiente_in_mV =coarse_Trimmer_offset_step_actual[canale] / 1000;
537// tx_data[0] = coefficiente_in_mV & 0xFF;
538// tx_data[1] = (coefficiente_in_mV >> 8) & 0xFF;
539// coefficiente_in_mV =fine_Trimmer_offset_step_actual[canale] ;
540// tx_data[2] = coefficiente_in_mV & 0xFF;
541// tx_data[3] = (coefficiente_in_mV >> 8) & 0xFF;
542// } else if (vettore_istruzioni_byte_3 ==2){
543// coefficiente_in_mV =coarse_Trimmer_thermal_step_actual[canale] / 1000;
544// tx_data[0] = coefficiente_in_mV & 0xFF;
545// tx_data[1] = (coefficiente_in_mV >> 8) & 0xFF;
546// coefficiente_in_mV =fine_Trimmer_thermal_step_actual[canale] ;
547// tx_data[2] = coefficiente_in_mV & 0xFF;
548// tx_data[3] = (coefficiente_in_mV >> 8) & 0xFF;
549// }
550//}
551
552
553///*! \brief Calibration of some parameters of the ADC mainly
554
555//*\return No Parameters
556//\showrefby
557//\showrefs
558//\snippet{lineno} inizializzazione.c fun_instruction_ricalibrazione_scheda
559// */
560//! <!-- [fun_instruction_ricalibrazione_scheda] -->
561//void instruction_ricalibrazione_scheda(void){
562
563// calibrazione_Resistenze_sterne_ADC();
564//
565//}
566//! <!-- [fun_instruction_ricalibrazione_scheda] -->
567
568
569
570
571
572
573
574
575
void ADC_sleep_ON_OFF(uint8_t up_down, uint8_t ADC_ON_1_OFF_0_NOP_GT1)
ADC is set to sleep or awake.
Definition: Adc.c:350
void ADC_Wakeup(uint8_t up_down)
ADC Wakeup and 24 bits reading.
Definition: Adc.c:388
volatile uint8_t ADC_sleep_off
if 0 ADC in sleep when not working, ADC>1 ADC never sleep
Definition: Adc.c:205
void ADC_selfcal_zero_scale(uint8_t up_down)
ADC self-calibration. ADC needs to be pre-selected.
Definition: Adc.c:296
void ADC_scrittura_registro(char ADC_0_o_1, uint8_t up_down, uint8_t indirizzo_registro_ch0, int32_t value_to_write)
This function allows to read a whatver regsiter of the ADC.
Definition: Adc.c:654
volatile uint8_t rx_data[8]
Received data vector.
Definition: Can.c:318
void CAN_Inizialize(void)
The CAN initialization function.
Definition: Can.c:433
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
void Relays_driver_set_reset_channel(uint8_t scheda_su_giu, uint8_t numero_canale, uint8_t valore_da_trasmettere)
Setting the state of the detector realis: pre connected to detector or intrnal resistor,...
#define Detector_prea_to_GND
#define Detector_bias_diretto
#define Detector_large_RLOAD
void LED_pin_configuration(void)
Red and Green LED pin configuration and reset.
Definition: Gpio.c:284
void ADC_pin_configurations(void)
ADc pins are initialized here.
Definition: Gpio.c:362
void Configure_Reset_selection_port_analog_mux_ResIn_ADC_buffer(void)
Set the reset pins of te analog mux's. Take care: reset=0 means output off.
Definition: Gpio.c:308
void Configure_Reset_I2C_mux(void)
Set the reset pins of te I2C mux, reset the I2C mux and put them into operation.
Definition: Gpio.c:244
void Configure_Bit_Address_for_CAN(void)
Switches for the selection of the hw CAN bus address. Pin are set as input with internal pull-up.
Definition: Gpio.c:415
void I2C_0_Initialize(void)
The I2C_0 initialize.
Definition: I2C_0.c:369
void I2C_1_Initialize(void)
The I2C_1 initialize.
Definition: I2C_1.c:106
#define I2C_mux_Scheda_giu
Selection of the I2C1 for lower board (purtroppo \'e contorto)
Definition: I2C_mux.h:16
#define I2C_mux_Scheda_su
Selection of the I2C0 for the upper board (purtroppo \'e contorto)
Definition: I2C_mux.h:15
void termometro_sht_down(uint8_t scheda_su_scheda_giu, uint8_t canale)
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]
...
void I2C_to_Parallel_ini_PCA9554(uint8_t scheda_su_scheda_giu, uint8_t select_PCA)
The I2C_to_Parallel_ini_PCA9554 inits the I2C_to_Parallel_ini_PCA9554 chips by setting all the output...
#define I2C_to_Parallel_name_3
the third PCA
#define I2C_to_Parallel_name_1
the first PCA
#define I2C_to_Parallel_name_2
the second PCA
void Setting_of_the_pointer_for_command_parser(void)
The pointer to the instruction functions is constructed here.
Definition: Istruzioni.c:33
void LED_accendi_spegni(uint8_t LED, uint8_t accendi_1_spegni_0)
This function turns ON or OFF any of the selcted LED.
Definition: Led.c:123
#define LED_RED
Definition: Led.h:10
#define spegni
Definition: Led.h:13
#define LED_GREEN
Definition: Led.h:11
#define accendi
Definition: Led.h:12
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.
void EPROM_store_recover_state_M24C32_64(uint8_t scheda_su_scheda_giu, uint8_t canali_da_regolare, uint8_t set_1_store_0, uint8_t startup_1_user_0)
Store the system state or recover and apply the system state.
void EPROM_restore_detector_slopes_in_pream(uint8_t scheda_su_scheda_giu, uint8_t canale)
[fun_EPROM_store_recover_detector_voltage_M24C32_64]
@ Memory_mainboard_address_fw
Mainboard fw version.
@ Memory_postmainboard_ADCs_always_ON_0_powerdown_1
ADCs powerdown ON if 0, always ON if >1.
@ Memory_postmainboard_micro_PD_wait_time_in_sec
wait time before microcontroller power down since last operation
@ Memory_postmainboard_micro_powdown_active_1_alwaysON_0
microntroller aoutopower OFF if true, always ON if false
@ Memory_preamplifier_slope_calibration_ON_0_OFF_ff
slope 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
void PGA_trimmer_gain(uint8_t scheda_su_scheda_giu, uint8_t canale)
Here the PGA on mainboard implemented with trimmers in feedback is managed.
volatile uint32_t POWER_DOWN_MAX_ATTESA
upper limit for POWER_DOWN_TEMPO_ATTESA
Definition: Power_down.c:118
#define preamplifier_scrivi_il_trimmer
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
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
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
void instr_inizializza_tutto_da_zero_function(void)
Start-up function.
void instr_periferal_reset_function(void)
I2C, SPI and CAN can be rest.
#define __INT_DATE__
Here the fw version is created that coincides with the date of compilation.
bool flag_power_down
if flag_power_down is true the u-controller goes in power down after a while
volatile int8_t vettore_istruzioni[8]
This is a copy of the received 8 bytes from the CAN.
unsigned int FW_version
This is where the FW version is stored.
uint8_t I2C_to_parallel_chip_num
This is the I2C to parallel chip to which the driver is connectted, they are 3.
uint8_t I2C_to_parallel_chip__pin_num
This is the outputo pin to enable.