reading analog signals on a MCU with only digital I/O

I've been working with the ARMexpress microcontrollers, which has only digital I/O. Apart from the lack of A/D inputs, I love it. So I'm looking for some way to work around that limitation.

It seems to me that you could use a PIC or Atmel chip for this. These could be programmed to respond to a simple serial protocol, where the input indicates the pin number of interest, and the response is the A/D level on that pin. Is this a reasonable approach? Which specific chip would be a good choice for this?

Also, is there an off-the-shelf solution that does the same thing, without requiring an AVR/PIC programmer? Something set up to speak I2C,

1-Wire, SPI, or serial? (Any of those should be easy to talk to from the ARMexpress.)

Thanks,

- Joe

Reply to
Joe Strout
Loading thread data ...

Joe:

The answer is "yes", such chips exist. One of the easier ways to find them is to use the parametric search capability of DigiKey. Go to and type in "A/D Converter". Select the catagory with 8000+ items in it. Now you have the parametric tables. Narrow down your search with I2C, SPI, and 3-wire, select some packages that you can live with, etc. Now comes sticker shock.

Once you have found a part number that you like, you can go to and see if somebody sells it for a better prices.

A dedicated PIC/AVR with built in A/D is frequently cheaper than most of these stand alone chips. However, there is the up front cost of getting a AVR/PIC programmer.

-Wayne

Reply to
Wayne C. Gramlich

No kidding. Those seem ridiculously expensive. (For those following along at home, the cheapest 8-pin DIP I could find in single quantities was the AD7893ANZ-2-ND for $16.50.)

Sure, but this is the sort of thing where your friendly local robotics club can help out. I'm not all that familiar with these chips, though. Is there one you'd recommend that has at least, say, four A/D channels?

This also seems like the sort of thing where an industrious hobbyist could make a few extra bucks, selling pre-programmed chips with friendly instructions on how to use them. At (say) $10 each, you could well undercut the competition and still make a tidy profit per chip.

In fact, I'm surprised nobody's doing this... but maybe it doesn't come up to often. I take it that most MCU's have A/D channels built in?

Thanks,

- Joe

Reply to
Joe Strout

You need to look a little harder. The ADC08831IN and the ADC08832IN were about $2.51 quantity 1 (in stock). There are plenty in the $3-$4 range.

Make sure that you do not over constrain your search. I usually select package first and then select other features.

Getting the hang of Digikey parametric search takes a little time and patience, but it is worth it in the end.

I'm from the PIC side of the fence. I use the PIC16F688 for everything. I buy 'em in tubes of 25 from Mouser or Digikey. I use 'em like popcorn.

I'll let somebody else chime in for the appropriate Atmel part (probably and ATtiny##.)

Microcontrollers are cheaper, but there is not that much margin. Most people will just find a MCU with A/D built in.

A/D conversion is the first thing most MCU vendors add to their product mix.

-Wayne

Reply to
Wayne C. Gramlich

I guess another approach would be to use a Voltage-to-Frequency converter, like the Analog Devices AD7740. This only costs about a buck, and should be easy to use from the microcontroller (using the PULSIN function to measure the pulse width). It's only a single channel, but still, for a buck you could buy several. Any comments on this approach?

Of course that particular chip is a surface-mount chip. I'd vastly prefer a DIP or SIP. Anyone have a chip they recommend for this purpose? (Yes, I can wade through Digikey myself; I'm just hoping someone has a favorite.)

Thanks,

- Joe

Reply to
Joe Strout

The venerable ADC0831 is only a couple bucks, but it is only 8-bit. A decent 10- or 12-bit version shouldn't be that much more. These basic chips use simple serial to keep things cheap.

You can also do it with an input capture timer, a resistor, and a capacitor. It's not as accurate, but it works for simple tasks. Another way is to use a 555. There are a number of ways to implement this. Search the Web and you'll find examples. This is basically how the PC gameport works. Here is just one page of many that discusses it:

formatting link

Take a look at the following PDF on the Parallax site for some ideas:

