Hi,
I have a project using the Atmega328p TQFP32-08 and want to use the PB5/D13/Pin17 as an analog input.
Currently the only time it is used is for uploading binary updates via ICSP. During normal running of the sketch it is not connected to anything and left open. I'd like to use is as analog input when running the sketch.
Details:
system running on 5v
Input being measure will be between 3v or 2.143v level.
I'm not sure if the two voltages fall in a way that would trigger a HI or LOW reading. The voltages are a result of a resistor-divider circuit with a physical Switch, so I can adjust those to move the voltages up and down somewhat.
Pin 13 is not an analog input. Analog inputs are A0 to A5 or IDE pins 14 to 19.
The input to a digital pin will be seen as HIGH if the voltage is greater than 0.6 * Vcc and will be read as LOW if the voltage is less than 0.3 * Vcc. See page 313 of the data sheet.
Between 0.3vcc (1.5v) and 0.6vcc (3.0v), digital pin input is undefined (could read HIGH or LOW, potentially depending on individual chip, and the direction that the pin approached that voltage from).
Since that pin does not have an ADC channel associated with it, it cannot be used to measure an analog voltage.
No pin without an ADC can be used to determine which of three applied voltages is applied to it.
You must use a different pin. Either an analog pin, or external circuitry and two digital pins could be used. Are you using all the analog pins, even A6 and A7?
groundFungus:
The problem remains that a digital input can only sense 2 levels, LOW and HIGH.
That's all I want. So it seems to be in finding the right voltage. Due to the project design the only variables are the resistor values. Plus it's likely that R6 & R7 have to be the same value...So the output is the same in both position 1&3