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 initialize PIC16F877 in ADC mode using microC?

Status
Not open for further replies.

theblackmac

Newbie level 3
Joined
May 2, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
hi

i'm working on a project that is a Digital relay to for an over current and negative sequence in a three phase motor.

the thing is I haven't worked on a PIC nor on the microC before, although I toke C language a while ago.

i need to take an Analog input to the microchip.

how can program initialize the pic to be in ADC mode.

P.S. I've already got the development board.

thanks
 

PIC16F877 and microC

mikroC has excellent help with lots of sample codes.. check them out
 

Re: PIC16F877 and microC

Check the mikroC manual for teh ADC library @ **broken link removed**
 

PIC16F877 and microC

thanks

but this is really deep and i don't have much time, do you have already written examples, that would help.

thanks again
 

Re: PIC16F877 and microC

It has an example, you can start from it ISA.
 

Re: PIC16F877 and microC

dear friend

if you don't have time, how you expect your project works fine?
till this time you could have go through the help file and the datasheet, you would be able to fine the solution
you did not specified which channel you are going to use, then how you expect others to provide you help?
please try something and come with the code that you wrote,it will be easy to clear the mistake

regards

ml
 

PIC16F877 and microC

I'll try something and I'll get back to you.

thank you.
 

Re: PIC16F877 and microC

can anyone tell me how can i make source code with mikroc for thic schematic??
 

PIC16F877 and microC

Hi,
You are using a 5v power supply, so your ADC reference is 5v. So, since you are using 10-bit ADC (you can configure to 8-bit if you like), the maximum value will be 1023 which will be achieved when input = vref = 5v. So anything you read will be on a scale of 0 to 1023 for 0 to 5v. It follows:
Code:
Val(ADC) = (Input Voltage / Ref Voltage) * (2 ^ Resolution)
So,
Code:
Val(ADC) = (Input Voltage / 5) * 1024
So, you read the ADC channels as:
Code:
unsigned int AD1;
unsigned int AD2;
AD1 = ADC_Read(0);
AD2 = ADC_Read(1);
AD1 and AD2 now hold digital values for corresponding analog values at ADC channels 0 and 1 respectively.
Ignoring channel 1 for the moment, let's consider you have 35'C temp. So LM35 reads
Code:
35 * 0.01 = 0.35v
. This will be read by PIC as
Code:
(0.35/5) * 1024 = 71
AD1 stores 71.
Now you need to convert this such that you can show the value on the 7-segments.

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top