chipKIT® Development Platform

Inspired by Arduino™

Have I broken my max32?...

Created Mon, 16 Apr 2012 13:03:52 +0000 by mogplus8


mogplus8

Mon, 16 Apr 2012 13:03:52 +0000

Not sure what I've done. I put together a program to read an analog input (A0) and print the value every 1/2 second. When I first tried it last week it worked a treat. Then I attached two pots, one on A0 and one on A1. I attached one side of both pots to 3.3v, and the other side of both pots to ground. I attached the middle (wiper) of one pot to A0 and the other one to A1. Didn't work.

Went over the code multiple times and couldn't see the problem. Removed all the changes and tried again. The original code didn't work. Removed the second pot. still no joy. The first number it displayed was 956, the second (other end of the pot) was 887. Then it just printed mostly 888 regardless of where the pot was positioned.

Gave up then (last night) and had another go tonight (and changed the input to A3, in case I had stuffed A0 and A1). The results are even more random. If I don't move the pot at all the number printed varies from 0 to 1023. It's all over the place like a mad dog's breakfast.

I'm worried that I might have stuffed the board by connecting the two pots in parallel, between 3.3v and ground. Is that possible? I'll be very unhappy if that's what I've done...

All advice gratefully received, Ian

/*
  AnalogReadSerial
 Reads an analog input on pin 0, prints the result to the serial monitor 
 
 This example code is in the public domain.
 */
int analogLow = 0;
int analogHigh = 0;
int ailIn = 3;
void setup() {
  Serial.begin(9600);
//  Calibrate stick
  Serial.println("move stick and trim to extreme");
  delay(2000);
  analogLow = analogRead(ailIn);
  Serial.println("analogLow="+String(analogLow));
  Serial.println("move stick and trim to other extreme");
  delay(2000);
  analogHigh = analogRead(ailIn);
  Serial.println("analogHigh="+String(analogHigh));
}

void loop() {
  int sensorValue = analogRead(ailIn);
  long sensorOutput = ((sensorValue - analogLow)*1023)/abs(analogHigh - analogLow); 
  String newString = String(String(sensorValue) + "- " + String(sensorOutput));
  Serial.println(newString);
  delay(500);
}

hdphilip

Mon, 16 Apr 2012 23:50:05 +0000

maybe take a step back

i copied this from the arduino:

int analogPin = 3; // potentiometer wiper (middle terminal) connected to analog pin 3 // outside leads to ground and +3.3V int val = 0; // variable to store the value read

void setup() { Serial.begin(9600); // setup serial }

void loop()

it copiled ok

just a thought

Philip


mogplus8

Tue, 17 Apr 2012 13:19:46 +0000

Thanks for the reply Philip. My code compiled okay, and the program runs. It asks me for the max movement in both directions, then starts printing numbers to the screen. Problem is, when I first ran it it worked fine, with the numbers going very small (between 0 and 10) in one direction, and moving the stick to the opposite extreme sent the numbers up to about 1010 to 1020, so it was working. Now it compiles, but the numbers are all over the place, they don't track the stick movement at all. I can't figure why. The program is the same, the setup is the same. That's why the only thing I can think of is that I've somehow damaged the ADCs...

:-(


knChip

Tue, 17 Apr 2012 18:23:21 +0000

Hi, It is unlikely that you have damanged the ADC , Since you have used 3.3V as one end of the pot,. Just a clarification.. A0 is not pin 0, A3 is not 3 Can you please post your working(compiled sketch). refer to [url]http://www.chipkit.org/forum/viewtopic.php?f=19&t=826[/url] Thanks, KN


Ryan K

Tue, 17 Apr 2012 23:41:08 +0000

Hello,

Actually you can pass in A0 as 0 it should work fine. This section of code converts the digital pin to that number anyways:

/* Pin number is allowed to be either the digital pin number or the ** analog pin number. Map the input so that it is guaranteed to be ** an analog pin number. */ pin = (pin < NUM_DIGITAL_PINS) ? digitalPinToAnalog(pin) : NOT_ANALOG_PIN; if (pin == NOT_ANALOG_PIN) { return 0; }

As Philip suggested have you tried simplifying the code to just the read and print and see what you get?

Best Regards, Ryan K Digilent


mogplus8

Wed, 18 Apr 2012 07:12:49 +0000

Hi Ryan, thanks for the reply. I posted the full program in my original post. I did try the example sketch (who came up with that name?...) AnalogReadSerial, but it printed the numbers so fast I couldn't read them. So I added a delay after the print. It now looks like this.

/*
  AnalogReadSerial
 Reads an analog input on pin 0, prints the result to the serial monitor 
 
 This example code is in the public domain.
 */

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue, DEC);
  delay(1000);
}

Can't figure out how to add a screenshot, but the numbers are varying from about 313 to about 896. Moving the pot makes no difference. I've tried it with two different pots, both of them 5k. The pots are both working, I tested them with a mutimeter.

Thanks, Ian


les1943

Wed, 18 Apr 2012 12:18:13 +0000

[attachment=0]ana2.jpg[/attachment]

I am a bit wary of connecting pins directly to wipers as u describe , although a port configured as analogue input will be ok what if due to some code crash or miss coding bug the port becomes an output ? adding the 330R resistor would be insurance and should not effect the voltage levels to any extent.


mogplus8

Sun, 22 Apr 2012 05:22:43 +0000

Thanks les1943, another valuable lesson. I will do as you suggest. ;)


mogplus8

Wed, 02 May 2012 11:42:40 +0000

Well, I don't know why but the board is back to working again. I haven't been playing with it for a while (life gets in the way...) but tried it again yesterday, and it worked fine. No idea what I've done or what's changed, but all is well.

Thanks again to all who responede with help and advice, much appreciated.

Cheers, Ian