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

PIC18F2431 X A/D

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



Joined: 13 Dec 2006
Posts: 10

View user's profile Send private message

PIC18F2431 X A/D
PostPosted: Thu Feb 15, 2007 7:17 am     Reply with quote

I am using PIC18F2431 for the first time. Somebody possess an example of as to configure the A/D for this chip?

Somebody obtained 200ksps converter?



Alessandro
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Feb 15, 2007 10:33 pm     Reply with quote

I don't have this PIC to test, but I think the following program will
demonstrate basic operation of the A/D. It should display values
from 0x000 to 0x3FF for an input of 0v to +5v on the AN0 pin.
Code:

#include <18F2431.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000) 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//================================
void main()
{
int16 result;

setup_adc_ports(sAN0 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_16);  // For 20 MHz crystal
set_adc_channel(0);

delay_us(20);

while(1)
  {
   result = read_adc();
   printf("%LX\n\r", result);
   delay_ms(500);
  }

}
alcomen



Joined: 13 Dec 2006
Posts: 10

View user's profile Send private message

PostPosted: Tue Feb 20, 2007 7:42 pm     Reply with quote

Ok

I tested in my house your code. It's right. Tomorrow I go to test in the my job with oscilloscope for the time test acquisition.

Thanks


Alessandro
alcomen



Joined: 13 Dec 2006
Posts: 10

View user's profile Send private message

PostPosted: Fri Feb 23, 2007 5:47 am     Reply with quote

I got 155ksps.

I donī understand why my code only execute the interrupt.

The exemple:

#include <18F2431.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//================================

#int_timer1
void isr()
{
result = read_adc();
set_timer1(65534);
}

//================================
void main()
{
int16 result;

setup_adc_ports(sAN0 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_16); // For 20 MHz crystal
set_adc_channel(0);
delay_us(20);

setup_timer_1(T1_internal);
set_timer1(65534);
enable_interrupts(int_timer1);
enable_interrupts(global);


while(1)
{
printf("%LX\n\r", result);
delay_ms(500);
}

}

This dont print in serial, only read the A/D. Why??????

Thanks



Alessandro
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