formatting link

They provide the book with an A2D kit they sell. The kit is intended for the BASIC Stamp, but the concepts are the same.

-- Gordon

Reply to
Gordon McComb

Thanks, that's a good start. I see there's also an ADC0834, which is still 8-bit but offers 4 channels, for $9. That's not too bad.

Sounds like the voltage-to-frequency converter idea I had shortly after my first post. I'm currently reading over the data sheet for the LM231, which is under $5. The thing I like about this approach is that it should be dead-simple to use from the ARMexpress, which has a PULSIN function for measuring an input pulse width. That should make getting a value from it a one-liner.

(The same technique would work directly with the TSL230 Light to Frequency converter too, if one had need for such a thing.)

But I haven't yet worked through whether this would actually be faster than a serial interface.

Hey thanks, that's very neat! It's just at my level. :)

So the BASIC Stamp doesn't have analog inputs either? That surprises me. But if so, it puts the ARMexpress in good company, and means I should find lots of other people who have already solved this problem.

Thanks,

- Joe

Reply to
Joe Strout

Yes, I frequently end up not finding what I really wanted at DigiKey, which is why it's great that I have kind folks like you to ask for help. :) I'm not sure quite what I did wrong in this case... pity that their parametric search doesn't include "price" as a parameter!

:) Well, I want to get to that point too. Seems to me that they're the swiss-army knife of electronics; once you learn to program and support one of these things, you can use them in place of a whole lot of more specialized parts.

Yes, if there are solutions in the $3-$4 range (or $9 for a 4-channel one), then there isn't as much opportunity as I thought.

Yes, I wish I had one with A/D built in... but I really dig the ARMexpress in every other way, which is why I'm putting a bit of effort into seeing how this one little problem can be solved.

Yeah, Coridium did that with their newer ARMmite board, but they also took a couple of big steps backwards IMHO (much larger form factor, harder to prototype with as it's no longer a DIP package, programmable only from the built-in USB port rather than serial, and requires the use of Windows).

Thanks,

- Joe

Reply to
Joe Strout

I just wish they would stop showing me items that have 1000 piece minimum orders!

That's the way I treat them. One of my projects had 9 PIC's on it.

[snip money making opportunity]

The ARMmite does sound like they removed some pertty interesting features.

I've always been scratching my head about the ARM's. Billions of them are made, but why can't some clever manufacturer figure out how to put one into a DIP package for less then $10?

-Wayne

Reply to
Wayne C. Gramlich

Since the ARMexpress is something of a BASIC Stamp "compatible" device you may want to read up on the documentation for the chip before spending much more time on this. I think you'll find that like the BASIC Stamp it supports an RCTIME statement that does exactly what the BASIC Stamp does with the resistor/capacitor (hence "RC") measurement.

There's not a lot of accuracy with this approach, but it's not bad for many tasks. For most anything else there are plenty of ADC chips out there. This is a well-travelled road.

-- Gordon

Reply to
Gordon McComb

Seemed like it must be. I did indeed see RCTIME in the documentation, but it didn't sound relevant. It says "Measure the time which pin remains at *level*, returning the value to variable." It sounds the same as PULSIN, except that it applies when the pin is already at the specified level (low or high), whereas PULSIN waits for the next transition to that level before starting its measurement.

But both RCTIME and PULSIN seem to measure the time at which a digital input remains in a given state. How does that help me with analog sensors?

An attempt to answer this very question myself (adding RCTIME to my search terms) did turn up these, which look helpful:

I think I see now -- this doesn't have its own resistor/capacitor circuit inside the chip; instead you set up your own R/C circuit in such a way that you can pull the pin low (discharging the capacitor?), and then let it charge up again in a way that the charging time depends on the voltage or resistance you're trying to measure. The RCTIME function will then return how long this took to cross a threshold indicating a digital "high" state. Clever!

I'll have to play with this a bit, but it sounds like a promising approach when minimizing the component count is desired. Thanks again!

Best,

- Joe

Reply to
Joe Strout

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.