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 CCS Technical Support

Vref problem on 16F628A

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



Joined: 04 Nov 2004
Posts: 33

View user's profile Send private message Send e-mail

Vref problem on 16F628A
PostPosted: Mon Aug 21, 2006 5:08 pm     Reply with quote

Compiler: PCWH version 3.236
PIC: PIC16F628A
Oscillator: 4 MHz
Target Voltage: 5V

I'm trying to set up the comparator as follows:
Code:

   setup_comparator(A0_A2_A1_A2_OUT_ON_A3_A4);
   setup_vref(VREF_LOW|8|VREF_A2);


This should put 2.5V on the vref pin, RA2. However, when I probe pin 1, RA2, I do not get 2.5V. From looking at other posts in the forum it seems that there are a lot of problems with the internal vref. Should I just set up the vref as follows:

Code:

   setup_comparator(A0_A2_A1_A2_OUT_ON_A3_A4);
   setup_vref(FALSE|VREF_A2);


And then put an external 2.5V on pin 2 as my reference. This way I am not using the internal voltage reference but supplying my own.

Can someone explain why the internal Vref does not work as expected?
Guest








PostPosted: Mon Aug 21, 2006 6:25 pm     Reply with quote

Hi,

The Voltage Reference module in the PIC16F628A is not automatically connected to RA2. Rather, the TRISA<2> bit, and the VROE bit of the VRCON register must be set. This information is contained in section 11.5 of the PIC16F628A datasheet. If the compiler isn't doing it for you, you may have to do it yourself manually.

PCB
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 21, 2006 9:06 pm     Reply with quote

I compiled the following test program with PCM vs. 3.236 and ran
it on a 16F628A on a PicDem2-Plus board. It worked. I put a
voltmeter on pin A2 of the PIC, and every time I pressed the Enter
key, the voltage went up by 0.21 volts, stopping at 3.15v. That fits
the equation given in the data sheet.

Code:
#include <16F628A.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)

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

setup_comparator(A0_A2_A1_A2_OUT_ON_A3_A4);

for(i = 0; i < 16; i++)
   {
    setup_vref(VREF_LOW | i | VREF_A2);
    getc();
   }

while(1);   
}   

Note:
In order to connect the 16F628A's UART receiver to the MAX232A chip
on the PicDem2-Plus board, I jumpered pins B1 and C7 together in the
port i/o jumper area.
Sensor



Joined: 04 Nov 2004
Posts: 33

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 24, 2006 1:51 pm     Reply with quote

I figured out the problem, my Vdd was only getting to around 4.7V. That is why the vref voltage was never where it was suppose to be. I used a similar program to the one you posted and I fixed the Vdd problem and everything works great. Thanks for the help.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

$0.02
PostPosted: Thu Aug 24, 2006 2:31 pm     Reply with quote

$0.02 suggestion

Ideally, you would measure the Vcc and adjust the on-chip voltage reference. If you have a spare A/D input pin, you can use the following trick. Connect an external voltage reference (Zener diode) to an analog input and measure it with an A/D with respect to the Vcc. [spam] the Vcc goes down, the measurement of the Zener reference, whose voltage is constant, goes up. So, you can measure the Vcc on the fly.
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