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 problem

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



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

ADC problem
PostPosted: Tue Sep 15, 2015 1:28 am     Reply with quote

Hi, i'm having trouble with ADC. Suppose when i used pic18f4550 it can be used for 10 bit ADC. But it only display 8bit. What is wrong with my code?

Code:
#include <18F4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,error)

void main()
{
   int i;
   float min, value, max;

    setup_port_a(ALL_ANALOG);
    setup_adc(ADC_CLOCK_INTERNAL);
    set_adc_channel(0);

    do  {
            min=1023;
            max=0;
            for(i=0; i<=1; ++i)
                {
                  delay_ms(5);
                  value = Read_ADC();
           
                   If( value<=min);
                       min=value*5/1023;
                   If( value>=min);
                       max=value;       
                 }
             printf(" Voltage : %2.3f V   NO: %3.0f ", min, max);
            }while(TRUE);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 15, 2015 1:45 am     Reply with quote

Download the CCS manual for your compiler:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look in the section called "ADC". It's on page 48 in the Adobe reader.
(numbered page 38).

It says:
Quote:

#DEVICE ADC=xx
Configures the read_adc return size. For example, using a PIC with a
10 bit A/D you can use 8 or 10 for xx- 8 will return the most significant
byte, 10 will return the full A/D reading of 10 bits.

The default is 8 bits. So you need to put in a #device statement right
after the #include for your PIC.


Also, this is going to fail to compile:
Quote:
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,error)

Consult the CCS manual and fix it.
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Tue Sep 15, 2015 1:51 am     Reply with quote

Thank you very much, problem solve. Very Happy
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