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

About the VREF+ and VREF-

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



Joined: 05 May 2009
Posts: 5

View user's profile Send private message

About the VREF+ and VREF-
PostPosted: Fri Jun 19, 2009 3:16 pm     Reply with quote

hi all,
I have a problem with CCS, when I need specify a reference voltage to the ADC in a PIC16F877A, for a value different of 0V and 5V (vref- and vref+, respectivelly).
If you could show me a schema, I thanks a lot.

Translation:
Quote:

Hello to all,
I have a problem with CCS to specify the A/D voltage reference.
There exists the method of setup_adc_ports() where the parameter
passed to it is AN0_VREF_VREF.
In the case of setup_adc_ports(AN0_VREF_VREF):
In accordance with the header file of the PIC, it says to me that with
AN0_VREF_VREF, the reading will be in pin RA0, with RA2 being VREF-
and RA3 being VREF+, but this is not what happens. I feed RA2 and RA3
with 0.7 and 2.7 Volts respectively, but the reference voltage continues
being 0V and 5V. If somebody has already worked with a voltage
reference for the PIC and will be able to give me a tip, I will be thankful
to you. There follows an attachment of my test circuit .


Olá a todos,
Estou com um probleminha no CCS quando preciso especificar uma tesão de referência para o AD diferente de 0V a 5V .

existe um método setup_adc_ports( );

onde o parâmetro passado para ele é AN0_VREF_VREF, no caso

setup_adc_ports(AN0_VREF_VREF );

De acordo com o arquivo cabeçalho do PIC, AN0_VREF_VREF me diz que a leitura será no pino RA0, com RA2 sendo VREF- e RA3 sendo VREF+, mas não é isso que acontece. Eu alimento RA2 e RA3 com 0.7 e 2.7 Volts respectivamente, mas a tensão de referência continua sendo 0V e 5V.


Se alguém já estiver trabalhado com uma tensão de referência diferente da do PIC e puder me dar uma dica agradeço.

segue anexado o esquema do meu circuito de teste.
gilavar



Joined: 03 Mar 2009
Posts: 24

View user's profile Send private message

Re: About the VREF+ and VREF-
PostPosted: Fri Jun 19, 2009 3:27 pm     Reply with quote

This what i used in my application for analog inputs 5 and 6.
Code:

setup_adc_ports(sAN5 | sAN6 | sAN11, VREF_VREF);
      setup_adc(ADC_CLOCK_DIV_4);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 19, 2009 3:30 pm     Reply with quote

He's using a 16F877A. It doesn't use the "sANx" style of constants.
gilavar



Joined: 03 Mar 2009
Posts: 24

View user's profile Send private message

PostPosted: Fri Jun 19, 2009 3:52 pm     Reply with quote

PCM programmer wrote:
He's using a 16F877A. It doesn't use the "sANx" style of constants.

Ooops,

(AN0_VREF_VREF) Does not look right, isn't it? Embarassed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 19, 2009 5:04 pm     Reply with quote

I created the Vref voltages with a voltage divider made from 3 resistors,
and I connected it to the PIC as shown below.
Code:

        2.2K           2.0K        820 ohms
+5v ---/\/\/\/---o---/\/\/\/---o---/\/\/\/--- Ground
                 |             |               
                 |             |
                2.8v          0.8v
             To pin RA3     To pin RA2
               Vref+          Vref-


I have a 5K trimpot connected to pin A0 to provide the input analog
voltage. If I set the trimpot to 2.82v, I get this output from the program
below. (The compiler is doing the A/D conversions in 8-bit mode).
Quote:
254
254
254
254
254


If I set the voltage on pin A0 to 0.83 volts, I get the following output:
Quote:

1
2
2
1
1
1
1

Those readings are correct, for the given Vref circuit. This was tested
with vs. 4.093 of the compiler, on a PicDem2-Plus board.

Here is the test program:
Code:

#include <16F877A.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

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

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

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

}
Guest








about the solution
PostPosted: Sat Jun 20, 2009 8:06 am     Reply with quote

thanks, I'm using the Proteus 7.4 to simulate the circuit. Then, I print the voltage values on LCD 16X2. I'll try to use your example and come back to show the results.
Thanks.
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