View previous topic :: View next topic |
Author |
Message |
lboghy
Joined: 04 Jun 2008 Posts: 23
|
fvrbuffer1 error reading |
Posted: Tue Sep 06, 2011 11:10 pm |
|
|
Hello
I'm using a pic16f1939 and I want to read the internal voltage reference using adc but always adresh and adresl is 00.
Can someone help me?
Code: |
FVREN = 1; ADFVR1 = 0; ADFVR0 = 1;
CHS4 = CHS3 = CHS2 = CHS1 = CHS0 = 1;
while (!FVRRDY);
ADON = 1;
delay_us(100);
GODO = 1;
while (GODO);
internal_voltage = (ADRESH<<2) + ADRESL;
FVREN = 0; ADFVR1 = 0; ADFVR0 = 0;
ADON = 0;
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Wed Sep 07, 2011 5:20 am |
|
|
I scanned the datasheet as I don't use that PIC and....
According to the ADC section of the datasheet(chapter 15...), selecting ADC channel 31 and then doing an ADC conversion should read the FVR pin...providing you've already got the FVR registers configured for 'output' mode.
You don't show complete code and there are errors.
The basic code will be about 30 lines of code to configure the PIC, the FVR, ADC, read ADC and display, sending result to PC terminal program. |
|
|
lboghy
Joined: 04 Jun 2008 Posts: 23
|
SOLVED |
Posted: Wed Sep 07, 2011 10:52 am |
|
|
Dear Temtronic,
Yes, I did not put the entire code.
Meanwhile I found the mistake.
I did not made the correct assignation. Now is working.
If some one wants to read the internal reference here is the code and is working fine. Hope that will help some one.
#include <16F1939.H>
#BYTE ADRESL = 0X09B
#BYTE ADRESH = 0X09C
#BYTE FVRCON = 0X117
#BIT FVREN = FVRCON.7
#BIT FVRRDY = FVRCON.6
#BIT ADFVR1 = FVRCON.1 // 0 for 1.024V internal~
#BIT ADFVR0 = FVRCON.0 // 1 ~voltage reference
#BYTE ADCON0 = 0X09D
#BIT CHS4 = ADCON0.6
#BIT CHS3 = ADCON0.5
#BIT CHS2 = ADCON0.4
#BIT CHS1 = ADCON0.3
#BIT CHS0 = ADCON0.2
#BIT GODO = ADCON0.1
#BIT ADON = ADCON0.0
#BYTE ADCON1 = 0X09E
#BIT ADFM = ADCON1.7
#BIT ADNREF = ADCON1.2
#BIT ADPREF1 = ADCON1.1
#BIT ADPREF0 = ADCON1.0
u16 internal_voltage;
void read_internal_voltage(void)
{
u16 local_val;
FVREN = 1;
ADFVR1 = 0; ADFVR0 = 1;
while (!FVRRDY);
ADON = 1;
ADFM = 1;
CHS4 = 1;CHS3 = 1; CHS2 = 1; CHS1 = 1; CHS0 = 1;
delay_cycles(4);
GODO = 1;
while(GODO);
ADON = 0;
local_val = ADRESH;
internal_voltage = local_val<<8;
internal_voltage += ADRESL;
FVREN = 0; ADFVR1 = 0; ADFVR0 = 0;
//ADFM = 0;
CHS4 = 0;CHS3 = 0; CHS2 = 1; CHS1 = 1; CHS0 = 1;
}
void main()
{
setup_adc(ADC_CLOCK_DIV_2); //clock is 4.0MHz
while(1)
{
read_internal_voltage();
printf ("adc: %Lu", internal_voltage);
delay_ms(500);
}
} |
|
|
|