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

◆ PGA_DAC_GAIN_CROSS()

void PGA_DAC_GAIN_CROSS ( uint8_t  scheda_su_scheda_giu,
uint8_t  canale,
uint8_t  guadagno_da_impostare,
uint8_t  PGA_si_NO 
)


It sets the PGA gain irrespective of the offset

Parameters
[in]scheda_su_scheda_giuis the board up or down
[in]canalechi_aggiustiamo which channels to adjust
[in]guadagno_da_impostarethe gain to set
[in]PGA_si_NODAC PGA is not set if this parameter is 0
Returns
No Parameters.
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}
uint8_t massimo_guadagno_impostabile
Definition: DAC_PGA.c:89
uint8_t guadagno_minimo_PGA
Definition: DAC_PGA.c:88
uint8_t PGA_settled_gain[12]
PGA set gain.
Definition: DAC_PGA.c:95
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
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.
@ 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_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 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

Definition at line 193 of file DAC_PGA.c.