• 0
Sign in to follow this  
andrewkhardy

analogRead functionality for chipkit uC32

Question

Hello and thanks for taking the time to read my question.  I'm hoping to use the ADC functionality of the chipkituC32 but I have some questions. As I understand it, when I write the command

Input = analogRead(A3)

I should get an interger number 1023 /3.3 = x . However when I have no input into the A3 port, I get the constant number 788. How do I do the correct conversion? When I was sending in a DC voltage of 2 V I was getting alternating numbers between 600 and 1023 which make no sense.

Also, I cannot find in the datasheet, what is the frequency to read in a signal? I found somewhere online that it was only 10kHz.  That seems incredibly low. IS the read frequency for digital signals higher? If I have a separate ADC and send a digital signal could I speed this up?  Thanks again

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @andrewkhardy,
I'm not certain what the rest of your code is (in terms of viewing the result you received and the voltage conversion), but here is some example code that I used to test the analog conversion on a uC32. I would also recommend making sure that whatever you are using to supply to voltage has it's ground connected to the uC32 ground pin to create a common reference.

Spoiler



int value = 0;
float voltage = 0.0;

void setup() {
  // setting up
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  
}

void loop() {
  // read in the analog input
  value = analogRead(A3);
  //blink an LED to see a visual change
  digitalWrite(13, HIGH);
  delay(value);
  digitalWrite(13, LOW);
  delay(value);
  //print out the measured ADC value
  Serial.print("value is: ");Serial.println(value);
  //convert the value that is between 0 and 1023 to a voltage scale
  voltage = float(value)/1023.0*3.3;
  Serial.print("voltage is: ");Serial.println(voltage);
}


 

With regards to the ADC itself, it is my understanding that the on-board ADC only runs up to 1 MSPS, though you can change some of the internal parameters detailed in this Microchip datasheet.

Let me know if you have any questions.

Thank you,
JColvin

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this