View previous topic :: View next topic |
Author |
Message |
alcomen
Joined: 13 Dec 2006 Posts: 10
|
PIC18F2431 X A/D |
Posted: Thu Feb 15, 2007 7:17 am |
|
|
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
|
|
Posted: Thu Feb 15, 2007 10:33 pm |
|
|
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
|
|
Posted: Tue Feb 20, 2007 7:42 pm |
|
|
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
|
|
Posted: Fri Feb 23, 2007 5:47 am |
|
|
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 |
|
|
|