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

Help for ADC mode!

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



Joined: 17 Dec 2006
Posts: 15
Location: Singapore

View user's profile Send private message AIM Address MSN Messenger

Help for ADC mode!
PostPosted: Mon Jan 08, 2007 2:46 am     Reply with quote

Hi all,
Anybody will help me to get the example program for ADC conversion. I want to convert from 2V analog data to 10 bit digital value. My PIC is 16F877A. Thanks a lot!!! Acutally I don't know how to write down in ADC mode.

Kyaw Kyaw.
_________________
Thanks and Best Regards,
Kyaw Kyaw.
Ttelmah
Guest







PostPosted: Mon Jan 08, 2007 5:50 am     Reply with quote

You don't say what clock rate your chip is running?. This changes the settings needed.
There is a potential problem regarding the voltage. The 16F877A, requires a minimum Vref, when the chip is running off 5v, and Vss is the 0v reference, of 2.5v.
How many analog inputs do you want to use. There is a choice of 2, 5 or 7 inputs set as analog, with the external Vref for the 'high' point, and Vss as the low point.
The best place to start is the chip data sheet. If you have trouble translating the ADC options in this, to 'CCS' form, then come back.

Best Wishes
Kyaw Kyaw



Joined: 17 Dec 2006
Posts: 15
Location: Singapore

View user's profile Send private message AIM Address MSN Messenger

Hi Ttelmah
PostPosted: Mon Jan 08, 2007 8:45 am     Reply with quote

Hi Ttelmah,
Sorry, I forgot to say clk freq. My one is 20MHz and I tried to use one or two channels. I saw some examples programs written by PWM programmer and tried with these. But I don't know how to change the Vref+ point. So I looked through the PIC manual and feed 2V and ground from AN3 and AN4 as Vref+ and -. I got some values 03c7 or something like that even I didn't connect for input. Do you have any idea for my problem? Thanks for your consideration about my problem.

Best Regards,
Kyaw Kyaw.
_________________
Thanks and Best Regards,
Kyaw Kyaw.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 08, 2007 1:00 pm     Reply with quote

Quote:

So I looked through the PIC manual and feed 2V and ground from
AN3 and AN4 as Vref+

Look at what Ttelmah wrote:
Quote:

The 16F877A, requires a minimum Vref, when the chip is running
off 5v, and Vss is the 0v reference, of 2.5v.


Quote:

So I looked through the PIC manual and feed 2V and ground from
AN3 and AN4
as Vref+ and -

Look in the 16F877A.H file. It says to use pins A3 and A2, which
correspond to AN3 and AN2.
Quote:
#define AN0_AN1_VREF_VREF 0x0D // A0 A1 VRefh=A3 VRefl=A2



Quote:
I saw some examples programs written by PWM programmer

It's PCM programmer.
Kyaw Kyaw



Joined: 17 Dec 2006
Posts: 15
Location: Singapore

View user's profile Send private message AIM Address MSN Messenger

Sorry PCM!
PostPosted: Mon Jan 08, 2007 7:01 pm     Reply with quote

Sorry PCM programmer,
I wrongly posted yesterday. Actually I used pin 4 and 5 (using AN2 and AN3 for Vref + and -.
Quote:
#define AN0_AN1_VREF_VREF 0x0D // A0 A1 VRefh=A3 VRefl=A2

Could you please explain what is intended for 0x0D? I am not familar with the PIC programming language.
Quote:
I got some values 03c7 or something like that even I didn't connect for input.

DO I need to grounded the unused pin for input? I mean that, now I am trying to test with one analog pin and another pin is not used. Do you have any idea for about getting some strange values?
_________________
Thanks and Best Regards,
Kyaw Kyaw.
Kyaw Kyaw



Joined: 17 Dec 2006
Posts: 15
Location: Singapore

View user's profile Send private message AIM Address MSN Messenger

Wrong data
PostPosted: Mon Jan 08, 2007 9:53 pm     Reply with quote

Hi all, Now I trying to get sampling and I get the some values expected. Without grounded, I got some values like 03f or sometimes,01fc like that even i didn't feed any analog value. When I connected to the AN0 pin with ground (Vss), it showed mostly 0000 and sometime I got 0002 or 0003. I set the Vref+ with 2V { I got by making voltage Divider from 5V supply for PIC 16F877A} to PIN5 (AN3) and Connected PIN4 (AN2) to Vss (0V). When I feed the data (analog output form Meterman light meter LM631) to AN0 I cannot get the acutal value and I got only some value 0038 or 0041 and the digital value is not stable. Can Any of you help me with this case? Thanks for your time!

The quote is the program I used for AD conversion. ( I found in the forum and it is PCM one.)

Quote:
#include <16F877A.h>
#device adc=10
#fuses HS, NOWDT, PUT ,BROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define AN0_AN1_VREF_VREF 0x0D

//===================================
void main()
{
int16 result;

setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
delay_us(20);

while(1)
{
result = read_adc();
printf("%lx \n\r",result);
delay_ms(500);
}

}


I forgot one thing that my Meterman output is 0 to 200mV range. (It is quite low voltage). I also tried with the Vref+ of 1V and still got the same outcomes.
_________________
Thanks and Best Regards,
Kyaw Kyaw.
Ttelmah
Guest







PostPosted: Tue Jan 09, 2007 3:58 am     Reply with quote

First, read my earlier reply. Note what the _minimum_ Vref is allowed to be for the chip to give it's accuracy (neither 2v, or 1v, are acceptable...). You are going to need to amplify the signal. Use something like a LMC6482 (nice little op-amp, which has 'rail to rail' inputs and outputs, running off 5v). Use a proper reference (5v supply is unlikley to really give a good reference). I'd suggest a 2.5v bandgap reference, which will met the processors Vref spec. Then multiply your input voltage by perhaps 12* with the op-amp, and you will start having something useable.

Best Wishes
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