Using AREF as another Digital Input

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

Weird Idea Time...

 

I've got a current project, which needs a lot of DIP configuration switches, running on a 328P in a DIP package. At a fairly late stage I've discovered that I really need another bit. Every pin on the uC is already allocated. Changing to another chip is not an option.

 

I'm not using the ADC so AREF is unconnected. My thought was...

 

Select AREF as the ADC Vref

Switch the bandgap as the source to be measured to the ADC

Measure

 

If AREF is high, nominally 5V, then the ADC will return something around (1.1V/5V*1024) = 0x0D0

If AREF is low, nominally 0V, then I'd expected the ADC to return something around 0x3FF

 

...this feels so wrong that I hesitate to mention it. But sometimes needs must.

 

I'l try it later but will await the cry of 'are you mad' with interest.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Brian Fairchild wrote:
I'm not using the ADC
That may be your first mistake then ;-)

 

Instead of individual config switches each using up an I/O make a switched resistor ladder with all your configs switching a cascade of resistors into a single ADC pin.

 

Arrange one switch to add 0.5Vcc, the next to switch 0.25Vcc, the next 0.125Vcc etc.

 

Now if you read 0.375Vcc on the ADC you know the second 2 switches but not the first are closed.

 

EDIT: Just googled "multiple switches on a single adc using resistor ladder", one of the top hits was:

 

https://www.edn.com/design/analo...

 

other hits there look useful such as:

 

http://tronixstuff.com/2011/01/1...

Last Edited: Tue. Oct 3, 2017 - 11:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We seem to be having a '90s retro thread:

 

Brian Fairchild wrote:
a lot of DIP configuration switches ... a 328P in a DIP package

 

clawson wrote:
make a switched resistor ladder with all your configs switching a cascade of resistors into a single ADC pin.

 

My late father-in-law had a VCR (remember them?) with a wired remote control (remember them?) which used exactly that principle ...

 

laugh

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

After a morning of doodling I've realised that switched resistor networks work, up to a point, but have a number of drawbacks...

 

1) They take up board real estate for the resistors. If you are going to do an 8-bit one then you may as well dump a shift register on as it'll take up the same space.

 

2) The usual suggestion to use an R-2R DAC arrangement doesn't work properly, by giving equal step sizes and linearity, unless you use SPDT switches.

 

3) Handling the situation where you need to close multiple switches gets 'interesting' when trying to work out optimum resistor values.

 

4) Using off-the-shelf resistor values limits the number of bits you can handle when you also factor in tolerance.

 

 

As it happens, fig 6 in EDN link Cliff gave, works quite nicely and might get used.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

I'm assuming you're using through hole resistors aswell? Then why not use a SIL resistor network to save space.

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

BTW I remember reading something about 10 years ago about using a resistor ladder on ADC and it even included a spreadsheet where you input N (buttons) and it calculated all he resistor values for you. Bet I can't find that again!

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

Brian Fairchild wrote:
1) They take up board real estate for the resistors.

While I do realize that "engineering is the art of making what you need from what you have", to me it is a bit questionable complaining about board real estate for resistors when you are starting with the DIP AVR.  And perhaps also the "full sized" slide switch blocks?

 

Note that if you need "just one more I/O", or a few, there is no need to try to max out the switch ladder count.

 

I like your AREF idea for "just one more" signal.

 

Heck, go all the way and RSTDISBL.

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

You can also drop the xtal and use the internal RC to gain 2 more i/o's, or use an external clock to gain that just one more i/o.

 

 

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

Wot - nobody's mentioned charlieplexing ... 

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

bloody-orc wrote:

I'm assuming you're using through hole resistors as well? Then why not use a SIL resistor network to save space.

 

Sadly, all the resistor packs I know of, and can find, have equal value resistors and unless you pay a lot of money are only 2%. Because of the non-linearity inherent in such techniques, this tolerance limits the number of 'bits' it's useful for and the number of packs needed goes up very quickly when you implement R-2R networks. Oh, and you need access to both ends of the resistors so have to use DIP resistor packs.

 

 

