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

◆ PGA_GAIN_set()

void PGA_GAIN_set ( char  canale,
unsigned int  guadagno_da_impostare 
)

It sets the new gain irrespective of the offset.

Parameters
[in]canalewhich channels to adjust
[in]guadagno_da_impostarethe gain to set
Returns
No Parameters.
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}
uint8_t massimo_guadagno_impostabile
Definition: DAC_PGA.c:89
uint8_t guadagno_minimo_PGA
Definition: DAC_PGA.c:88
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
#define istruzione_byte_3
Definition: Istruzioni.h:23
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
volatile int8_t vettore_istruzioni[8]
This is a copy of the received 8 bytes from the CAN.
Definition: Gpio.h:13

Definition at line 443 of file DAC_PGA.c.