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

negative voltage range

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



Joined: 12 Jul 2006
Posts: 9

View user's profile Send private message

negative voltage range
PostPosted: Wed Jul 12, 2006 10:44 am     Reply with quote

adc on 18f4550
PostPosted: Wed Jul 12, 2006 10:20 am Reply with quote
I am collecting the analog data from strain guages that are connected to a fiberglass arm. When the arm bend the resistance changes. Bend it one way and the voltage should go positive and bend it the other is should go negative. I am not sure how to read the negative values from adc. It just returns to 0. Below is the code I am using.
Code:

//init
setup_adc_ports(AN0|VSS_VREF);
setup_adc(ADC_CLOCK_DIV_16);
set_adc_channel(0);


port_b_pullups(TRUE);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_HIGH|VREF);
lcd_init();
setup_low_volt_detect(FALSE);
setup_oscillator(FALSE);

//usage of adc
#define VREF 12.0
long sample = 0;
float volts = 0.0;

sample = read_adc();

volts = (VREF/1024.0) * (float)(sample);




Any help would be much appreciated.
Thanks
dmendesf



Joined: 31 Dec 2005
Posts: 32

View user's profile Send private message

PostPosted: Wed Jul 12, 2006 11:13 am     Reply with quote

You can�t read negative values from the A/D. You can only read from 0 to VrefH (or from VrefL to VrefH, if you set it this way). Both VrefH and VrefL MUST be in the 0 to VDD (5.5V max) range. All this means that you need analog conditioning of your signal: suppose you use O for VrefL and 4.096V for VrefH (very common values... think why). You can use one (or some, deppending of your needs) operational amplifier to shift the resting position signal to 2.048V and make it scale near to 4.096V when fully bended to one side, and near 0V when bended to the other side. This sort of thing scares people from a programming-only background, and that�s one of the differences between programming C# / ASP / Delphi / etc from programming a uC to do what you want... You must care for a LOT of things, not all of them programming-related.
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Wed Jul 12, 2006 11:14 am     Reply with quote

Quote:
When the arm bend the resistance changes.


What is your circuit? Is the sensor using a positive and negative voltage (+/-5 volts for example) as power and ground or is it using 0V to 5V? Its hard to say without knowing what your circuit looks like.

Also, in the other thread that you started about this, the reply that you got sounded like a good option.
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