ki0bk wrote:

You can also drop the xtal and use the internal RC to gain 2 more i/o's, or use an external clock to gain that just one more i/o.

 

I thought about dropping the crystal but I have a serial port to worry about.

 

 

theusch wrote:

While I do realize that "engineering is the art of making what you need from what you have", to me it is a bit questionable complaining about board real estate for resistors when you are starting with the DIP AVR.

 

Agreed.

 

theusch wrote:

And perhaps also the "full sized" slide switch blocks?

 

Piano keys, but yes, but then my customer has fat fingers.

 

 

theusch wrote:

Heck, go all the way and RSTDISBL.

 

Sadly I need RESET to get into the bootloader. I have found a suggestion that you can use RESET as both RESET and an input pin. As long as you don't pull it below 0.9VCC you won't trigger the internal reset circuit so you just need an external pull-up to swamp the internal one and arrange your source to pull down the pin just enough to be detected by the ADC. Now that is living on the edge.

 

 

As I type this I've just realised I could put two diodes in series with VCC with switches to short either one or both of them out. Use the ADC to measure VCC against the bandgap and I have two more 'phantom' inputs. And no, I am not serious.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Brian Fairchild wrote:
As long as you don't pull it below 0.9VCC you won't trigger the internal reset circuit so you just need an external pull-up to swamp the internal one and arrange your source to pull down the pin just enough to be detected by the ADC

 

I did that to monitor the battery, if it was low enough to trigger the reset, it wouldn't run any way! I had to compensate/calibrate for the internal pull up but worked just fine on a tiny25 project.

 

Jim

 

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

Just thought of this, you have two (unused) ADC pins A6,A7, as your not using the ADC for anything else, those two pins are available, just add a pull up and connect your switch(s) there.

 

Opps, sorry your using the PDIP package, never mind!

Your AREF idea should work!

 

Jim

 

 

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

One thing we have done, described in general terms, is to multiplex e.g. a switch block and a set of button inputs.  Diode-isolated, and the AVR pulls a pin low to read the switch block, then releases that pin and pulls another low to read the buttons. Even with 4-position switch block and 4 buttons, you end up with 6 I/O vs. 8.

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

Oh, yeah, on your AREF idea -- I like the idea OK.  But you may have to do some experimenting on what results the ADC actually gives when AREF is lower than the minimum in the datasheet.

 

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

theusch wrote:

Oh, yeah, on your AREF idea -- I like the idea OK.  But you may have to do some experimenting on what results the ADC actually gives when AREF is lower than the minimum in the datasheet.

 

Good point - operating outside of spec always gives me the shivers.  But a single additional resistor would solve the problem.  Presumably there's already a pullup resistor that would be connected to Vcc, with the DIPSW grounding the bottom end of the resistor.  Simply add another resistor between the bottom of the switch and gnd.  If both resistor values are the same, the AREF value would switch between Vcc and Vcc/2, which would be quite easy to detect.

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

Depending on what you are doing, you could use a pot as an input "switch" ...given 8 "settings", it's equiv to 3 bits...a 3 to 1 improvement with one pot wire..

When in the dark remember-the future looks brighter than ever.

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

Oh, yeah, on your AREF idea -- I like the idea OK.

+1

 

But as implied by Lee, there may be an issue with AREF at 0V.  It's not in the Absolute Maximums, but it is in the ADC Characteristics.  Perhaps you tie Aref to the output of a voltage divider, say a VCC-10K-AREF-10K-GND.  The button would short the VCC-side resistor, so that when the button is pushed, AREF sees VCC, and the samples will come back around 0x0E1 (not 0x0D0 as you noted).  With the button released, AREF will be about VCC/2, and samples will come back around 0x1C2.

 

For the record, when AREF is less than the ADC input, the sample comes back full-scale i.e. 0x3FF for 10-bit, even if VREF is less than the minimum of 1.0, and even if it is 0V.

 

