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

◆ Relays_driver_set_reset_channel()

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, polarity of the detector bias, load resistro choiche and internal or external detector bias.

Parameters
[in]scheda_su_giuthe board to be managed of the 2 available
[in]numero_canalethe channel for which we need to manage the relay
[in]valore_da_trasmetterethe relay to be managed
Returns
No Parameters
110 void Relays_driver_set_reset_channel(uint8_t scheda_su_giu, uint8_t numero_canale , uint8_t valore_da_trasmettere){
111
112 SPIdrv->Control(SPI_control_for_relay_driver, spi_clock_for_relais); // SPI fits Relay driver specs at 8 bits and speed
113 //Detector Relays Drivers reset and un-reset all together with the reset pin
114 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_giu, detector_reset_all_relays_driver.I2C_to_parallel_chip_num, detector_reset_all_relays_driver.I2C_to_parallel_chip__pin_num);
115 Aspetta_tanti_ms(10);
116 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_giu, detector_reset_all_relays_driver.I2C_to_parallel_chip_num, \
117 I2C_to_Parallel_ini_set[detector_reset_all_relays_driver.I2C_to_parallel_chip_num] );
119
120 //Chip_select: now select the chip to speak with
121 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_giu, detector_chip_select_bias[numero_canale].I2C_to_parallel_chip_num, \
122 detector_chip_select_bias[numero_canale].I2C_to_parallel_chip__pin_num);
124// SPItx(valore_da_trasmettere);
125 SPIdrv->Send ( &valore_da_trasmettere ,1); //send the 16 bits
126// while( SPIdrv->GetStatus().busy ){} //wait end of transmission
127// Aspetta_tanti_ms(1);
128
129 uint8_t troppa_attesa=0;
130 while( (SPIdrv->GetStatus().busy) && (troppa_attesa <250) ){
132 troppa_attesa++;
133 } //wait end of transmission ;
134 if((troppa_attesa>=250) || (Error_bad_operation)) ERROR_codifica_errore(scheda_su_giu, error_address_SPI, SPI_error_EVENT_DATA_LOST,1);
135
136 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_giu, detector_chip_select_bias[numero_canale].I2C_to_parallel_chip_num,\
137 I2C_to_Parallel_ini_set[detector_chip_select_bias[numero_canale].I2C_to_parallel_chip_num]); //Set the driver OFF: it is important to switch off the chip because ony in this moment the outputs are
138 // enabled
139 Aspetta_tanti_ms(wait_time_for_rele_setting); //Wait the time the relay takes action, 5 ms at least.
140
141 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_giu, detector_chip_select_bias[numero_canale].I2C_to_parallel_chip_num, \
142 detector_chip_select_bias[numero_canale].I2C_to_parallel_chip__pin_num);//Select the cip again
144// SPItx(0);
145 uint8_t zero=0;
146 SPIdrv->Send ( &zero ,1); // Set high all the ouputs
148 I2C_to_Parallel_set_PCA9554_outputs_values( scheda_su_giu, detector_chip_select_bias[numero_canale].I2C_to_parallel_chip_num,\
149 I2C_to_Parallel_ini_set[detector_chip_select_bias[numero_canale].I2C_to_parallel_chip_num]); //Disable the chip and set high the ouputs
151
152//Qui consideriamo la varibaile di stato per il detector relay
153 uint8_t canalone=scheda_su_giu *6 + numero_canale;
154 if (valore_da_trasmettere & Detector_prea_to_det){
156 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_prea_to_GND);
157 }else if (valore_da_trasmettere & Detector_prea_to_GND){
159 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_prea_to_det);
160 }
161 if (valore_da_trasmettere & Detector_large_RLOAD){
163 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_small_RLOAD);
164 }else if (valore_da_trasmettere & Detector_small_RLOAD){
166 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_large_RLOAD);
167 }
168 if (valore_da_trasmettere & Detector_external_bias){
170 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_internal_bias);
171 }else if(valore_da_trasmettere & Detector_internal_bias){
173 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_external_bias);
174 }
175 if (valore_da_trasmettere & Detector_bias_invertito){
177 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_bias_diretto);
178 }else if(valore_da_trasmettere & Detector_bias_diretto){
180 detector_Relay_state[canalone] &= ~(uint8_t)(Detector_bias_invertito);
181 }
182
183 }
uint8_t detector_Relay_state[12]
The state of the Detector realis is considerede. Note that this is the wanted working condition....
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_small_RLOAD
#define Detector_prea_to_det
#define wait_time_for_rele_setting
[ref_spi_clock_for_relais]
#define Detector_bias_invertito
#define Detector_external_bias
#define Detector_internal_bias
#define Detector_prea_to_GND
#define Detector_bias_diretto
#define spi_clock_for_relais
[ref_spi_clock_for_relais]
#define Detector_large_RLOAD
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.
@ 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 struct chip_select_type detector_chip_select_bias[6]
This is the vector of constant values which allows to enable the relays drivers of each channels,...
const uint8_t I2C_to_Parallel_ini_set[4]
...
#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
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.

Definition at line 110 of file Detector_Relays_managing.c.