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 read adc from channels AN6,AN7 at PIC24HJ12GP201?

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



Joined: 17 Jul 2010
Posts: 26

View user's profile Send private message

How to read adc from channels AN6,AN7 at PIC24HJ12GP201?
PostPosted: Wed Apr 17, 2013 1:43 am     Reply with quote

ccs compiler 4.140
On PIC24HJ12GP201 have 6 channels of analog. I try to read adc from channel AN0,AN1,AN2 and AN3 successfully but on channel AN6,AN7 cannot. Please advise.

this is some header file about adc.
Code:
// Constants used in SETUP_ADC_PORTS() are:
// First argument:
// OR together desired pins
#define NO_ANALOGS      0           // None
#define ALL_ANALOG      0xFFFFFFFF  // All
#define sAN0      0x00000001 //| A0
#define sAN1      0x00000002 //| A1
#define sAN2      0x00000004 //| B0
#define sAN3      0x00000008 //| B1
#define sAN4      0x00000010 //| B15
#define sAN5      0x00000020 //| B14


And this my code
Code:

#include <24HJ12GP201.h>
#device adc=12
#fuses FRC,NOWDT,NOPROTECT_HIGH,NODEBUG,NOBSS,NOPUT,NOJTAG,NOWRT
#fuses OSCIO,NOIESO,NOPR,NOALTI2C,NOWRTB
#fuses NOIOL1WAY,NOCKSFSM,NOWINDIS
#use delay(clock=80M,internal)
#use standard_io(all)

unsigned long  result1,result2,result3,result4,result6;

void main()
 {
  setup_oscillator(OSC_INTERNAL);
  set_tris_a(0b0000000000000011);     
  set_tris_b(0b1000000000000011);     
  setup_adc_ports( sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|VSS_VDD); 
  setup_adc(ADC_CLOCK_DIV_64);     

while(TRUE)
   {
                 set_adc_channel(0);   //read from channel 0
                 delay_ms(2);
                 result1=read_adc();
                 delay_ms(10);
                 set_adc_channel(1);   //read from channel 1
                 delay_ms(2);
                 result2=read_adc();
                 delay_ms(10);
                 set_adc_channel(2);  //read from channel 2
                 delay_ms(2);
                 result3=read_adc();
                 delay_ms(10);
                 set_adc_channel(3);  //read from channel 3
                 delay_ms(2);
                 result4=read_adc();
                 delay_ms(10);
                 set_adc_channel(4);  //read from channel 4
                 delay_ms(2);
                 result5=read_adc();
                 delay_ms(10);
                 set_adc_channel(5);  //read from channel 5
                 delay_ms(2);
                 result6=read_adc();
                 delay_ms(10);
                 .
                 .
    }
}
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Wed Apr 17, 2013 3:50 am     Reply with quote

You didn't enable the analog channel on AN6 & AN7

Code:

setup_adc_ports( sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|VSS_VDD);

Should be
Code:

setup_adc_ports( sAN0|sAN1|sAN2|sAN3|sAN6|sAN7|VSS_VDD);

and also you are reading from Analog channels 4&5 they should be 6 & 7.
masterat



Joined: 17 Jul 2010
Posts: 26

View user's profile Send private message

How to read adc from channels AN6,AN7 at PIC24HJ12GP201?
PostPosted: Wed Apr 17, 2013 6:30 am     Reply with quote

Thank you , alan for your prompt reply .

But I understand that in PIC24HJ12GP201 head file is declare for AN6=sAN4 and AN7=sAN5 or have something wrong?
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Wed Apr 17, 2013 7:09 am     Reply with quote

Errr no......
sAn6 and sAN7 are for AN6 & 7 respectivly accordind to my CCS header file.
masterat



Joined: 17 Jul 2010
Posts: 26

View user's profile Send private message

PostPosted: Wed Apr 17, 2013 7:29 pm     Reply with quote

I try change to sAN6,sAN7 compiler error "Undefined identifier sAN6 sAN7 "

This is my 24HJ12GP201 Header file list
Code:

//////// Standard Header file for the PIC24HJ12GP201 device ////////////////
// Constants used in SETUP_ADC_PORTS() are:
// First argument:
// OR together desired pins
#define NO_ANALOGS      0           // None
#define ALL_ANALOG      0xFFFFFFFF  // All
#define sAN0      0x00000001 //| A0
#define sAN1      0x00000002 //| A1
#define sAN2      0x00000004 //| B0
#define sAN3      0x00000008 //| B1
#define sAN4      0x00000010 //| B15
#define sAN5      0x00000020 //| B14



+++++++++++++++++++++++
Most header file lines deleted.

Reason: Forum rule #10
10. Don't post the CCS example code or drivers. This includes header files for devices (example 18f452.h).

Forum rules:
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

- Forum Moderator
+++++++++++++++++++++++
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

PostPosted: Wed Apr 17, 2013 9:44 pm     Reply with quote

One major rule here is never post CCS supplied code in the forum (device files, driver files, example files, etc.).

The file you have is incomplete. You should report it to CCS support via the email address provided on their web page so they can fix it.

In the mean time, take a look at AD1PCFGL register in the data sheet and compare it to the sAN values in the .h file you posted. You should quickly see a pattern in how they are defined vs how the register expects them to be. You could theoretically add the additional values to the .h file this way.
masterat



Joined: 17 Jul 2010
Posts: 26

View user's profile Send private message

PostPosted: Thu Apr 18, 2013 2:28 am     Reply with quote

Thank you jeremiah, and sorry for my foolish post about header file. Now I can use all adc analog input by you hint.
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