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 support@ccsinfo.com

Output on Port A?

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



Joined: 25 Nov 2004
Posts: 30
Location: Germany

View user's profile Send private message

Output on Port A?
PostPosted: Tue Aug 16, 2005 5:05 am     Reply with quote

Hello,

I am using the 18F258 and I want to measure voltage and use some pins of port A as outputs.

I know how to measure the voltages. I want to use no reference but the normal levels.

How to setup the pins? I could use

setup_adc_ports( AN0_AN1_AN2_AN4_VSS_VREF);

but I do not have a reference, so the line is not correct. I don't know what to write for VREF so that there is used the normal voltage level. VSS or VPP don't work.

Another way is using

setup_adc_ports(ALL_ANALOG);

but then I can't use some of the pins as outputs, can I?

I am looking forward for your help and I would be very thankful for it.

Bye, pom
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Tue Aug 16, 2005 8:14 am     Reply with quote

Code:

    setup_adc_ports(RA0_RA1_RA3_ANALOG);
    setup_adc(ADC_CLOCK_INTERNAL);
    set_adc_channel(0);


This code uses 5V as the reference.
In my case, i only use RA0 & RA1 as analog inputs. RA3 is unfortunately a wasted pin which i tie to either the vdd or vss just to terminate it.

You say you want to use some RA pins as i/o. You can either use RA0 only, RA0,1,3 as a/d while the rest are io, etc. It's in the datasheet. In summary, you do not have the liberty to arbritrarily choose which pins you want as io and which ones as a/d pins. If that was otherwise the case, then i would choose not to waste the RA3 pin as in my code example above.
pom



Joined: 25 Nov 2004
Posts: 30
Location: Germany

View user's profile Send private message

PostPosted: Wed Aug 17, 2005 1:34 am     Reply with quote

I see the problem.

Now I was successful in measuring the voltages at pins A0, A1, A2. Unfortunately I didn't know, that there would be a problem with choosing these three for measuring and pin A3 as output. I can't change the circuit, because ist is etched (correct word?).

But as I said, I was successful in measuring the three voltages. I just used
Code:

set_adc_ports(all_analog);

But nevertheless the orders
Code:

output_low/output_high(PIN_A3);

seem to work correct. Will there be a problem I don't see at the moment or is it ok to work with it?

Have a nice day, pom
Ttelmah
Guest







PostPosted: Wed Aug 17, 2005 2:36 am     Reply with quote

It should work OK. However you slightly increase the potential 'noise' sources on your analog measurements. basically to be used as an analog pin, three things have to happen:
1) The pin has to be selected as an analog input in the setup.
2) The pin has to be selected to be read using the analog multiplexor.
3) To make any sense, the pin has to be set as an input, since otherwise the drive transistors turn on and drive the pin.

Now you can therefore use a pin that is set by number '1' to be 'analog' as an output, by just changing TRIS (which is what you are doing by outputing data on the pin), and enabling the drive transistors. The 'downside' is that the digital signal will still be routed a little further into the analog circuitry than would otherwise happen, being fed through the first selector, into the analog multiplexor. This makes it more likely to introduce noise into the analog circuitry. So long as you are careful, that the line is not connecting to a noisy signal, and do not change the line yourself when taking a reading (the less the processor is doing when taking an analog reading the better - this applies always for good accuracy), everything should be OK.

Best Wishes
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