Hi,
When I test this code:
#include "voieRC.h"
#define Serial SerialUSB
#define pinVoieGAZ 20
voieRC voieGAZ(pinVoieGAZ);
void setup() {
attachInterrupt(pinVoieGAZ, interruptRC_GAZ, CHANGE);
}
void loop() {
SerialUSB.println(voieGAZ.valeur());
//delay(50);
}
void interruptRC_GAZ(void) {
voieGAZ.etat();
}
voieRC::voieRC(int pin){
pinRC = pin;
pinMode(pin, INPUT_PULLUP);
}
unsigned int voieRC::valeur() const{
return (lastValidValue);
}
class voieRC{
public:
voieRC(int);
unsigned int valeur() const;
void etat();
private:
int pinRC;
unsigned int timeUP;
unsigned int timeDOWN;
unsigned int lastValidValue;
};
void voieRC::etat() {
//noInterrupts();
if (digitalRead(this->pinRC) == HIGH) { // Front montant
timeUP = micros();
timeDOWN = timeUP;
}
else { // Front descendant
timeDOWN = micros();
lastValidValue = timeDOWN - timeUP;
}
//interrupts();
}
I find that I have some data outliers.
Here is the data received through the USB port:
http://bernard.o.perso.neuf.fr/Electronic/MAPLE/BugRC/sansServo.txt
http://bernard.o.perso.neuf.fr/Electronic/MAPLE/BugRC/radioSansServo.txt
http://bernard.o.perso.neuf.fr/Electronic/MAPLE/BugRC/avecServo.txt
Here is the graph:
http://bernard.o.perso.neuf.fr/Electronic/MAPLE/BugRC/avecServo.jpg
Data are not usable as it stands.
You will find on this webpage for a video with the consequences of this problem:
http://bernard.o.perso.neuf.fr/Electronic/MAPLE/BugRC/BugRC.htm
My questions:
* Is there a programming error, is there any other way to avoid this?
* Is there an error in the wiring?
* How to eliminate these values?
thank you for your answers.