CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pic16f877 and internal ADC convertion

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kristian
Guest







Pic16f877 and internal ADC convertion
PostPosted: Thu Mar 27, 2003 4:29 pm     Reply with quote

Hello, I'm having truble with the ADC convertion on the pic. So I was wondering if anybody could help me with the code in C for the init, input, convertion and yes almost everything. How should I couple the pic, and what ref on wich pin should I use.

Need HELP

Kristian
___________________________
This message was ported from CCS's old forum
Original Post ID: 13161
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Pic16f877 and internal ADC convertion
PostPosted: Thu Mar 27, 2003 4:48 pm     Reply with quote

:=Hello, I'm having truble with the ADC convertion on the pic. So I was wondering if anybody could help me with the code in C for the init, input, convertion and yes almost everything. How should I couple the pic, and what ref on wich pin should I use.
------------------------------------------------------------

See the CCS example file, EX_ADMM.C, which is in this folder:
c:\Program Files\Picc\Examples

The only lines you need to change are these:
<PRE>
#include <16c74.h>
#fuses HS,NOWDT,NOPROTECT
</PRE>

Change them to be:
<PRE>
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
</PRE>

If your crystal frequency is 4 MHz, then change the HS to XT.

I also assume your PIC is using a +5 volt power supply.

Connect the center pin of a trimpot (1K will work) to pin 2
of the 40-pin 16F877. Connect one end of the trimpot to +5v,
and the other end to Ground.

The example file uses the internal voltage reference of +5v.

___________________________
This message was ported from CCS's old forum
Original Post ID: 13162
Kristian
Guest







Thank you but..
PostPosted: Thu Mar 27, 2003 7:52 pm     Reply with quote

I'm using a 11MHz crystal, should i use a 4mhz? And should I use the setup_adc(ADC_CLOCK_DIV_32)?
I'm measuring the heart beat , so is the 4MHz fast enough?
What is best to use then XT or HS

Thank you so much
___________________________
This message was ported from CCS's old forum
Original Post ID: 13165
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Thank you but..
PostPosted: Thu Mar 27, 2003 8:39 pm     Reply with quote

:=I'm using a 11MHz crystal, should i use a 4mhz? And should I use the setup_adc(ADC_CLOCK_DIV_32)?
:=I'm measuring the heart beat , so is the 4MHz fast enough?
:=What is best to use then XT or HS
:=
-----------------------------------------------------

The data sheet says that the internal A/D clock should
only be used in sleep mode, if the PIC's clock is greater
than 1 MHz.

So, in your case, you should use ADC_CLOCK_DIV_32. The chart
in section 11.2 of the data sheet shows that this is the
correct value for an 11 MHz crystal.

If you look at Table 12-2 in the data sheet, it shows that HS
is recommended for an 11 MHz crystal. You may need a series
resistor in the oscillator circuit, as shown in Figure 12-1.
I use 470 ohms.


The heart beat is about 1-2 Hz. So a 4 MHz crystal would
certainly provide enough processing power to handle such
a low data rate.

You may want to use an external circuit to do some signal
conditioning (ie., op-amp circuits) and use the CCP to measure
the heartbeat frequency. Just a suggestion -- you can always
do it at a later date.

The data sheet can be downloaded here:
<a href="http://www.microchip.com/1000/pline/picmicro/category/flash/index.htm" TARGET="_blank">http://www.microchip.com/1000/pline/picmicro/category/flash/index.htm</a>

Reference manuals, with more information than the data sheet,
can be downloaded here:
<a href="http://www.microchip.com/1000/suppdoc/refernce/midrange/index.htm" TARGET="_blank">http://www.microchip.com/1000/suppdoc/refernce/midrange/index.htm</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 13166
Kristian
Guest







Than you once again, just one more question..
PostPosted: Thu Mar 27, 2003 9:19 pm     Reply with quote

Everything works great now, the only thing is that when I massure, the readings change from hex 3F6 to hex 3FE when Im putting steady 5V trough the AD port. Is there any way I can make this go away. And Is it possible to just massure from 0 to 2,5 V and get the full resulution ( 0 to 3ff) The signals im getting is very small and i need the highest accuracy possible

Thank you so much!
___________________________
This message was ported from CCS's old forum
Original Post ID: 13172
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Than you once again, just one more question..
PostPosted: Fri Mar 28, 2003 12:34 pm     Reply with quote

:=Everything works great now, the only thing is that when I massure, the readings change from hex 3F6 to hex 3FE when Im putting steady 5V trough the AD port. Is there any way I can make this go away. And Is it possible to just massure from 0 to 2,5 V and get the full resulution ( 0 to 3ff) The signals im getting is very small and i need the highest accuracy possible
:=
------------------------------------------------------

Microchip recommends that you put a small capacitor on the
A/D input pin. I would start with .01 uf. See if that fixes
the problem.

If you look in the 16F877.H file, you will see a list of all
the constants that are used to define the A/D pins setup.
Here is one that looks suitable:
#define RA0_RA1_ANALOG_RA3_REF 0x85 // A0 A1 Ref=A3

That one would allow using RA0 and RA1 as A/D inputs. It uses
RA3 as the Vref input pin. So the line of code would be:

setup_adc_ports(RA0_RA1_ANALOG_RA3_REF);

Then you could put 2.5v on the pin A3, as the reference voltage.
___________________________
This message was ported from CCS's old forum
Original Post ID: 13208
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group