first commit

This commit is contained in:
Jérôme Delacotte
2025-03-06 11:15:32 +01:00
commit 7b30d6e298
5276 changed files with 2108927 additions and 0 deletions

View File

@@ -0,0 +1,137 @@
#ifdef PIN_HALL
//int mVperAmp = 66; // 185 pour 5A, use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
//int ACSoffset = 2500;
//double mp_offset = 0.040;
//double Voltage = 0;
//double Amps = 0;
void getHall();
float getVPP();
int mVperAmp = 48; // 185 pour 5, use 100 for 20A Module and 66 for 30A Module
double VRMS = 0;
double Amps = 0;
//void getHall()
//{
// double Voltage = getVPP();
// Serial.print(Voltage);
// Serial.print(" mv ");
// VRMS = (Voltage / 2.0) * 0.707; //root 2 is 0.707
// Amps = (VRMS * 1000) / mVperAmp;
// Serial.print();
// Serial.println(" Amps RMS");
//}
//
//float getVPP()
//{
// float result;
// int readValue; //value read from the sensor
// int maxValue = 0; // store max value here
// int minValue = 1024; // store min value here
//
// uint32_t start_time = millis();
// while ((millis() - start_time) < 1000) //sample for 1 Sec
// {
// readValue = analogRead(PIN_HALL);
// // see if you have a new maxValue
// if (readValue > maxValue)
// {
// /*record the maximum sensor value*/
// maxValue = readValue;
// }
// if (readValue < minValue)
// {
// /*record the minimum sensor value*/
// minValue = readValue;
// }
// }
//
// // Subtract min from max
// result = ((maxValue - minValue) * 5.0) / 1024.0 - 0.06;
//
// return result;
//}
//
//#ifdef PIN_HALL
void getHall(){
int i = 0;
RawValue = 0;
// Somme du courant alternatif pendant 20 ms ==> 50hz
// Détermination du max et max pour hauteur de crete
int vmin = 4096;
int vmax = 0;
int sum = 0;
const int bcl = 2000;
for (i = 0; i < bcl; i++) {
int value = analogRead(PIN_HALL);
if (value >= 0) {
RawValue += value;
vmax = max(value,vmax);
vmin = min(value,vmin);
sum += value;
} else {
i--;
}
delayMicroseconds(100);;
}
// Serial.print("Raw Value = " );
// Serial.print(RawValue);
Serial.print("min = " );
Serial.print(vmin);
Serial.print(" max = " );
Serial.print(vmax);
// Serial.print(" i =" );Amps
// Serial.print(i);
// RawValue = RawValue / i;
// Tension continue
// Voltage = (RawValue / 1023.0) * 5000; // Gets you mV
// Amps = ((Voltage - ACSoffset) / mVperAmp);
// La valeur maxi * racine carrée de 2 pour obtenir la tension "réelle"
// La tension efficace pour l'effet Hall étant réduite d'un facteur 0,707
//VRMS = ((vmax - vmin) / 430.0) * 5000;
double average = sum / bcl;
VRMS = 1000 * (((average) / 4095.0) * 3.3 - 2.43);
//Amps = max(5.5 * (vmax - vmin) / 473.0 -0.0580, 0.0); // <= pour le bruit
Amps = (VRMS / mVperAmp);
// Serial.print(" Raw Value = " ); // shows pre-scaled value
// Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(VRMS,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.print(Amps,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Watt = "); // shows the voltage measured
Serial.print(Amps * 220,3);
Serial.print("\t WattH = "); // shows the voltage measured
Serial.println(Amps * 220 / 1200,3);
// long sum = 0;
// for (int i = 0; i < numSamples; i++) {
// int sample = analogRead(PIN_HALL);
// sum += sample;
// delayMicroseconds(100);
// }
//
// float average = sum / numSamples;
// VRMS = (average / 4095.0) * 3.3; // Convertir l'échantillon ADC en tension (ESP32 utilise 3.3V référence ADC)
// float currentOffset = VRMS - offset; // Calculer l'offset du courant
// Amps = currentOffset / sensitivity; // Calculer le courant en utilisant la sensibilité de l'ACS712
}
//#endif
#endif