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

adc on 18f4550

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







adc on 18f4550
PostPosted: Wed Jul 12, 2006 6:57 am     Reply with quote

Does anyone know what the conversion equation is to convert the value obtained from read_adc() on a 18f4550 chip to volts DC?

Thanks
Ttelmah
Guest







PostPosted: Wed Jul 12, 2006 7:08 am     Reply with quote

It depends on your Vref.
(Vref/1024)*ADC_READING

Note that the divider is 1024, though the output of the ADC, is 0-1023. Also that this will need to be done in floating point arithmetic (slow and bulky). Using a scaled integer is much quicker fo most applications.

Best Wishes
krodkey78
Guest







adc on 18f4550
PostPosted: Wed Jul 12, 2006 10:20 am     Reply with quote

I used the equation and it seems to be working but the voltages will not swing into the negative range. 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
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Jul 12, 2006 10:46 am     Reply with quote

page 399
http://ww1.microchip.com/downloads/en/DeviceDoc/39632c.pdf

It shows range from VREFlow to VREFhigh
and VREFlow can only go down to Vss-0.3 ie the PICs ground.

I think you would need and opamp of some configuration to shift and scale
your reading to fit inside the 0-5V range.
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