|
|
View previous topic :: View next topic |
Author |
Message |
Megadave
Joined: 04 Jan 2011 Posts: 4
|
ADC configuration question |
Posted: Tue Jan 04, 2011 2:32 pm |
|
|
Hello
I am using an 18F4550 and I need to use port AN7 as an analog input and the rest as digital inputs and outputs but unfortunately a board has already been laid out so I can't make any changes. How can I use port AN7 to read a voltage without affecting A0-A6 (A6 would be the only output while the rest are inputs)? The datasheet for this PIC shows that it doesn't allow for a single ADC port configuration unless you use AN0. I've searched this forum but haven't really found an answer to my question. Would reconfiguring the ADC port (NO ANALOG) after I do a read work? Any suggestions? Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Jan 04, 2011 4:03 pm |
|
|
A couple of questions.
Can you turn off the analog source when you are not reading it?.
How accurate do you need to be?.
There are two separate problems. The first is the 'nastiest'. Digital inputs, do not like being left with voltages attached in the indeterminate levels between 'on', and 'off'. If you leave a voltage like this for a long time, it can locally overheat the gate, and cause damage. It will also draw significant extra power. With a single input like this, you will usually 'get away' with it. However if you could turn off the analog source, when you program the inputs back to 'digital', you would avoid the problem.
Basically, digital inputs, don't terribly 'like' analog voltages being attached.
When you have the inputs set to 'analog', there should be not problems (I'm assuming you are using Vdd as Vref). However if the digital inputs or outputs transition while you are reading, there _will_ be an increase in noise on the signal (since these lines are connected to the input multiplexer). Only small, but perhaps a count, if there are significant transitions going on. Hence slightly reduced accuracy.
So what you describe, can basically work fine, if you can disconnect the analog signal (and ideally pull the line to to one rail), while the inputs are programmed as digital. If not, it'll 'probably' work, but I have seen a commercial unit that did this, and had a remarkably 'high' failure rate in use....
Best Wishes |
|
|
Megadave
Joined: 04 Jan 2011 Posts: 4
|
|
Posted: Tue Jan 04, 2011 5:30 pm |
|
|
Ttelmah, so what I am doing is reading the voltage off a pot with AN7(with 2.048v ref). I'm using AN6 to send serial data to an LCD. The other signals are normally high through pullup resistors reading an input from a keypad. I would read the ADC every 10sec So basically what I was planning to do was the following:
Code: |
void read_adc_port()
{
setup_adc_ports(ALL_ANALOG |VSS_VREF);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(AN7);
delay_us(20);
var = read_adc();
setup_adc_ports(NO_ANALOG);
setup_adc( ADC_OFF );
}
|
Would this cause an issue with the gate overheating??? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Wed Jan 05, 2011 3:22 am |
|
|
You have a problem with the reference.
Analog inputs, aren't allowed to go above the Vref+ (some chips specify Vref+0.3v, but the 4550, specified VrefH, as the maximum voltage on an input). Basically you reverse bias the multiplexer FET if you do this, and it starts to act as a diode, and will pull the Vref up. So you can't have a 2.048 reference, and leave digital signals connected to the other pins when the inputs are setup as analog.
You will develop excessive heat in the A7 input, when it is set as digital as well.
I'm afraid I have to say the _best_ solution, is getting the soldering iron out, and doing a patch on the board to swap A7, and A0. Anything else is likely to cause problems. A pity if you have had many made, but this is why I'll always go to something like four boards for the first 'alpha' test.
A real case of 'vital to read the data sheet'.
Best Wishes |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Jan 05, 2011 1:23 pm |
|
|
I agree with Ttelmah. There is no good software solution. This is what careful study of the datasheet and prototype PCB runs are for. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|