View previous topic :: View next topic |
Author |
Message |
16f Guest
|
Help in Multiplexing 16 analog inputs with PIC16F877 |
Posted: Fri Feb 13, 2009 9:47 pm |
|
|
I am trying to multiplex 12 analog sensors with PIC16F877 which has 8 adc channels only. I interface the PIC with two 8 mux/demux analog 74HC4051/4053/4052. Can anyone help me in the coding for multiplexing the readings??? |
|
|
wohn Guest
|
Sugggestion for better performance mux |
Posted: Sat Feb 14, 2009 2:08 am |
|
|
In my opinion as an audio engineer, the 405x series are becoming obsolete fast. A better mux with less distortion and offset problems are the DG series. DG408 replaces the 4051 also the DG409 and 412 replace the other 2, not sure which is which off the top of my head. a simple code would be Code: | for(x=0, x>=7, x++)
{
set_adc_channel (x);
y=read_adc();
do what you want with data
...
...
...
}
for(x=0, x>=5, x++)
{
set_adc_channel (8);
output_x(x);
y=read_adc();
do what you want with data
...
...
...
} |
connect 1-7 analog inputs to PIC and leave the 8th as the output of the mux. Wire the data lines of the mux to whichever port you chose in the seconf for statement. I will provide a drawing if you need.
Hope this helps. |
|
|
Guest
|
|
Posted: Sat Feb 14, 2009 2:13 am |
|
|
Sorry the for statements should read
Code: | for(x=0, x[b]<=[/b]7, x=++) |
The last post I used greater than instead of less than, it's 3 am I'm tired. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
you might check this part |
Posted: Sun Feb 15, 2009 9:18 am |
|
|
the DG406 and ADG406 are both 16 channel excellent analog multiplexors - with 4 binary control lines plus enable - very low common channel capacitance. these work GREAT and offer high ESD protection too.
i can vouch for the 408 /406 solution - you need 4/( 5 with toggled enable) digital outputs and ONE analog input on the pic |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Feb 15, 2009 9:24 am |
|
|
Considering the limited resolution of a PIC ADC, 74HC405x parts are offering sufficient signal quality to my opinion. They are also competitive in terms of leakage currents and similar parameters. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
comparing muxes - DEPENDS ON WHAT YOU ANT TO MEASURE |
Posted: Sun Feb 15, 2009 8:53 pm |
|
|
DG40x - 35 ohm switch resistance - VERY linear at low signal levels - all the way down to the single digit millivolt range +/- 20V tolerance - and the ADG40xB has 3KV ESD protection too.
I've used these with AC currents of 2ua @ 50mv - frequencies from 4khz to 72khz for a scientific instrument i designed some time ago - after THE '4051 WAS PROVED AN ABJECT FAILURE !
ANYWAY
CD4051 74hc4051 EXHIBIT as much as 400 ohms switch ON resistance and significant channel non linearity below 100 mv on the selected channel and as a bonus - inferior off state leakage performance when holding several inputs near VCC potential while in the OFF state -and lastly - channel R varies quite a bit with temperature too. up to 10x the variation as with ADG40x parts
i have used the DG family - OUTPUT directly into an analog port of the PIC - but always had to buffer a '4051 output with an OP AMP - to keep good low Z at the PIC input to avoid long settling times after channel selection ( before read)
the 4051 is cheap - and it maybe be OK for your app - but do your homework with the spec sheets before U R in 2 deep -
and remember - 10 bits / 5 v is appx 5 mv per step - how low do you need to resolve ? at very low sig levels - below 100mv - the difference in the 2 muxes is dramatic - been there - done that - |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Feb 16, 2009 1:04 am |
|
|
Clearly, the DG chips haver better specs than the said CMOS multiplexers. I see however , that you apparently don't know the difference between standard CMOS CD4000 and 74HC series. But even 400 ohms Ron wouldn't cause considerable offsets with PIC input leakage currents.
Ron linearity is an important parameter with analog switches, generally. If directly connected to a PIC ADC input, it's more or less irrelevant if Ron is sufficient low.
There is actually a problem of additional leakage currents or input crosstalk with standard CMOS analog switches, if any CMOS input voltage is exceeding the supply voltage range by e.g. 0.3 V. This effect can be expected also with PIC analog inputs itself. DG40x and other dedicated analog switches have better properties in this respect.
If the application demands a high quality analog multiplexer, one should consider a dedicated high resolution ADC as well. |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Mon Feb 16, 2009 12:35 pm |
|
|
But there are practical considerations.
Is the mux required to run off a single 5V supply? Is it going to be in a hand-wired circuit which makes a DIP package desirable? Is cost a major issue? As has been pointed out, how good does it have to be anyway?
Is "the best" the enemy of "the good enough"?
Or vice versa, of course. |
|
|
n-squared
Joined: 03 Oct 2006 Posts: 99
|
|
Posted: Tue Feb 17, 2009 11:27 pm |
|
|
There is another solution to this problem. Switch to PIC16F887, which is pin compatible and has 14 analog inputs.
It will also allow you to save money by using internal RC instead of an external crystal. _________________ Every solution has a problem. |
|
|
|