View Full Version : ADC values on Teensy 2.0

01-21-2013, 10:20 PM
Hi guys,

I have tried searching for similar problems to this, but couldn't find anything.

I have set up ADC on my Teensy 2.0 using C and the simple readADC code on the website, and weird things are happening. It looks like the Teensy is unable to return values between certain numbers from readADC. For example, the ADC will read (as I increase voltage) 0, 1, 3, 32, 48, 56. Instead of going up steadily, in regular increments.

What's weird is that the change in voltage required from one value to the next is correct (i.e. the change from 0->1 is tiny, and from 3->32 takes a much larger change in voltage).
Its as if the Teensy gets 'stuck' on the value 3 (and its always the same number), and cant return any values until the input is high enough to return 32.
I have checked my input voltage with a multimeter, and it is definitely going up smoothly during this process.

I am really lost for what might be causing this. Any help is appreciated.

01-22-2013, 12:03 AM
If you are using a power supply to generate the input, perhaps it has limitations.

Use a large capacitor (e.g. 100 uF) and a pullup resistor to VDD (discharge the cap first). with 10 kohm and 100 uF it will take > 1 s to charge -- if you read and print all the ADC readings, you should be able to see the results ramp up smoothly.

As a refinement, connect the R to a port and toggle it every 10 s -- now it will ramp up and down.

Note the ramp will not be a straight line.

01-22-2013, 12:18 AM
If you are using a power supply to generate the input, perhaps it has limitations.

I first saw the problem while reading output from an accelerometer, and I thought this might be the case. However I have checked with a multimeter while tilting the accelerometer very slowly. I have does the same thing with a power supply and using different references, but the intervals between readings on the teensy are always exactly the same numbers.

I can give your capacitor idea a go, but I don't think a smooth input voltage is where the problem is.

01-29-2013, 08:45 PM
I have tried your solution and the same problem occurs. The time difference between the 'steps' in ADC values varies with how big the step is - exactly the same as I was experiencing before.

I'm stumped.

01-29-2013, 08:54 PM

01-29-2013, 09:36 PM

Complete Source Code (or a link to the code)

using C and the simple readADC code on the website
My apologies, I didn't provide a link: http://www.pjrc.com/teensy/adc_simple.zip
Also I erroneously reffered to the function as readADC when it is in fact adc_read. I can see how this would be confusing.

Screenshot or the exact text of any error messages

I don't have any error messages, sorry.

Which PJRC product you're using

on my Teensy 2.0
To clarify, this is the "Teensy 2.0" (without quotes). Not the "Teensy++ 2.0".

Part numbers of any other chips or modules + links to their info

The accelerometer this was originally tested with is the ADXL335.
Link to my specific breakout board (https://www.sparkfun.com/products/9269)
Schematic (http://dlnmh9ip6v2uc.cloudfront.net/datasheets/BreakoutBoards/ADXL335_v13.pdf)
Datasheet (http://www.sparkfun.com/datasheets/Components/SMD/adxl335.pdf)
Wiring example (http://wiring.org.co/learning/basics/accelerometer.html)

However I'm not sure this is relevant, since it has been tried with many other methods, including directly applied analog voltages, measured via multimeter.
I am able to get you information on the specific bench power supply and/or 100uF capacitor used if you would like.

Wiring details - how exactly have you connected the hardware (a photo's worth 1000 words)

I have my Teensy 2.0 powered via USB, with the aforementioned analog voltage applied to pin F0. If this is confusing I can provide a picture.

Software setup, Arduino vs C+makefile, running on Windows, Mac or Linux?Versions?

using C
Again, I appologise for missing some information.
Archlinux, 64-bit, kernel 3.6.10-1
avr-gcc v4.7.2-1

Any other information needed to reproduce the problem.....

Unfortunately I only have a single Teensy, and so I am not sure if it is reproducable. However I was able to produce the problem with the setup described above.

Hopefully I have filled in all the gaps. If you need any more info, please let me know =)

02-03-2013, 01:36 AM
I tried the same code example you have, using a variable resistor as an analogue source. I too have a regular Teensy 2.0, and was using the F0 analogue input.

I tried it using WinAVR 2010 (http://www.webring.org/l/rd?ring=avr;id=59;url=http%3A%2F%2Fwinavr.sourcefo rge.net%2F) on my windows machine, and using avr-binutils 2.23-2, avr-gcc 4.7.2-1, avr-libc 1.8.0-4 and avrdude 5.11.1-2 on 64-bit Archlinux 3.6.11-1.

I can confirm that the analogue input works properly, and works very well.
It then appears that your Teensy is a bit bung :(

02-03-2013, 03:29 AM
For anyone googling in the future:

I decided to change just about everything - I rewrote what I had (basically, copied adc_read into a blank file), compiled using WinAVR on Windows. And the problem is gone.

So it was either a problem in my code, or a problem with the compiler.

EDIT: Just booted up Archlinux to and used my original setup to recompile the whole thing and it works fine. So it looks like something I had done was causing the problem. Not that I have any idea how one would cause my symptoms even if they wanted to.