Prendo questa parte di programma per spiegare come si traduce un programma in Italiano, guardate questa immagine:
Qui fornisce il titolo a cosa farà la parte successiva del programma, che si chiama
chargeHighVoltages
Codice: Seleziona tutto
/****************************************************************************
* Charges up the high-voltage capacitor banks to the target values
****************************************************************************/
Dichiara (void) la funzione chargeHighVoltages
Spegne tutti i mosfet (buona pratica quando non si sa da quale funzione precedente si arriva
Codice: Seleziona tutto
digitalWrite(FIRE1_PIN, LOW); //Turn off MOSFETs (fail-safe measure)
digitalWrite(FIRE2_PIN, LOW);
digitalWrite(CHARGE1_PIN, LOW);
digitalWrite(CHARGE2_PIN, LOW);
digitalWrite(DISCHARGE1_PIN, LOW);
digitalWrite(DISCHARGE2_PIN, LOW);
Vedere il partitore di tensione che ha per uscita VA1, per esser sicuro di non eccedere mai i 5V sull'ingresso dell'Arduino:
E vedere qui l'ingresso VA1 sull'Arduino Master:
Legge le tensioni ricavate dallo schema precedente (VA1_PIN è appuntol'ingresso di VA1, stessa cosa fa per VA2):
Codice: Seleziona tutto
measuredValues[HV1] = analogRead(VA1_PIN); //Measure the high voltage and store the value
measuredValues[HV2] = analogRead(VA2_PIN); //Measure the high voltage and store the value
Non carica entrambi i gruppi di condensatori insieme, ma prima carica quelli relativi a HV1 controllando la tensione:
Codice: Seleziona tutto
//While either storage cap is not charged to the correct voltage, alternately charge each cap
//NB: Both cannot be charged simultaneously or one may hold down the supply to the other.
while((measuredValues[HV1] != targetValues[HV1]) || (measuredValues[HV2] != targetValues[HV2])){
while(measuredValues[HV1] < (targetValues[HV1]-0)) {//If voltage is too low, charge capacitor
digitalWrite(CHARGE1_PIN, HIGH);
measuredValues[HV1] = analogRead(VA1_PIN); //Keep checking the voltage
}
E quando è corretta isola i condensatori dal resto del circuito (vedere sempre prima immagine animata):
Codice: Seleziona tutto
digitalWrite(CHARGE1_PIN, LOW); //Done, isolate this storage capacitance. It will begin to discharge slowly.
Ripete la stessa procedura per il secondo gruppo di condensatori di HV2:
Codice: Seleziona tutto
measuredValues[HV2] = analogRead(VA2_PIN); //Measure the high voltage and store the value
while(measuredValues[HV2] < (targetValues[HV2]-0)) {//If voltage is too low, charge capacitor
digitalWrite(CHARGE2_PIN, HIGH);
measuredValues[HV2] = analogRead(VA2_PIN); //Keep checking the voltage
}
digitalWrite(CHARGE2_PIN, LOW); //Done, isolate this storage capacitance. It will begin to discharge slowly.
Controlla di nuovo per sicurezza i condensatori del primo banco HV1, che non si siano scaricati nel frattempo.
Codice: Seleziona tutto
measuredValues[HV1] = analogRead(VA1_PIN);//Check first capacitor bank again
}