|
|
View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
accessing ADFM [solved] |
Posted: Wed Mar 23, 2011 4:34 pm |
|
|
Hi There,
I would like to have my a/d value read right aligned and for that I need to set ADFM to 1.
I tried following:
Code: | #include <18F87K22.h>
#device HIGH_INTS=TRUE, adc=16, ICD=TRUE
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HSM //Hi-Speed crystal oscillator
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPLLEN //No PLL enabled
#FUSES BBSIZ1K //1K words Boot Block size
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=10000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC, ERRORS)
#bit ADFM = ADCON2.7
void main (void)
{
ADFM=1;
int16 adcval=0;
while (true) {
setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_0);
set_adc_channel(sAN0);
delay_us(10);
adcval=read_adc();
fprintf(PC,"0x%4LX\r\n", adcval);
}
} |
But the compiler doesn't seem to know what ADCON2 is as it says:
*** Error 12 "analog.c" Line 16(1,3): Undefined identifier
How do I get access to the ADFM config bit in the ADCON2 register?
Thanks!
MCU: PIC 18F87K22
Compiler: 4.119 |
|
|
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Wed Mar 23, 2011 5:11 pm |
|
|
GOT IT!
Probably not the best version but it works:
Code: |
#include <18F87K22.h>
#device HIGH_INTS=TRUE, adc=16, ICD=TRUE
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HSM //Hi-Speed crystal oscillator
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPLLEN //No PLL enabled
#FUSES BBSIZ1K //1K words Boot Block size
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=10000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC, ERRORS)
//#bit ADFM = ADCON2.7
#byte ADCON2 = getenv("sfr:ADCON2")
void main (void)
{
//test=1;
int16 adcval=0;
setup_adc(ADC_CLOCK_INTERNAL);
ADCON2|= 0x80;
while (true) {
set_adc_channel(sAN0);
delay_us(10);
adcval=read_adc();
fprintf(PC,"0x%x 0x%4LX\r\n", ADCON2,adcval);
}
} |
|
|
|
|
|
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
|