3#include "tutti_gli_header.h"
109void PGA_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t PGA_gain_to_set ){
111 uint8_t offset_schdea=0;
112 if (scheda_su_scheda_giu){
114 scheda_su_scheda_giu=6;
125 PGA_DAC_GAIN_CROSS( scheda_su_scheda_giu, canale, PGA_gain_to_set, PGA_gain_for_second_stage);
145 uint8_t spedizione[2];
146 if( scheda_su_scheda_giu) scheda_su_scheda_giu=6;
153 if( set_2_reset_1_idle_0) {
155 spedizione[0] = set_2_reset_1_idle_0 << 1 ;
160 while( I2C_mux->GetStatus().busy);
170 while( I2C_mux->GetStatus().busy);
174 while( I2C_mux->GetStatus().busy){};
193void PGA_DAC_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t guadagno_da_impostare, uint8_t PGA_si_NO){
199 uint8_t offset_scheda=0;
200 if (scheda_su_scheda_giu){
227 SPIdrv->Uninitialize();
231 uint16_t PGA_code =1+ (( (fondo_scala_DAC_PGA *
guadagno_minimo_PGA) * PGA_si_NO) / guadagno_da_impostare);
232 if ( PGA_code > 0x3ff) PGA_code=0x3ff;
233 PGA_code = (PGA_code<<4) & 0x3FFF ;
242 PGA_DAC_chip_select[canale].I2C_to_parallel_chip__pin_num );
245 SPIdrv->Send ( &PGA_code ,1);
249 uint8_t troppa_attesa=0;
250 while( (SPIdrv->GetStatus().busy) && (troppa_attesa <250) ){
269 SPIdrv->Uninitialize();
278unsigned int PGA_Gain_code[2];
279unsigned int PGA_Gain_V_su_V[2];
292void PGA_GAIN(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t guadagno_da_impostare){
321 unsigned short PGA_code = ((fondo_scala_DAC_PGA *
guadagno_minimo_PGA) * PGA_si_NO / guadagno_da_impostare) ;
325 SPIdrv->Uninitialize();
331 PGA_DAC_chip_select[canale].I2C_to_parallel_chip__pin_num );
333 SPItx_16_per_il_DAC( (PGA_code<<4) & 0x3FFF);
341 SPIdrv->Uninitialize();
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};
393 for( canale=0;canale<2;canale++){
394 if( (chi_aggiustiamo >> canale) & 1){
396 valore_target_per_offset[canale]=correzione_misura_ADC(coeffcienti_misura_ADC_nodi[nodo_di_misura_1[canale]], offset);
398 if( (valore_target_per_offset[canale] >= saturazione_positiva) || ( valore_target_per_offset[canale] <= saturazione_negativa ) ) {
399 valore_target_per_offset[canale]=0;
402 valore_target_per_offset[canale] = ( valore_target_per_offset[canale] * (int)
guadagno_minimo_PGA ) / (int)guadagno_da_impostare ;
417 for( canale=0;canale<2;canale++){
418 if( (chi_aggiustiamo >> canale) & 1){
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);
446 signed char PGA_si_NO=1;
454 if ( (canale >> ii) & 1) {
455 if ( guadagno_da_impostare < gain_pre_PGA_x_2){
457 Detector_PGA_Rele( ( (ii<<4) | 8));
462 Detector_PGA_Rele( ( (ii<<4) | 9));
466 Detector_PGA_Rele( ( (ii<<4) | 8));
475 unsigned short PGA_code = ((fondo_scala_DAC_PGA *
guadagno_minimo_PGA) * PGA_si_NO / guadagno_da_impostare) ;
479 if ( (canale >> ii) & 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;
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;
492 SPIdrv->Uninitialize();
495 GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 0);
497 SPItx_16_per_il_DAC( (PGA_code<<4) & 0x3FFF);
499 GPIO_PinWrite(local_pin_port.porta_num, local_pin_port.pin_num, 1);
502 SPIdrv->Uninitialize();
uint8_t tx_data[8]
Transmission data vector.
void instruction_for_PGA_GAIN_set(void)
The second stage gain is settable here.
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...
uint8_t massimo_guadagno_impostabile
uint8_t guadagno_minimo_PGA
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.
uint8_t PGA_settled_gain[12]
PGA set gain.
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.
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...
void PGA_GAIN_set(char canale, unsigned int guadagno_da_impostare)
It sets the new gain irrespective of the offset.
void PGA_DAC_GAIN_CROSS(uint8_t scheda_su_scheda_giu, uint8_t canale, uint8_t guadagno_da_impostare, uint8_t PGA_si_NO)
#define PGA_pre_PGA_max_gain
#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.
#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.
#define set_pre_pga_idle
The swirches are set both off.
#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.
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
#define istruzione_byte_4_e_scelta_canale
void SPI_Inizialize_per_il_DAC(void)
SPI is initialized here for DAC. Remember to set the variable SPI_speed before the call....
void SPI_Inizialize(void)
SPI is initialized here. Its ise t at 8 bits and 100 KHz, as default.
void Aspetta_tanti_ms(int millisecondi)
The timing function.
const struct address_detector_bias_trimmer_type address_detector_bias_trimmer[6]
Detector trimmer addresses.
uint8_t contenuto_trimmer_detector[12][4]
Content of the trimmer for detector bias system.
volatile int8_t vettore_istruzioni[8]
This is a copy of the received 8 bytes from the CAN.