teensy 3.1 analog input

Status
Not open for further replies.

spencoid

Well-known member
can the analog inputs on the teensy 3.1 (other than the analog only pins) measure 5 volts or do i need to use a voltage divider to scale my 5 volts signals to 3.3 volts?
 
Analog inputs can only handle 3.3 volts. The digital inputs are 5V tolerant. Not sure about inputs that can have both analog and digital, but I assume it is a limitation of the analog input internally. So in analog input mode I would assume 5V is too high. I would look at the chip datasheet to really see what is going on there.

I am measuring 400VDC on mine so I divide it down with a 1M and 8.2K resistor to keep it in range.
 
On the Teensy 3.1, the pins that support digital reading (i.e. not A10-A14), are 5v tolerant for digital reads. As Demolishun says, doing analog input, the pins are restricted to 3.3v. I believe Paul has said if the voltage is above 3.3v, analog reads will just return 1,023. Teensy 3.0 is not 5v tolerant.
 
Indeed, the pins can't measure over 3.3V, even though they're able to tolerate being driven up to 5V. The 5V tolerance is only for being able to receive 5V digital signals.

However, the 3.3V analog input range is when using 3.3V power as the reference voltage, which is the default setting. A 3.3V power reference makes sense when measuring voltage from a pot or resistor-thermistor or something else that scales when/if the power supply voltage changes.

If you're measuring an external voltage, which is independent of the 3.3V power, you should really use the 1.2V internal reference. It's far more stable and has virtually no change when the 3.3V power changes slightly. You'll need to reduce the 8.2K resistor to get the right 1.2V scale, but eliminating error from fluctuations in the 3.3V is almost certainly worth it.
 
Hey, I was wondering if there is a way I can measure the input/USB voltage? I would like to accurately be able to read what the input voltage is coming from the USB and simply print it via serial for now.
 
Use a voltage divider to translate 5V to 3.3V
bunatu.png
4.7k for R1
9.1k for R2

Feed the output to a teensy analogue input.

Remember to multiply the read value by 1.5165 to counteract the voltage divider
 
Last edited:
So by connecting the Vin to R1, R1 to R2 to AGND, and A9 between R1 and R2 I should get a 3.3v reading? Which then I can sample and do some math to determine the actual input voltage from Vin? (Vin == USB+ Right??) Assuming all of this is true at this point what would the math look like? USB+*(R2\(R1+R2))=Vin? Would you care to give me a bit more detailed example of how I could pull this please? :)
 
Last edited:
I think i grasp the concept of a voltage divider now. I was told by someone to use proportional mapping by using a voltage divider to bring the Vin down to a bit less than the Internal reference (1.2 on Teensy 3.1) to 1.1 which will be connected to ADC. To my knowledge I will then need to account for power dissipation by using Vin/(R1+R2) in my logic. So assuming all so far is correct, what kind of calculation would I do to measure the reading at ADC pin against the actual internal reference? Can anyone supply some example code.
 
The reference voltage for the Teensy 3.1 is by default the external 3.3V regulator.

So lets look at if Vin is at 5

Vout = (Vin*R2)/(R1+R2) not 'Vin/(R1+R2)'
3.2971V = (5*9.1E3)/(4.7E3+9.1E3) This website is great for calcing voltage dividers

So now we know 5V maps to 3.2971V. Lets round to 3.3V
Consider our ADC is set to 12 bits. This gives a max value of 4095 calculated from (2^12)-1. 4095 will be our voltage reference. This is the external 3.3V by default

So when we read 4095 we know we have 5V at Vin. And 3.3V at our analogue pin.

So our read_value * (5/4095) = Voltage_In

Code:
void setup() {
  Serial.begin(9600); 
  analogReadResolution(12); 
}

void loop() {
    uint16_t Ain;
    float Aout;
    Ain = analogRead(A0);
    Aout = float(Ain) * (5.0/4095.0);
    Serial.println("RAW = " + "String(Ain) + "  :  Converted = " + String(Aout) + "V"); 
    delay(100); 
  }

}
 
Forgive my ignorance, I am a bit of electronics noob. Would the diagram you show here be suitable for translating a +5/-5v audio signal into something the Teensy 3.x onboard ADC can read?

Use a voltage divider to translate 5V to 3.3V
View attachment 6110
4.7k for R1
9.1k for R2

Feed the output to a teensy analogue input.

Remember to multiply the read value by 1.5165 to counteract the voltage divider
 
It might be a little too late for the poster above, but there has to be mentioned that Teensy's ADC can't measure negative input voltages.

That's it, you first need to translate your AC signal to a positive range (-5/+5V => 0-10V) then you could use a regular voltage divider (like in the circuit above) to apply a 0-3.3V voltage range to ADC input..
 
Status
Not open for further replies.
Back
Top