Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Analog voltage incorrect


  • Please log in to reply
23 replies to this topic

#1 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 23 October 2010 - 09:08 PM

I am a newby on the forum as well as to the Netduino and C#. I have a LM35 connected to A1 pin. The voltage on the pin is measured to be 227mv or there about. The Aref is connected to the 3.3v and I get a digital reading of around 118. As per my code below it results in a voltage of 380mv. private static double ReadTemp() { // Read the temp sensor int read = temp.Read(); Debug.Print("raw "+read.ToString()); //convert the reading to voltage Double voltage = read * (3.3 / 1024); Debug.Print(voltage.ToString()); //calculate Celsius from voltage double tempC = (voltage) * 100; //calculate Fahrenheit from Celsius double tempF = (tempC * 9 / 5) + 32; //Print your results //Debug.Print("Temp in F is: " + tempF + " -- Temp in C is: " + tempC); return (tempC); }
If at first you don't succeed, then try and try again.

#2 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 24 October 2010 - 12:04 AM

Check the actual voltage on the aref. If you're running only off USB, I have found that it could be off a significant amount if your usb voltage is low for whatever reason.

You can also use the .SetRange(0, 3300) on your pin method to get the millivolt conversion "for free". I'm guessing if your aref is actual at 3.26 or something you could do .SetRange(0,3260)...

Also check this thread on the LM35

I'd be curious to know about fluctuations in your readings, which I have been struggling with:

Analog Input Fluctuations

#3 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 24 October 2010 - 06:34 AM

Hi Bill, Thanks for the reply. I have :- 1: checked the aref, it is correct at 3.3v 2: set the range to 1024. I dont understand the function correctly but I think the range is the actual digital range of the converter - 1024 for 10 bit???? 3: I have shorted the A1 pin to gnd and get 0. 4: shorted the A1 pin to 3.3v and get 1023. The problem is that the LM35 has a voltage of say 220mv and the converter will read 370mv. Never near to the real value. It would also seem to stay more or less in that range. ie the read does not change that much with change in input voltage. Very strange and frustrating. I have not had the fluctuations just yet. I might pick that up once the converter works. It could be noise in your case. I alway use a twisted pair for analog input. Connect the gnd and signal as close to the sensor as possible.
If at first you don't succeed, then try and try again.

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 October 2010 - 07:23 AM

Just to make sure you're not experiencing integer casting, try using AnalogInput.SetRange(0, 3300) and then see what the results are... Chris

#5 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 24 October 2010 - 07:33 AM

Ok this is getting to me know. When I remove the humidity sensor that uses A0, the reading changes a lot. Why do I measure a voltage on the analog pins with nothing attached?
If at first you don't succeed, then try and try again.

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 October 2010 - 07:57 AM

Ok this is getting to me know. When I remove the humidity sensor that uses A0, the reading changes a lot.

Why do I measure a voltage on the analog pins with nothing attached?


Marius,

If you are opening up multiple analog pins in code, you need to have something connected to each one (or you need to wire the unused ones to ground). Otherwise, the unconnected analog inputs can drive floating readings...

Chris

#7 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 24 October 2010 - 01:37 PM

Chris, Do we have to load the input pin that has a sensor connected a bit as well? I am more concerned about the reading that is not consistent with the real voltage on the pin.
If at first you don't succeed, then try and try again.

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 October 2010 - 05:39 PM

Chris,
Do we have to load the input pin that has a sensor connected a bit as well? I am more concerned about the reading that is not consistent with the real voltage on the pin.


All analog inputs that are in use should be driven to a voltage (whether that is 0V, 3.3V, or anything in between). If you leave an analog input "floating," you'll get floating results...

I can ping our electrical engineering team on this, but some other forums members might have some insight to share as well...

Chris

#9 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 25 October 2010 - 07:13 PM

Chris, Because I am a newby I can ask this, I think. What is the difference between declaring like this static AnalogInput temp = new AnalogInput(Cpu.Pin.GPIO_Pin10); and this static AnalogInput temp = new AnalogInput(Pins.GPIO_PinA1);
If at first you don't succeed, then try and try again.

#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 October 2010 - 07:24 PM

Chris,

Because I am a newby I can ask this, I think.
What is the difference between declaring like this

static AnalogInput temp = new AnalogInput(Cpu.Pin.GPIO_Pin10);

and this

static AnalogInput temp = new AnalogInput(Pins.GPIO_PinA1);


Marius,

