Continue to Site

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.

How to turn off A/D converter and comparator modules in PIC16F877A?

Status
Not open for further replies.

rezaf

Advanced Member level 4
Full Member level 1
Joined
Apr 11, 2009
Messages
106
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Location
Montagram
Activity points
2,147
Hello.
I have a project with PIC but my code don't work properly because the A/D converter is on please help me.how can I turn off A/D converter and comparator modules in PIC16F877A (I don't understand what said in datasheet)??
ADCON0 = ??
ADCON1 = ??
CMCON = ??
Thanks.
 

Re: PIC ADC question

Try this
Have a look at section 11.2, page 112 of the 16F877 datasheet.
There is a table for setting up the ADCON1 register for the PortA i/o.

Pay particular attention to bit 7. This bit sets up for right or left justification of the ADIN result.
For most uses, this bit should be set to '1', right justification.
Bits 0-3 of ADCON1 are used to set up port A to user requirements according to the table. i.e. which pins are analog, which are digital, and what the Vref setup is.

I would also suggest you test your AD program in the free VSM supplied with Proton. This will allow you to test your program before committing to pic.


ADCON1 = %1xxxnnnn

where bit 7 is set for right justification
xxx are don't care
nnnn are set according to user requirement from table. I.E these are the ports you want to set read the input, like this ADCON1 = %1000011 PORTA,0&1 are set has input

The best way to remember is 1=input and 0=output
 

    rezaf

    Points: 2
    Helpful Answer Positive Rating
Re: PIC ADC question

Very Very Thanks my Friend, you give me the best and complete guidance.
Best Regards.
Best Wishes for you.

Added after 2 hours 43 minutes:

sorry but I test your method but have problem yet. I have MikroBasic Pro and write in basic and test with Proteous(PIC16F877A.I tested two mode :ADCON1 = %10000110 and ADCON1 = %011 to turn off all analog pins and use all as digital but have problem and pic don't work properly yet. I have problem with comparator module too. I can't turn off comparator with CMCON = 0x07
Please help me and say the code to turn off all analog pins and use as digital I/O.
and a code to turn off comparators.
Thanks.
 

Re: PIC ADC question

I use PDS, This is the way I set it up and this works on 16F877,A and 18F452

'*********** SETUP THE A/D PORTS****************************
TRISA = %1011001 ' SET PORTA TO ALL INPUT
TRISA = %11101111 ' SET PORTA TO ALL INPUT
ADCON1 = %10000101 ' CONFIG THE A/D CHANNEL TO A0 ONLY
ADCON0 = %10000101 ' CONFIG THE A/D CHANNEL TO A0 ONLY

I've necer trurned off the comparator, Try above and let me know also they these

ADCON1 = %10001101 ' CONFIG THE A/D CHANNEL TO A0 ONLY
ADCON0 = %10001101 ' CONFIG THE A/D CHANNEL TO A0 ONLY

I have not used microbasic,
Does it work in ISIS ?
 

Re: PIC ADC question

according to your speak the code : ADCON1 = %10000101 in table of PCFG3:pCFG0 said that 0101 is AN0 and AN1 analog pin and other pins digital but you say that A0 is analog only, why??
yes the hex output file of mikrobasic work in ISIS. in new version of mikrobasic the compiler give .coff output file and you can debug your code line by line in ISIS.
 

PIC ADC question

If it works in ISIS then it should work in real life, I'd check your hardware setup, try and just print hello world on your LCD, The above owrks for me, I had the same trouble before where the LCD remained blank, all this was casued by the A/D set up
Not sure if microbasic supports this

ALL_DIGITAL = TRUE
 

PIC ADC question

Hi rezaf,
I use mikroBASIC and to turn off ADC and comparator, code should be:
Code:
ADCON1 = 7 'Turn off ADC
CMCON = 7 'Turn off comparator
Hope this helps. It always worked for me. Be sure to set TRIS bits.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top