View previous topic :: View next topic |
Author |
Message |
krodkey
Joined: 12 Jul 2006 Posts: 9
|
negative voltage range |
Posted: Wed Jul 12, 2006 10:44 am |
|
|
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
|
|
Posted: Wed Jul 12, 2006 11:13 am |
|
|
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
|
|
Posted: Wed Jul 12, 2006 11:14 am |
|
|
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. |
|
|
|