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

fvrbuffer1 error reading

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



Joined: 04 Jun 2008
Posts: 23

View user's profile Send private message

fvrbuffer1 error reading
PostPosted: Tue Sep 06, 2011 11:10 pm     Reply with quote

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: 9240
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Sep 07, 2011 5:20 am     Reply with quote

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

View user's profile Send private message

SOLVED
PostPosted: Wed Sep 07, 2011 10:52 am     Reply with quote

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);
}


}
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