View previous topic :: View next topic |
Author |
Message |
Sensor
Joined: 04 Nov 2004 Posts: 33
|
Vref problem on 16F628A |
Posted: Mon Aug 21, 2006 5:08 pm |
|
|
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
|
|
Posted: Mon Aug 21, 2006 6:25 pm |
|
|
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
|
|
Posted: Mon Aug 21, 2006 9:06 pm |
|
|
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
|
|
Posted: Thu Aug 24, 2006 1:51 pm |
|
|
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
|
$0.02 |
Posted: Thu Aug 24, 2006 2:31 pm |
|
|
$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. |
|
|
|