Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 11 of 11

Thread: Can Not Read Proper Voltage?

  1. #1
    Junior Member
    Join Date
    Dec 2014
    Posts
    19

    Can Not Read Proper Voltage?

    Hello,

    So I have a project that is using a simple voltage divider. Two 10K resistors from a 5V. When I try and read it with the Teensy, I am getting around 4.0 voltage, but I even verified it with my fluke that it is at 2.5V!!! Why would my teensy not read the proper voltage.
    Here is the Code I am using. Could the ADC be screwed up? It does change when I change the voltage divider, but it kinda seems it is always 1V above the true voltage. :/

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

    void loop()
    {
    int sensorValue = analogRead(A9);
    float voltage = sensorValue * (5.0 / 1023.0);
    Serial.println(voltage);
    }

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,075
    This thread may offer ideas, if not the same conclusion, running this sample might show if you can generally read and write values: https://forum.pjrc.com/threads/28889...ll=1#post75592

  3. #3
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    vref = 3.3V is likely the case.

    (4/5) * 3.3 = 2.64; much nearer the expectation.

    Code:
    float voltage = sensorValue * (3.3 / 1024.0);
    Any good?

  4. #4
    Junior Member
    Join Date
    Dec 2014
    Posts
    19
    Thanks guys. Idk why but I was thinking the analog ref was 5V. So.....crap. I have my PCB supplying 5V to the voltage divider instead of 3.3V. Is it safe to attatch 5V to the ARef pin?

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,780
    If this is Teensy 3.1 (you didn't say exactly which board you're using), then NO, do not connect 5V to the AREF pin. You'll likely damage the chip. The analog-only pins, A10-A14 and AREF are NOT 5V tolerant. You MUST NOT connect 5V to any of those pins!

    On Teensy-LC, none of the pins are 5V tolerant. 5V connected to any pin except VIN or VUSB will damage the chip.

    On Teensy 2.0 and Teensy++ 2.0, you can connect 5V.

  6. #6
    Junior Member
    Join Date
    Dec 2014
    Posts
    19
    Thanks Paul. Yeah, I'm realizing a logic error I was making on my circuit. This is outside of the Teensy hardware, but I do have a technical question. Why are some boards tolerant of 5V and others only up to 3.3V? It seems like higher end micro controllers are using 3.3V for their Ref? What is the reason for this?

  7. #7
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    I make no attempt to answer the question you have posted for Paul; I post FYI:

    You do not need to change VREF from 3.3V

    It is possible to measure voltages many (many) times larger than VREF by using resistors as voltage dividers (I had the impression you knew that because you were dividing 5V appropriately to measure using 3.3V ref but your subsequent post indicates maybe not, so...), to measure up to 33 volts you only need to divide the voltage by something close to (but prefer larger than) 10 (for sake of error and fluctuation etc), a 10K resistor from the ADC/analog node to GND and a 100K resistor from that node to Vsrc will divide Vsrc at a ratio very near 11:1

  8. #8
    Junior Member
    Join Date
    Dec 2014
    Posts
    19
    Quote Originally Posted by robsoles View Post
    I make no attempt to answer the question you have posted for Paul; I post FYI:
    Why do you say this?
    And thanks or your response on measuring higher voltages.

  9. #9
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    my post makes no attempt to answer the question "why do higher end MCUs use lower voltages?", that is why I said/wrote that.

    It is academic and, whether or not my understanding of why is right, wrong, worth anything or completely worthless; I don't have the time to do it justice, sorry.

  10. #10
    Junior Member
    Join Date
    Dec 2014
    Posts
    19
    Quote Originally Posted by robsoles View Post
    my post makes no attempt to answer the question "why do higher end MCUs use lower voltages?", that is why I said/wrote that.

    It is academic and, whether or not my understanding of why is right, wrong, worth anything or completely worthless; I don't have the time to do it justice, sorry.
    Then just don't answer. You didn't have to say you weren't going to answer. haha never got a response on a forum like this before. O.o

  11. #11
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    Quote Originally Posted by SDTricker View Post
    Thanks Paul. Yeah, I'm realizing a logic error I was making on my circuit. This is outside of the Teensy hardware, but I do have a technical question. Why are some boards tolerant of 5V and others only up to 3.3V? It seems like higher end micro controllers are using 3.3V for their Ref? What is the reason for this?
    On page 11, of the manual the designers of the chip mention the following:
    Code:
    All 5 V tolerant digital I/O pins are internally clamped to VSS through a ESD protection diode. There is no diode connection to VDD. If VIN greater than VDIO_MIN (=VSS-0.3V) is observed, then there is no need to provide current limiting resistors at the pads. If this limit cannot be observed then a current limiting resistor is required. The negative DC injection current limiting resistor is calculated as R=(VDIO_MIN-VIN)/|IIC|.
    2. Analog pins are defined as pins that do not have an associated general purpose I/O port function.
    3. All analog pins are internally clamped to VSS and VDD through ESD protection diodes. If VIN is greater than VAIO_MIN (=VSS-0.3V) and VIN is less than VAIO_MAX(=VDD+0.3V) is observed, then there is no need to provide current limiting
    resistors at the pads. If these limits cannot be observed then a current limiting resistor is required. The negative DC injection current limiting resistor is calculated as R=(VAIO_MIN-VIN)/|IIC|. The positive injection current limiting resistor is calculated as R=(VIN-VAIO_MAX)/|IIC|. Select the larger of these two calculated resistances.
    On the following pages, they also go over power consumption, etc. Note how the chip consumes the same number of milli-amps at 1.8V vs. 3.3V. Your answer may very well be there, i.e. in order to keep the power consumption in check despite high clock rates, the designers keep lowering the core voltages of chips. The Edison from Intel runs at 1.8V, for example.

    Folks in the overclocker community have been playing with core CPU voltage for years, balancing the stability of the rig at high speeds vs. the thermal output. Lower voltages = lower heat production but the chip may not be stable.

    However, also have a look at the technical data sheet and the rather more in-depth reference manual for the MK20 series.
    Last edited by Constantin; 06-18-2015 at 12:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •