Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

ADC using PIC 16f877a

Status
Not open for further replies.

gopintj

Member level 4
Joined
Sep 1, 2010
Messages
77
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
Thirukalukalukundra, Kanchipuram, Tamilnadu, India
Activity points
1,953
Hello friends,..!!!!

I am very new to Microcontrollers. As i am a Final Year Electronics student, I would like to build ADC as my mini project.

I hav searched lots of webpage and i found nothing helpful.

This is my program coding.. Please help me. :(

Code:
#include<pic.h>
#include"delay.c"
#include"lcd_driver.c"
__CONFIG(0x1932);
void adc_init(void);
void adc_channel(void);
unsigned char adc_res(void);
void main()
{	
	
	unsigned char result=0;
	setup_lcd_port();
	lcd_init();
	adc_init();
	adc_channel();
while(1)
	{
		result=0;
		DelayUs(20);
		result=adc_res();
		lcd_goto_pos(1);
		lcd_putn(result);
		DelayUs(20);
		}
}
void adc_init(void)
{
	TRISA=0x01;
	TRISC4=0;
	DelayUs(20);
	ADCON1=0b10000010;
}
void adc_channel(void)
{
	DelayUs(20);
	ADCON0=0b11000001;
}
unsigned char adc_res(void)
{
	ADRESL=0;
	DelayUs(10);
	ADGO=1;
	while(ADGO)
	{
		
		continue;
		
	}
    return ADRESL;
	
}

I am using 16f877a and High Tech C compiler.

Thanks in advance.. :)
 
Last edited by a moderator:

bigdogguru

Administrator
Joined
Mar 12, 2010
Messages
9,831
Helped
2,348
Reputation
4,690
Reaction score
2,273
Trophy points
1,413
Location
Southwest, USA
Activity points
62,490
These are the best PIC tutorials I have come across online:

Gooligum PIC Tutorials

Gooligum Midrange PIC Hi-Tech C Tutorials

The cover both the baseline and midrange PICs using both MPASM Assembler and Hi-Tech C.

Your 16F877A is a midrange PIC and tutorial 8 in the second link above covers Analog to Digital Conversion.

You should have no problems find your answers in these tutorials. They are very professionally done in PDF form with downloadable source.

Hope the tutorials help you in your endeavors.
 

gopintj

Member level 4
Joined
Sep 1, 2010
Messages
77
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
Thirukalukalukundra, Kanchipuram, Tamilnadu, India
Activity points
1,953
Thanks for your valuable reply.. :)

I think, Analog Input in Channel 0 of 16f877a is not suitable for A/D conversions.

I then, tried in channel 1 and i got the output successfully.. :)


The doubt that i hav now is, Which one is the best compiler,.. i mean, I have known about High tech c compiler and i m working on it till now. :)

But, some says that, CCS compiler is better than High Tech C compiler...!!!!!

Could you tell me which of the above is best one to create codes...???

Waiting for your valuable reply. :)
 

engshahrul

Banned
Joined
Apr 27, 2009
Messages
330
Helped
97
Reputation
194
Reaction score
94
Trophy points
1,308
Location
Malaysia
Activity points
0
The doubt that i hav now is, Which one is the best compiler,.. i mean, I have known about High tech c compiler and i m working on it till now. :)

But, some says that, CCS compiler is better than High Tech C compiler...!!!!!
I'm using Hi-Tech compiler. I like to use Hi-Tech. I also heard about CCS Compiler and Micro C, but I don't give a try yet.

From my view, I see the CCS Compiler and Micro C have many ready made function that user can use, while Hi-Tech don't have many function. I'm using Hi-Tech with all my own function but this is good to get more understanding what's going on.

The Hi-Tech is cheaper but CCS I heard need to pay some yearly, maybe for the function updates.
 

gopintj

Member level 4
Joined
Sep 1, 2010
Messages
77
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Location
Thirukalukalukundra, Kanchipuram, Tamilnadu, India
Activity points
1,953
Oh.. :)

Thank you for your valuable reply.. :)

I here after going to use High Tech C compiler to improve my knowledge as like you ppl..:)

Thank u very much once again.. :)

dont use the forum as your mobile and spoil the quality of it...

spend some time to type the complete words when you ask for help...

this is the last warning to you ,
 
Last edited by a moderator:

Zwilorg

Member level 5
Joined
Oct 13, 2010
Messages
89
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Activity points
1,906
You have alot of compilers available to use.

Some will need payment thought.

Arduino - easiest (huge number of libraries. They go as far as having libraries for specific IC, like max6674 or max6675.

CCS and Mikro - they have a decent community helping them and they also have a very good number of libraries to compare and create more complex codes

Hi-Tech - (the one i use) has loads of ppl using it but the number of libraries built for it are very small comparing with the others... but when you get something working on it you get double pleased. You need to check datasheets, etc... etc... i think that by working with this compiler you learn more of C than working on the others ;)
 

sebgar

Newbie level 4
Joined
Jun 30, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,345
These tutorials are great! Thanks for the links, I'm new to pics, I've been looking for something like this for a while.
 

ravimd

Newbie level 4
Joined
Mar 2, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,345
I was not able to find out that tutorial for free. Can any one help ?
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545

wire042

Newbie level 3
Joined
Mar 2, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
Hi Tahmid

this is great work.
How can it be read with an LCD, to display the value maybe the RMS value like a range of 100V--300V
 

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
What do you mean by read with LCD. The value you get from adc is converted to string and then passed to lcd display function which displays the adc data on LCD.
 

wire042

Newbie level 3
Joined
Mar 2, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
What I mean is this how do I measure an RMS with range of 100v-300v and above to display it on an LCD. This is my question
 

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
Vrms = V/sqrt(2)

If you are measuring a scaled down dc value proportional to some AC value then you calculation will be

like this.

If your adc input is 5V DC and your AC for 5V DC is equal to 300 V AC then

5V DC = 1023 raw adc value

1023 * x = 5
x = 5/1023 = 0.0048875855327468

If raw ad c value 765 then 765 * 0.0048875855327468 = 3.73900293255132 V

5V Dc = 300V AC

5 * y = 300

y = 300/5 = 60

So, 3.739 * 60 = 224.34 V AC

Try this method and see if it works. In AC the rms value will be equal to 70% of the peak value

Vrms = V/sqrt(2) = 224.34/1.41421 = 155.5648

Eg: 165 V AC = 115 V AC RMS

If you get 230 V AC RMS then actual AC is 325.266 V
 

wire042

Newbie level 3
Joined
Mar 2, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
Ok I think I got it but I have to try it and see the result. thanks a million Jayanth.devarayanadurga

- - - Updated - - -

Ok I think I got it but I have to try it and see the result. thanks a million Jayanth.
 

sinorbee

Newbie level 6
Joined
Apr 8, 2013
Messages
12
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,366
hello guys i am doing a ph meter project using pic 16877a, i have no idea about the coding can anyone help me please.......

thank you
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top