Wot - nobody's mentioned charlieplexing ... 

Hadn't seen the thread yet ;-)

 

The advantage of Charlieplexing is that it will >>reduce<< the component count.  An N-pin matrix needs only N pins resistors.  If you've got 12 LEDs, that can be done with 4 pins, so you save 8 resistors.

 

If you can enumerate what you've got on the other pins without revealing anything confidential, maybe there will be other bright ideas.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Wed. Oct 4, 2017 - 02:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For a bit of topic closure...

 

as I was finalising the design I realised that I needed yet another switch position or else the user instructions were going to get very 'mode dependent' with address bits moving around according to which mode the unit was in. Not good. So I did the sensible thing and squeezed a MCP23017 in along with a full bank of 16 switches.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Mega32 ?
.
MG

I don't know why I'm still doing this hobby

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

MicroGyro wrote:
Mega32 ? . MG

 

If I was going to move to a bigger package it'd be the 1284. Out of the whole standard AVR range I only use the tiny4313, mega328 and mega128, each being at the 'top' of their pin count range.

 

On this board a 40-pin DIP wouldn't fit. To say the board has some interesting mechanical constraints is an understatement.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Brian Fairchild wrote:

On this board a 40-pin DIP wouldn't fit. To say the board has some interesting mechanical constraints is an understatement.

I understand this is a bit OT, but why are you (or the customer) insisting on DIP parts?

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

kk6gm wrote:

I understand this is a bit OT, but why are you (or the customer) insisting on DIP parts?

 

In a word...quantity. Or rather lack of. The order is for a couple of dozen units which I always find to be too few to easily go SMT.

 

Setup costs for a third-party assembly house push the price up too much; doing 25 units as SMT in-house takes too long when done 'manually'. I would love to set up a small in-house SMT facility and it is something I'm looking at but space is an issue.

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

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

Instead of a bunch of switches why not use a rotary encoder?...maybe add a 7 seg display as a readout of the selection and/or what mode you are configuring.  The EEPROM  stores the selections.

When in the dark remember-the future looks brighter than ever.

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

Brian Fairchild wrote:
In a word...quantity. Or rather lack of. The order is for a couple of dozen units which I always find to be too few to easily go SMT. Setup costs for a third-party assembly house push the price up too much; doing 25 units as SMT in-house takes too long when done 'manually'. I would love to set up a small in-house SMT facility and it is something I'm looking at but space is an issue.

IME I don't agree.  We hand-build most of our low volume stuff.  But I guess you'd need access to a good solderer.  [NB:  Actual soldering; no toaster ovens or such.]

 

Suit yourself, I guess.  You just mentioned cost, yet you pick the largest model in the AVR family.  You mentioned space constraint as an important criterion, but are applying the brontosaurus package.

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

How about a small-run oriented place like https://macrofab.com/features/   ...they might do exactly what you need at a low enough cost...save yourself a headache...They also have all the right tools/equipment & experience of using it every day.

When in the dark remember-the future looks brighter than ever.

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

Brian Fairchild wrote:

kk6gm wrote:

I understand this is a bit OT, but why are you (or the customer) insisting on DIP parts?

 

In a word...quantity. Or rather lack of. The order is for a couple of dozen units which I always find to be too few to easily go SMT.

 

Setup costs for a third-party assembly house push the price up too much; doing 25 units as SMT in-house takes too long when done 'manually'. I would love to set up a small in-house SMT facility and it is something I'm looking at but space is an issue.

I certainly don't want to presume to tell you your business.  Still, I have probably hand-soldered a hundred SMD AVRs and other chips, and thousands of SMD resistors and capacitors.  And in your case, you might be able to stick to 90% thru-hole parts, and just one or two SMD chips.

 

BTW, I've used SMD shift registers to increase I/O.  74HC165s, but I know there are others.  Probably cheaper, and possibly easier to lay out, than that 28-pin part you mentioned.  Just an FYI.