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

AD Converter 18f452

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



Joined: 11 Mar 2011
Posts: 3

View user's profile Send private message

AD Converter 18f452
PostPosted: Fri Mar 11, 2011 10:24 am     Reply with quote

Hello, I am working with the A / D converter of the PIC 18F452, I'm having trouble capturing a signal of 2.5 V measured by the A / D converter and printed on the screen.

In 18452.h is:
device adc = 8

In X.C file is:
Code:

void main ()
{
    unsigned int x;

    setup_adc_ports (ALL_ANALOG);
    setup_adc (ADC_CLOCK_DIV_2);
    setup_psp (PSP_DISABLED);
    setup_spi (SPI_SS_DISABLED);
    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);
    enable_interrupts (INT_RDA);
    enable_interrupts (GLOBAL);
/ / parameter not Setup_Oscillator selected from Intr Oscillator Config tab

    / / TODO: USER CODE!

while (1) {
           set_adc_channel (7);
           delay_us (10);
           read_adc x = ();
           printf ("\ r% u \ n ", x);
}


}

My voltage is from 0 to 5V (or FF) should be printing FF / 2 (V = 2.5), but printing is 255 instead of 127. Does anyone know why? I believe that is the problem ADFM.
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Fri Mar 11, 2011 10:52 am     Reply with quote

Several questions/comments:
1) Compiler version -always post this.
2) What clock rate?. FOSC/2, for the ADC clock, is only legal for a maximum of 1.25MHz.....
3) Are you using the RDA interrupt. Have you got a handler for this?. Code will not work properly without this, with the interrupt enabled.
4) Change the SPI setup line, to setup_spi(FALSE). SPI_SS_DISABLED, _enables_ the SPI.....
5) Er. Your read_adc line, is not right as posted. Syntax is:

x=read_adc();

This is probably the main problem.

Best Wishes
paivadaniel



Joined: 11 Mar 2011
Posts: 3

View user's profile Send private message

ops... answer
PostPosted: Fri Mar 11, 2011 11:51 am     Reply with quote

The code is this, had copied wrong
Code:

while (1) {
set_adc_channel (7);
delay_us (10);
read_adc x = ();
printf ("\ r% u \ n ", x);
}


I use the ccs, PCWHD, new version, the rda is already generated by it.

pq psi should change?


man, I think the answer is not ae, I believe that is the bit ADFM.
paivadaniel



Joined: 11 Mar 2011
Posts: 3

View user's profile Send private message

PostPosted: Fri Mar 11, 2011 12:35 pm     Reply with quote

why psi should change?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 11, 2011 1:31 pm     Reply with quote

Try this sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
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