CROSS Technical Documentation User Manual and Technical Doc.
INFN Milano Bicocca
Loading...
Searching...
No Matches

◆ ADC_lettura_24bit()

long int ADC_lettura_24bit ( char  line_to_read_to_select_ADCch0_ADCch1,
uint8_t  up_down,
uint8_t  cosa_fare 
)

ADC Wakeup and 24 bits reading.

Parameters
[in]line_to_read_to_select_ADCch0_ADCch1: which of the 2 channels within the ADC has to be considered, if =50 ADC ch0 if =51 ADC ch 1
[in]up_down: which boards: up or down
[in]cosa_fare: cosa_fare=1 measurement is launched, but the result is not waited; cosa_fare=2 measurement is launched end the result is waited, cosa_fare=3 only the result is waited
Returns
risultato : the measurement result in microV
433long int ADC_lettura_24bit(char line_to_read_to_select_ADCch0_ADCch1 , uint8_t up_down, uint8_t cosa_fare){
434 //cosa_fare=1 measurement is launched, but the result is not waited
435 //cosa_fare=2 measurement is launched end the result is waited
436 //cosa_fare=3 only the result is waited
437 //Exploting cosa_fare the ADCs can be operated in parallel. The parallel operation is not posssible
438 //with the 2 ADC of the same chip. If the function is called with cosa_fare= 2/3 with the same value of
439 //up_down the results will be unpredictable.
440 uint8_t ADC_0_o_1;
441 uint8_t limite;
442 ARM_SPI_STATUS errorone;
443 unsigned int risultato_= 0xffffffff;
444// unsigned long int registro_di_controllo;
445 if (up_down>1) up_down=1;
446 status = SPIdrv->Control(SPI_control_for_relay_driver,spi_clock_for_relais);
448 long int risultato=0;
449 if ( ADC_node_map[line_to_read_to_select_ADCch0_ADCch1] < 16) ADC_0_o_1=0;
450 if ( (ADC_node_map[line_to_read_to_select_ADCch0_ADCch1] >=16) ) ADC_0_o_1=1;
451
452 uint8_t ii=0,scelta_ADC=ADC_mode_reg_ch0, valore_da_trasmettere[4]={0,0,0,0};
453 uint8_t indirizzo_registro_lettura=read_from_CH0 ;
454 uint8_t valore_da_ricevere[4];
455 const porta_pin_def *ref_locale, *ref_locale_ADCready, *ref_locale_ResBuffer, *ref_locale_ResBuffer_;
456
457 if ( up_down == I2C_mux_Scheda_giu){
458 ref_locale =&ADC_Chip_Sel_down;
459 ref_locale_ADCready=&ADC_ready_down; //Ready pin of ADC down
460 ref_locale_ResBuffer = &ADC_ResIn_B_buffer_down;//switch for buffer resistor on/off
461 ref_locale_ResBuffer_ = &ADC_ResIn_A_buffer_down;//switch for buffer resistor on/off
462// if( ADC_0_o_1){
463// ref_locale_ResBuffer = &ADC_ResIn_B_buffer_down;//switch for buffer resistor on/off
464// }else{
465// ref_locale_ResBuffer = &ADC_ResIn_A_buffer_down;//switch for buffer resistor on/off
466// }
467 }else{
468 ref_locale =&ADC_Chip_Sel_up;
469 ref_locale_ADCready=&ADC_ready_up; //Ready pin of ADC up
470 ref_locale_ResBuffer = &ADC_ResIn_B_buffer_up;//switch for buffer resistor on/off
471 ref_locale_ResBuffer_ = &ADC_ResIn_A_buffer_up;//switch for buffer resistor on/off
472// if( ADC_0_o_1){
473// ref_locale_ResBuffer = &ADC_ResIn_B_buffer_up;//switch for buffer resistor on/off
474// }else{
475// ref_locale_ResBuffer = &ADC_ResIn_A_buffer_up;//switch for buffer resistor on/off
476// }
477 }
478 if (ADC_0_o_1==1){
479 scelta_ADC=ADC_mode_reg_ch1; //indirizzo registro start misura
480 indirizzo_registro_lettura=read_from_CH1; //indirizzo lettura misura
481 }
482 if (cosa_fare <=2 ){// Si sceglie di fare partire a misura
483 ADC_sleep_ON_OFF(scheda_su_scheda_giu , 2 + ADC_sleep_off ); //ADC on se serve
484// ADC_Wakeup(up_down);
485 GPIO_PinWrite(ref_locale->porta_num, ref_locale->pin_num, 0); // Viene abbassato il chip selector ADC per la lettura
486// if( ADC_sleep_off==0){
487// GPIO_PinWrite(ref_locale_ResBuffer->porta_num, ref_locale_ResBuffer->pin_num, 0); // Togliamo il consumo che simula l'ADC
488// GPIO_PinWrite(ref_locale_ResBuffer_->porta_num, ref_locale_ResBuffer_->pin_num, 0); // Togliamo il consumo che simula l'ADC
489// }
491 //SI lancia la misura dell'ADC selezionato
492 valore_da_trasmettere[0]= scelta_ADC; valore_da_trasmettere[1]= ADC_mode_reg_set_single_24bit;
493 evento_SPI=0;
494 SPIdrv->Send ( &valore_da_trasmettere ,2);
495 limite=0;
496// while( (SPIdrv->GetStatus().busy) && (limite<10) ){
497 while( (evento_SPI==0) && (limite<10) ){
499 limite++;
500 }
501 if( (limite>=10) || Error_bad_operation){
502 errorone=SPIdrv->GetStatus();
503 status = SPIdrv->Control(ARM_SPI_ABORT_TRANSFER,0);
505 }
506 GPIO_PinWrite(ref_locale->porta_num, ref_locale->pin_num, 1); // Viene alzto il chip selector ADC per la lettura
507 }
508 if(cosa_fare > 1){//Polling di fine misura solo nei casi selezionati
509 uint8_t registro38= (ADC_lettura_registro(ADC_0_o_1,up_down,0x38)>>16) & 0xFF;
510 //Leggiamo il registro 0x38 per verificare che l'ADc non sia in standby
511 if ( registro38 != 0x70){
512 //Attesa misura disponibile
513 limite=0;
514 while (( GPIO_PinRead(ref_locale_ADCready->porta_num,ref_locale_ADCready->pin_num) == 1 ) && (limite<10)){
516 limite++;
517 }
518 if( (limite>=10) ) ERROR_codifica_errore(up_down, error_address_reg_ADC0, ADC_RDY_pin_fault, 1);
519
520 GPIO_PinWrite(ref_locale->porta_num, ref_locale->pin_num, 0); // Viene abbassato il chip selector ADC per la lettura
521 //Leggiamo il risultato della lettura
522 uint8_t dati_da_trasmettere[]={indirizzo_registro_lettura,0,0,0};
523 SPIdrv->Transfer (&dati_da_trasmettere, &valore_da_ricevere ,4);
524 limite=0;
525 while( (SPIdrv->GetStatus().busy) && (limite<10) ){
527 limite++;
528 }
529 if( (limite>=10) || Error_bad_operation){
530 errorone=SPIdrv->GetStatus();
531 status = SPIdrv->Control(ARM_SPI_ABORT_TRANSFER,0);
533 }
534
535 GPIO_PinWrite(ref_locale->porta_num, ref_locale->pin_num, 1); // Viene alzto il chip selector ADC per la lettura
536 //Il primo byte letto \'e il MSB
537 risultato_ =(valore_da_ricevere[1]<<16) + (valore_da_ricevere[2]<<8 )+( valore_da_ricevere[3] );
538
539 GPIO_PinWrite(ref_locale->porta_num, ref_locale->pin_num, 1); // Viene alzato il chip selector ADC
540// if( ADC_sleep_off==0){
541// GPIO_PinWrite(ref_locale_ResBuffer->porta_num, ref_locale_ResBuffer->pin_num, 1); // Riconsumiamo dummy
542// GPIO_PinWrite(ref_locale_ResBuffer_->porta_num, ref_locale_ResBuffer_->pin_num, 1); // Riconsumiamo dummy
543// }
544 /* Per convertire il risultato in MICROVOLT si dovrebbe fare: (risultato/2^24*20E6) -10E6
545 Una formula equivalente \'e: { [(risultato*2)-(2^24)]*10E6 } / 2^24
546 Notando che 10^6 = (78125 * 2^7) allora 10^6 / 2^24 = 78125 / 2^17 */
547 risultato = ( (long long int) ( (int)(risultato_ << 1) - (1 << 24) ) * 78125 ) >> 17 ;
548 }
549// ADC_Sleep_fun(up_down + +ADC_sleep_off);
550 ADC_sleep_ON_OFF(scheda_su_scheda_giu , 0 + ADC_sleep_off ); //ADC off se serve
551 }
552
553 return risultato; //Risultato in microV
554}
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
long int ADC_lettura_24bit(char line_to_read_to_select_ADCch0_ADCch1, uint8_t up_down, uint8_t cosa_fare)
ADC Wakeup and 24 bits reading.
Definition: Adc.c:433
uint32_t ADC_lettura_registro(char ADC_0_o_1, uint8_t up_down, uint8_t registro_ch0)
This function allows to read a whatver regsiter of the ADC.
Definition: Adc.c:592
volatile uint8_t ADC_sleep_off
if 0 ADC in sleep when not working, ADC>1 ADC never sleep
Definition: Adc.c:205
#define spi_clock_for_relais
[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.
@ ADC_RDY_pin_fault
ADC ready not received.
@ error_address_reg_ADC0
Error register for ADC0.
@ error_address_SPI
Error register for SPI.
const porta_pin_def ADC_ready_down
Configuration ADC pin.
Definition: Gpio.c:148
const porta_pin_def ADC_Chip_Sel_up
Configuration ADC pin.
Definition: Gpio.c:146
const uint8_t ADC_node_map[]
Mapping to mux's on postmainboard. Its syntax: bits 0 to 3 are common to all the MUXs and select one ...
Definition: Gpio.c:172
const porta_pin_def ADC_ready_up
Configuration ADC pin.
Definition: Gpio.c:145
const porta_pin_def ADC_ResIn_A_buffer_down
Refernce to fgnd of theADC input buffer, if 1 there is a 10kOhm connected to GND.
Definition: Gpio.c:113
const porta_pin_def ADC_ResIn_A_buffer_up
Refernce to fgnd of theADC input buffer, if 1 there is a 10kOhm connected to GND.
Definition: Gpio.c:115
const porta_pin_def ADC_Chip_Sel_down
Configuration ADC pin.
Definition: Gpio.c:149
const porta_pin_def ADC_ResIn_B_buffer_down
Refernce to fgnd of theADC input buffer, if 1 there is a 10kOhm connected to GND.
Definition: Gpio.c:114
const porta_pin_def ADC_ResIn_B_buffer_up
Refernce to fgnd of theADC input buffer, if 1 there is a 10kOhm connected to GND.
Definition: Gpio.c:116
#define I2C_mux_Scheda_giu
Selection of the I2C1 for lower board (purtroppo \'e contorto)
Definition: I2C_mux.h:16
uint32_t evento_SPI
This is the variable which resembles the flags from the communication.
Definition: Spi.c:151
#define SPI_control_for_relay_driver
[ref_SPI_control_for_relay_driver]
Definition: Spi.h:10
void Aspetta_tanti_ms(int millisecondi)
The timing function.
Definition: Timer.c:52
Definition: Gpio.h:13

Definition at line 433 of file Adc.c.