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

How to setup ADC port on 16F819 ?

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



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

How to setup ADC port on 16F819 ?
PostPosted: Tue Mar 13, 2018 8:22 am     Reply with quote

Hi!

I am using AN4 for analog input signal.
Code:

#include <16F819.h>                         
#device  adc=10                             
#FUSES   INTRC_IO,WDT                     
#FUSES   NOPUT,NOMCLR,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT 
#use     delay(clock=4000000)               

#byte    OSCCON = 0x8F
#use     fast_io(A)
#use     fast_io(b)

float    Vreadch;
int1     led1,led2;

void     main()
{
 setup_oscillator(OSC_4MHZ);               
 disable_interrupts(GLOBAL);
 
 setup_timer_0(RTCC_DIV_8);     
 setup_timer_1(T1_DISABLED);               
 setup_timer_2(T2_DISABLED,0,1);           
 setup_adc_ports(AN4);

 port_b_pullups(TRUE);
 setup_spi(FALSE);
 set_tris_A(0b00010000);                   
 set_tris_b(0b00000000);                   
 setup_wdt (WDT_2304MS);                   

 while (true)
       {
        set_adc_channel(4);delay_us(20);
        Vreadch = read_adc();delay_us(20);
        restart_wdt();
       }
}


Compile report
***Error12"wash.c"Line26[18,21]:Undefined Identifier AN4

How to set up port for AN4 pin ?

Best regard
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Tue Mar 13, 2018 8:38 am     Reply with quote

Open the 16F819.h file and look at the constants allowed for the setup_adc_ports function.
sorasit46



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

PostPosted: Tue Mar 13, 2018 5:22 pm     Reply with quote

gaugeguy wrote:
Open the 16F819.h file and look at the constants allowed for the setup_adc_ports function.


16f819.h
Code:

// Constants used in SETUP_ADC_PORTS() are:
#define NO_ANALOGS                           7    // None
#define ALL_ANALOG                           0    // A0 A1 A2 A3 A4         
#define AN0_AN1_AN2_AN4_VSS_VREF             3    // A0 A1 A2 A4 VRefh=A3             
#define AN0_AN1_AN3                          4    // A0 A1 A3
#define AN0_AN1_VSS_VREF                     5    // A0 A1 VRefh=A3
#define AN0_AN1_AN4_VREF_VREF             0x08    // A0 A1 A4 VRefh=A3 VRefl=A2             
#define AN0_AN1_VREF_VREF                 0x0D    // A0 A1 VRefh=A3 VRefl=A2
#define AN0                               0x0E    // A0
#define AN0_VREF_VREF                     0x0F    // A0 VRefh=A3 VRefl=A2
#define ANALOG_RA3_REF         0x1         //!old only provided for compatibility
#define RA0_RA1_RA3_ANALOG     0x4         //!old only provided for compatibility
#define RA0_RA1_ANALOG_RA3_REF 0x5         //!old only provided for compatibility
#define ANALOG_RA3_RA2_REF              0x8   //!old only provided for compatibility
#define RA0_RA1_ANALOG_RA3_RA2_REF      0xD   //!old only provided for compatibility
#define RA0_ANALOG                      0xE   //!old only provided for compatibility
#define RA0_ANALOG_RA3_RA2_REF          0xF   //!old only provided for compatibility

That means I'm not able to set just AN4 pin or not.

Thk.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 13, 2018 6:09 pm     Reply with quote

That's correct. You can't do it with that PIC.

I suggest you switch to the 16F1847 which can use individual pins for A/D.
However, it requires a Pickit3, ICD3 or higher to program it.
sorasit46



Joined: 07 May 2007
Posts: 69

View user's profile Send private message

PostPosted: Tue Mar 13, 2018 6:40 pm     Reply with quote

Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Wed Mar 14, 2018 2:07 am     Reply with quote

and (of course), understand that this is not something that CCS are forcing, it is dependant on the capabilities of the PIC itself. This is why we repeat 'read the data sheet'....
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