ADC & pull-up question

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

I would like to ask you a simple and fast question:
Is there any way to use the internal pull-up of analog a pin, while it is set as an analog input channel???

I am using the ATmega48.

Thank you.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of what use would it be?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just asking?

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Just asking?

Quote:

a simple and fast question:

It is a trick question, as you didn't give enough information. What is DIDR0 set to? What is PUD set to?

I >>think<< that you won't get the pullup if the DIDR bit is set, but that is left as an exercise for the student. The port diagram isn't clear to me.

The short answer is that if DIDR0 is clear and PUD is clear then you get a pullup.

Quote:

Of what use would it be?

I've got it in a production app. ;) A thermistor has a bias pullup resistor of 31k, which gives me a linear ADC reading from about -40 to +40 F. It was also useful during cleaning mode of the product to get decent temperature readings from room temperature to hot water temperatures. With the bias in place that end of the scale was ugly.

Turn on the internal pullup, which is ~30k and you effectively have two 30k in parallel as the thermistor bias. This changes the curve so that decent readings could be obtained in the "hot water" range.

I also used it in a past life before AVRs had DIDR. The floating (especially) unused analog inputs on an app caused power draw to fluctuate when in logic no-man's-land. With slow power supply regulation and a few floating inputs reacting to mains hum it (the resultant Vcc/AVcc ripple) caused problems. "Software pill for hardware ill": I turned on the pullups on the channels I knew were "empty".

So that is two uses, Steve. ;)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee,

I would like to use the internal pull up simultaneously with the adc enabled at a pin. The pull up can help me to complete a circuit that I have in my mind. My question does not touches the circuit but only the AVR.

I am just asking if the AVR is able to see it's internal pull up (in any way), while the adc is enabled or in other words if the ADC measurement could be 1024 while the pin is not connected and the internal pull up effects the measurement. I don't want to use the pin as digital input because the circuit needs an analog input.

If this is not possible I will use external pull up, increasing the pcb size and cost.

Thanks.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is your application so extremely cost sensitive and so extremely small that an extra resistor is a major point?

The value of the internal pull up can vary quite a bit (35-122K for example for the t28 or 20-50K for m8535).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, the product uses 4 adc inputs and the pcb must not exceed the size of an euro. I really don't mind if the internal pull up's value varies. Also reading the electrical characteristics of the ATmega48, the internal pull up for digital inputs (except the reset pin) varies from 30 to 60K.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

May I ask something similar?
When a pin is configured as input but with internal pull-up enabled, if I read the pin should it be a logical "1" or a logical "0"?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"1"

(assuming nothing external and stronger than the pull-up is driving the pin in another direction)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kakarot wrote:
When a pin is configured as input but with internal pull-up enabled, if I read the pin should it be a logical "1" or a logical "0"?

Sorry but isn't the answer to this quite obvious?
I suppose you know what a pull-up resistor is?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried a sample program in AVR Studio, but it seems the simulator reads the PINx always zero, even though the pull-ups are enabled.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think i figured it out.
First someone needs to set DDRx as output 0xFF.
In this way when PORTx.y is set, PINx.y is set.
Restoring DDRx as input 0x00, has as result the pull-up
resistor enabled and the PINx.y as a logical "1" if read.
Thanks. Hope this is helpful.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kakarot wrote:
I think i figured it out.
First someone needs to set DDRx as output 0xFF.
In this way when PORTx.y is set, PINx.y is set.
Restoring DDRx as input 0x00, has as result the pull-up
resistor enabled and the PINx.y as a logical "1" if read.
Thanks. Hope this is helpful.

As I understand things, from reading the generic PORT schematic and from some experience, the PORT register either controls the output pin (if DDRx is high) or turns on the pull-up(if DDRx is low). It doesn't make any difference what the state of DDRx is at the time you write to PORTx, since there is only the one latch that serves both functions.
This can lead to unwanted intermediate states under some circumstances.
I would not want to make any assumptions about the simulator.

Four legs good, two legs bad, three legs stable.