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

accessing ADFM [solved]

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



Joined: 10 Feb 2011
Posts: 241
Location: Vancouver, BC

View user's profile Send private message

accessing ADFM [solved]
PostPosted: Wed Mar 23, 2011 4:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 23, 2011 5:11 pm     Reply with quote

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);
  }
}   
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