Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC 16f877A interfacing with ADC

Status
Not open for further replies.

john86

New Member
Dear all! :)
I need a help on C Code for PIC 16f877A interfacing with ADC (AD7715-5)
My analogue input is 0-5 volts. First of all I wanna show something from ADC in PORTD that is connected to 4 seven segments.
I used an ADC because I need more accuracy and the 10 bit ADC of PIC16f877A is not enough for me.
please help me to do it. :)
Regards,
 
Which compiler are you using? There are examples in the Hitech / samples/serial folder.

I use the 10 bit ADC on the pic's and achieve nearly 20 bit resolution...

The system I replaced uses a dedicated 16 bit ADC.... My resolution is better... It all depends on the hardware / software you use.

Plenty of noise (caps and diodes) and tons of oversampling... Then a decent averaging routine.

Of course it does depend on the signal you're sampling...
 
Last edited:
uh! Ian, thank you for your comment,
I use MikroC, I searched everywhere for an example code but unfortunatelly I didn't find anything :(
yeah there are plenty of noises from compressor and vacuum pump in my system, but It is solvable!
I just need a vivd sample for this application of PIC uC.
thanks again
 
Now I'm simulating a variable voltage between 0 and 5 volts, by a power supply and a multi turn potentiometer.
 
I mean... When you have it done.... What speed will you be sampling....

I analyse crane movement and lifting capacities and sometimes pressure in the hydraulic rams... the movement is slow so I can get away with oversampling

If you signal was fast, like a frequency, you can't afford too much oversampling... I was just wondering about the precision.
 
aha... I wanna use this micro for a "vacuum pressure guage indicator". In this system, pressure, sometimes varies fast and sometimes varis slow.
Indeed a 12 bit ADC is enough for me, but I had a AD7715-5 and I just wanted to write the body of the PIC software for this purpose. and later I'll change AD7715 with a 12 bit ADC.
 
I could help you with Hi-tech.. but I don't have mikroC and I don't plan on installing it.

Burt may be reading this.... He may know somewhere, where there is a C library function example for SPI..
 
Last edited:
anyway, thanks pal, it not a problem if you write it by Hi-tech or MikroC. I just need its C code in a text file.
 
I'll give it a go today... Trouble is! I'll have to write the whole thing in Hi-tech so I can simulate it to prove it works I only have simulation models for slightly different models... I'll get back to you.
 
Dear Ian
I'm wondering that if different C Compilers have different built-in functions? for example if I write a Program in MikroC, it will be different from the program that wrote in Hitech or CCS?!
I'm confused
would you please answer me
thannks
 
The Libraries from each compiler will not compile on other systems without small modifications.

However.. You can write C code that SHOULD compile on any ANSI compliant compiler...

If I stay within certain boundaries you should be okay.... All you need to do is check System specific Identifiers.

SSPBUF, INTCON, OPTION_REG etc...
 
I have done two functions so far... They seem to work.

SPI initialize

Code:
void SpiInitADC()
	{
	RC7 = 1;		// I used RC7 as CS
	TRISC = 0x10;	// SDI as input
	SSPSTAT = 0x40; // cke = 1 ??? 
	SSPCON = 0x30;	// set to on
	}

Read a 16 bit ADC

Code:
unsigned int SpiReadADC()
	{
	char dummy;				// chuck the buffer away
	unsigned int ADC = 0;	// clear last result
	dummy = SSPBUF;
	SSPIF = 0;
	RC7 = 0;				// CS low
	SSPBUF = 0;				// send 0
	while(!SSPIF);			// wait for ADC
	ADC = SSPBUF;			// read it
	ADC<<= 8 ;				// send to high nibble
	SSPBUF = 0;				// send another 0
	while(!SSPIF);			// wait again
	ADC += SSPBUF;			// bottom half
	RC7 = 1;				// CS high
	return ADC;				// All done
	}

It may need tweaking for your ADC but as they are both analog devices it should work.
 
Thank you Ian, I'm waiting for other parts :)
you really helped me.

It will take some time as I can't simulate the adc you are using... I was going to change the read function to take a channel parameter so you can specify which channel to read.
 
Status
Not open for further replies.

Latest threads

Back
Top