Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC setpu in CCS c Code. How to do it?

Status
Not open for further replies.
Joined
Dec 4, 2012
Messages
4,294
Helped
822
Reputation
1,654
Reaction score
793
Trophy points
1,393
Location
Bangalore, India
Activity points
0
I want to know how to setup adc ports in CCS C Compiler. I am using PIC16F887 MCU for the project. I will be using all the analog pins for adc and I will be using the Vref- and Vref+ pins for reference voltage. vref- will be connected to ground and vref+ will be given +2V.

I need an example for setup_adc_ports() function. What should be the arguments for the function? Should I define Vref somewhere else in the code?

I also want to disable the comparators on PORTA.
 

iukhan

Advanced Member level 4
Joined
Oct 4, 2007
Messages
107
Helped
31
Reputation
62
Reaction score
29
Trophy points
1,308
Location
Lahore
Activity points
1,939
I want to know how to setup adc ports in CCS C Compiler. I am using PIC16F887 MCU for the project. I will be using all the analog pins for adc and I will be using the Vref- and Vref+ pins for reference voltage. vref- will be connected to ground and vref+ will be given +2V.

I need an example for setup_adc_ports() function. What should be the arguments for the function? Should I define Vref somewhere else in the code?
setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|sAN9|sAN10|sAN11|sAN12|sAN13|VREF_VREF);
setup_adc(ADC_CLOCK_DIV_8);
I also want to disable the comparators on PORTA.
setup_comparator(NC_NC_NC_NC);
 

Joined
Dec 4, 2012
Messages
4,294
Helped
822
Reputation
1,654
Reaction score
793
Trophy points
1,393
Location
Bangalore, India
Activity points
0
I tried that but it doesn't work. I gave 1.5V which is max value of LM35 output to AN0 and gave +2V to Vref+ pin and 0V to Vref- pin. for 2V it has to give 1023 raw adc value and for 1.5V it should give 767.25 raw adc value but it is not giving the right value.

Edit: I am getting 1023 raw adc value if I give 0V to Vref- and +2V to Vref+ and 1.5V to AN0
 
Last edited:

DR.boy

Junior Member level 1
Joined
Mar 8, 2013
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,362
hello!!
which version of ccs c compiler do u use ?
-if you dont know how to code it, you should be able to chose analogical channels from the Wizard .
this is a simple example : setup_adc_ports(AN0_AN1_AN2_AN3_AN4); which means there are five adc channels .
-setup_adc_ports(AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_); == VRef=A3
 

Joined
Dec 4, 2012
Messages
4,294
Helped
822
Reputation
1,654
Reaction score
793
Trophy points
1,393
Location
Bangalore, India
Activity points
0
@DR.boy

My CCS C is v4.140. The latest vis 4.141

I will try setup_adc_ports(AN0_AN1_AN4_AN5_AN6_AN7_VSS_VDD); Will this take AN2 ad Vref- and AN3 as Vref+ ??

No. setup_adc_ports(AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_); doesn't compile. It gives error.
 

DR.boy

Junior Member level 1
Joined
Mar 8, 2013
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,362
hi
sorry for delay , i went and i back

try this
setup_adc_ports(AN0_AN1_AN4_AN5_AN6_AN7_VREF_VREF);

- - - Updated - - -


good luck !
 
Last edited:

jean12

Advanced Member level 2
Joined
Aug 27, 2013
Messages
529
Helped
5
Reputation
12
Reaction score
6
Trophy points
18
Activity points
5,497
fine for the completed project!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top