0

Under normal operation, the value of a joystick's ADC range on my board is from 0 to 1023 (10-bits). However, my graph for either axis is not continuous. Rather, there is more than one min and maximum for both axis. I am running this thread on a MSP432P401R however the code isn't any different than an Arduino.

int jumpFlag;
int backwardsFlag;
int forwardsFlag;
int selPin = P5_1; //Select digital pin location
int xOutPin = A14;
int yOutPin = A13;

void setupPlayerActions() {
  pinMode(selPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(selPin),jumpISR,RISING);
  //pinMode(xOutPin, ); //Analog X pin setup
  //pinMode(xOutPin, ); //Analog Y pin setup
}

void jumpISR() {
  Serial.println("Jump Detected!");
  jumpFlag = 1;
}


void loopPlayerActions() {
  int x_adc_val, y_adc_val; 
  int leftThreshold=50,rightThreshold=900;
  float x_volt, y_volt;
  x_adc_val = analogRead(xOutPin);
  y_adc_val = analogRead(yOutPin);
  x_volt = ( ( x_adc_val ));  /*Convert digital value to voltage */
  y_volt = ( ( y_adc_val));  /*Convert digital value to voltage */
  if (x_volt < leftThreshold){
    Serial.println("Move Backwards");
  }
  else if (x_volt < rightThreshold){
    Serial.println("Move Forwards");
  }
  Serial.println("X_Voltage = ");
  Serial.print(x_volt);
  Serial.print("\t");
  //Serial.print("Y_Voltage = ");
  //Serial.println(y_volt);
  delay(100);

  //delay(250);
}

The graph goes to zero for all positive x and y integers however it briefly reaches a maximum past a small value on the -x and -y axis then sinks to about ~420. What could be causing this?

4
  • Re “if (x_volt < rightThreshold)”: do you mean if (x_volt > rightThreshold)? Commented May 11, 2022 at 7:09
  • @EdgarBonet will not change the fact the graph of the potentiometer is not linear Commented May 11, 2022 at 7:41
  • 1
    Can you show the graph? Commented May 11, 2022 at 7:49
  • it could be a problem of analogRead implementation or the ADC itself. for example for AVR it is recommended to wait a little or do a dummy reading between consequent readings on the same ADC. Commented May 11, 2022 at 9:16

1 Answer 1

0

A 10 bit ADC may not have 10 bits of resolution for a given sample. It might only have 5 or 6 bits due to random noise and other factors. Consult the chip manufactures specifications / recommendations if you need a specific number.

What can be done?

  • If response time is not an issue, consider averaging the ADC reading. A common coding practice is to use an exponential moving average.
  • Consider a better ADC. Many times a dedicated ADC chip (not integrated into a processor) will have better specifications.

For more in depth reading this NXP (aka: Motorola, Freescale) application note discusses "How to Increase the Analog-to-Digital Converter Accuracy in an Application".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.