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

Detecting voltage

 
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

Detecting voltage
PostPosted: Thu Nov 25, 2004 10:59 am     Reply with quote

Hello,

I want to detect voltage by a 18F258. I know how to read the AD-converter and by this I get a value among 0 and 255 (8 Bit). In default, the 255 represents a voltage of 5V and the 0 represents a voltage of 0V. By changing the reference, the 255 might represent the voltage level of AN3 (2,5V in this case).

Is it also possible to change the 0 level? My aim is to have the 0 representing the voltage of AN2 (1,2 V in this case). My measurement would be delimited among 1,2V (read as 0) and 2,5V (read as 255).

I hope, you understand the question. My english is not that good. If there are problems in understanding, please ask me.

I am looking forward to your answers. Thank you.
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Thu Nov 25, 2004 11:51 am     Reply with quote

From the 18F258's data sheet, page 245:

Quote:
The analog reference voltage is software selectable to
either the device’s positive and negative supply voltage
(VDD and VSS) or the voltage level on the RA3/AN3/
VREF+ pin and RA2/AN2/VREF- pin.


So yes, it's definitely possible.

From the 18f258.h file:

Code:
////////////////////////////////////////////////////////////////// ADC
// ADC Functions: SETUP_ADC(), SETUP_ADC_PORTS() (aka SETUP_PORT_A),
//                SET_ADC_CHANNEL(), READ_ADC()
// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS             0x86         // None
#define ALL_ANALOG             0x80         // A0 A1 A2 A3 A5 E0 E1 E2 Ref=Vdd
#define ANALOG_RA3_REF         0x81         // A0 A1 A2 A5 E0 E1 E2 Ref=A3
#define A_ANALOG               0x82         // A0 A1 A2 A3 A5 Ref=Vdd
#define A_ANALOG_RA3_REF       0x83         // A0 A1 A2 A5 Ref=A3
#define RA0_RA1_RA3_ANALOG     0x84         // A0 A1 A3 Ref=Vdd
#define RA0_RA1_ANALOG_RA3_REF 0x85         // A0 A1 Ref=A3
#define ANALOG_RA3_RA2_REF              0x88   // A0 A1 A5 E0 E1 E2 Ref=A2,A3
#define ANALOG_NOT_RE1_RE2              0x89   // A0 A1 A2 A3 A5 E0 Ref=Vdd
#define ANALOG_NOT_RE1_RE2_REF_RA3      0x8A   // A0 A1 A2 A5 E0 Ref=A3
#define ANALOG_NOT_RE1_RE2_REF_RA3_RA2  0x8B   // A0 A1 A5 E0 Ref=A2,A3
#define A_ANALOG_RA3_RA2_REF            0x8C   // A0 A1 A5 Ref=A2,A3
#define RA0_RA1_ANALOG_RA3_RA2_REF      0x8D   // A0 A1 Ref=A2,A3
#define RA0_ANALOG                      0x8E   // A0
#define RA0_ANALOG_RA3_RA2_REF          0x8F   // A0 Ref=A2,A3


From this, the setups that would suit you are:
ANALOG_RA3_RA2_REF
ANALOG_NOT_RE1_RE2_REF_RA3_RA2
A_ANALOG_RA3_RA2_REF
RA0_RA1_ANALOG_RA3_RA2_REF
RA0_ANALOG_RA3_RA2_REF

If you're only measuring one analog input, then the last choice, RA0_ANALOG_RA3_RA2_REF, would suit you best.
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