At least a mystery to me anyway has me scratching my head. Below are two test sketches, the first one does not work as expected, and the second one works great. Note the only difference between the two sketches is the MAP command for Thr_Us. Very simple circuit using a Pot to input voltage to a analog pin, read it and print it.
The first sketch is erratic. Mostly prints 800 uS through most of the range except ring in the middle of the span then spits out garbage numbers of 1400 to 1900. Second sketch works perfectly and I get a nice linear readout from 800 to 2200. What in the Devil is going on.
The first sketch is erratic. Mostly prints 800 uS through most of the range except ring in the middle of the span then spits out garbage numbers of 1400 to 1900. Second sketch works perfectly and I get a nice linear readout from 800 to 2200. What in the Devil is going on.
Code:
const int inPin_A3_Thr = A3; // Ana Input - Rudder potentiometer
int AI_Raw_THR = 0; // Ana In raw var - 0->2047
int Thr_Us = 1500; // Ana In var - 0->2047 compensated
void setup() {
analogReadResolution(13);// Sets ADC range to 11 bits (0 to 2043). Teensy 3.2 ranges from 10 to 13 bits
analogReadAveraging(4);//Average 4, 8, 16 and 32 readings, smooths stick input and jitter.
Serial.begin(9600); //Test only disable with // when not in use
}
void loop() {
AI_Raw_THR = analogRead(inPin_A3_Thr);
[COLOR="#FF0000"]//Thr_Us = map(AI_Raw_THR, 0, 8191, 800, 2200); // Throttle
Thr_Us = map(analogRead(AI_Raw_THR), 0, 8191, 800, 2200); // Throttle [/COLOR]
Serial.print( " Thr_Us="); //Test only disable with // when not in use
Serial.print(Thr_Us); //Test only disable with // when not in use
delay(10); //Test only disable with // when not in use
}
Code:
const int inPin_A3_Thr = A3; // Ana Input - Rudder potentiometer
int AI_Raw_THR = 0; // Ana In raw var - 0->2047
int Thr_Us = 1500; // Ana In var - 0->2047 compensated
void setup() {
analogReadResolution(13);// Sets ADC range to 11 bits (0 to 2043). Teensy 3.2 ranges from 10 to 13 bits
analogReadAveraging(4);//Average 4, 8, 16 and 32 readings, smooths stick input and jitter.
Serial.begin(9600); //Test only disable with // when not in use
}
void loop() {
AI_Raw_THR = analogRead(inPin_A3_Thr);
[COLOR="#FF0000"]Thr_Us = map(AI_Raw_THR, 0, 8191, 800, 2200); // Throttle
//Thr_Us = map(analogRead(AI_Raw_THR), 0, 8191, 800, 2200); // Throttle [/COLOR]
Serial.print( " Thr_Us="); //Test only disable with // when not in use
Serial.print(Thr_Us); //Test only disable with // when not in use
delay(10); //Test only disable with // when not in use
}
Last edited: