CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ADC configuration question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Megadave



Joined: 04 Jan 2011
Posts: 4

View user's profile Send private message

ADC configuration question
PostPosted: Tue Jan 04, 2011 2:32 pm     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Tue Jan 04, 2011 4:03 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 04, 2011 5:30 pm     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Wed Jan 05, 2011 3:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 05, 2011 1:23 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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