19-10-2024, 04:34 PM
(Modification du message : 19-10-2024, 04:51 PM par Youpimatin.)
Certes... voici néanmoins une solution clé en main, André :
void MeasurePower() { //Lecture Tension et courants pendant 20ms
int iStore;
value0 = analogRead(AnalogIn0); //Mean value. Should be at 3.3v/2
static unsigned long OverflowOffset = 0;
static unsigned long PrevMicros = 0;
unsigned long NowMicros;
unsigned long MeasureMillis = millis();
while (millis() - MeasureMillis < 21) { //Read values in continuous during 20ms. One loop is around 150 micro seconds
NowMicros = micros();
if(NowMicros < PrevMicros) {
OverflowOffset += 7296;
}
iStore = ((NowMicros + OverflowOffset) % 20000) / 200; //We have more results that we need during 20ms to fill the tables of 100 samples
volt[iStore] = analogRead(AnalogIn1) - value0;
amp[iStore] = analogRead(AnalogIn2) - value0;
PrevMicros = NowMicros;
}
}
...pas forcément la plus élégante, mais fonctionnelle et rapide, un copier-coller et c'est bon.
void MeasurePower() { //Lecture Tension et courants pendant 20ms
int iStore;
value0 = analogRead(AnalogIn0); //Mean value. Should be at 3.3v/2
static unsigned long OverflowOffset = 0;
static unsigned long PrevMicros = 0;
unsigned long NowMicros;
unsigned long MeasureMillis = millis();
while (millis() - MeasureMillis < 21) { //Read values in continuous during 20ms. One loop is around 150 micro seconds
NowMicros = micros();
if(NowMicros < PrevMicros) {
OverflowOffset += 7296;
}
iStore = ((NowMicros + OverflowOffset) % 20000) / 200; //We have more results that we need during 20ms to fill the tables of 100 samples
volt[iStore] = analogRead(AnalogIn1) - value0;
amp[iStore] = analogRead(AnalogIn2) - value0;
PrevMicros = NowMicros;
}
}
...pas forcément la plus élégante, mais fonctionnelle et rapide, un copier-coller et c'est bon.