Cpu.Pin.GPIO_Pin10 refers to pin "PA10" on the Atmel microcontroller itself. As a general rule, skip those enumerations and use the Netduino ones (Pins.GPIO_PinA1, etc.) instead.

Chris

P.S. Advanced technique: you can access any digital pin on the Atmel microcontroller by using (Cpu.Pin)pinNumber -- where pinNumbers 0-30 are MCU pins A0-A30 and pinNumbers 32-62 are MCU pins B0-B30.

#11 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 25 October 2010 - 07:52 PM

Thanks Chris, that is handy information. I am still having a problem with the LM35. I have discovered that the ATD is ok but somehow connecting the LM35 directly to the pin make trouble. For some obscure reason is the reading lower than what I measure on the pin. I am beginning to think that it is an impedance problem. Any news from your technical chaps regarding my problem here? P.S. I am running the sensors from 3.3v, maybe a problem?
If at first you don't succeed, then try and try again.

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 October 2010 - 08:06 PM

Thanks Chris, that is handy information.
I am still having a problem with the LM35. I have discovered that the ATD is ok but somehow connecting the LM35 directly to the pin make trouble. For some obscure reason is the reading lower than what I measure on the pin. I am beginning to think that it is an impedance problem.
Any news from your technical chaps regarding my problem here?

P.S. I am running the sensors from 3.3v, maybe a problem?


Marius,

Do you have a regulated power supply that outputs a constant voltage? If you can generate a known voltage to measure on your Netduino, we can identify if there's a glitch in the MCU's ADC (analog-to-digital converter) somewhere...

Or if you have a friend with a Netduino, it would be really interesting to see if they got the same results.

Chris

#13 freds

freds

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts

Posted 26 October 2010 - 02:14 AM

Marius,

Do you have a regulated power supply that outputs a constant voltage? If you can generate a known voltage to measure on your Netduino, we can identify if there's a glitch in the MCU's ADC (analog-to-digital converter) somewhere...

Or if you have a friend with a Netduino, it would be really interesting to see if they got the same results.

Chris


I forget what type of filter they call it, but maybe try for aref a 10mf cap being fed through a 1k resistor from the v3.3 source. I had to do something simular with a sensor that I was working with to get rid of the noise that was affecting the sensor.

#14 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 26 October 2010 - 04:26 AM

I have tested the ADC with another type of sensor and it works fine. What I am going to do is: 1: Put a filter on the 3.3v 2: Load the output slightly 3: filter the output a bit I will let you know.
If at first you don't succeed, then try and try again.

#15 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 27 October 2010 - 03:32 PM

Chris, I removed the cap from the output to gnd as the spec indicate the the device cannot drive capacitive loads to well. I put a 100k from the pin to gnd and - fixed the problem. What I alway do with slow ADC signals is to put them through a software filter like a bucket filter with anything from 5 to 10 taps.
If at first you don't succeed, then try and try again.

#16 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 27 October 2010 - 04:49 PM

It sounds like you got it working, but you mention earlier that you're running the sensor off of 3.3v, the LM35 spec says: - Operates from 4 to 30 volts So perhaps that is an issue? You do need to be careful not put put more than 3.3v to the analog input, but from what I gather about the LM35 (10mV/degree C) that should not be an issue.

#17 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 27 October 2010 - 04:59 PM

Bill, Yes it is working fine. The 5v supply vs the 3,3v did not make a difference to the problem although I think it may have been problematic later. I am powering all the sensors and display from a secondary supply and it seems solid for now.
If at first you don't succeed, then try and try again.

#18 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 27 October 2010 - 11:00 PM

Thanks for the update, Marius. I'm really glad it's up and working well for you... Chris

#19 Marius

Marius

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationCenturion RSA

Posted 30 October 2010 - 07:56 AM

Chris, It is happening again. The problem is back. The voltage on the pin is not the same as the read voltage of the ADC. This is what I noticed so far. I did get it to work but after a reboot this is the situation. 1: If I ground the adjacent pins - no difference. 2: If I load the pin lightly - no difference. 3: If I load the input heavily (with a pot) - correct voltage is read. It would seem that the pins are all pulled high internally. How do I turn that off on the Netduino with the C# libraries?
If at first you don't succeed, then try and try again.

#20 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 October 2010 - 12:18 PM

Marius, Can you try something really quick for me? 1. Before you create your AnalogInput, create an OutputPort with an initial state of "off" (false) 2. Dispose of the OutputPort 3. Create your AnalogInput If that's fixing your problem, please let me know--we may need to assert a manual "pull-up disable" behind the scenes in the analoginput constructor. Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.