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

PIC16F720 FVR not working with ADC

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



Joined: 27 Jun 2013
Posts: 22

View user's profile Send private message

PIC16F720 FVR not working with ADC
PostPosted: Fri Aug 09, 2013 1:51 pm     Reply with quote

Hello all,

I am using PIC16F720 for a project and I am not being able to use the Fixed voltage reference (FVR) or the PIC chip for reading the adc channels.

Below is the code:
Code:

#include <16F720.h>                               //The chip we are using
#use delay(clock=8000000)                         //set clock speed to 8Mhz

#use fast_io(A)                                     
#use fast_io(B)                       
#use fast_io(C)

#FUSES INTRC_IO,PLLEN,NOWDT,NOPUT,MCLR,PROTECT,NODEBUG
#byte  FVRCON     =  0x9D             

void main(void)
{
   disable_interrupts(GLOBAL);
   FVRCON = 0xC2;
   
   set_tris_a(0xFF);         
   set_tris_b(0xFF);   
   set_tris_c(0xFF);   

   setup_adc_ports(sAN5,VSS_FVR);
   setup_adc( ADC_CLOCK_INTERNAL);   
   
   while(true)
   {
         set_adc_channel(5);
      read_adc();
      printf("%u ", read_adc());
      delay_ms(500);
   }
}


According to my understanding and reading multiple examples online, my code should enable the fixed voltage reference using the FVRCON register.
I have set appropriate bits high and set the reference at 2.048V.

Then I have set the adc channel 5 (AN5 or Pin C1) as analog and the voltage range from VSS to FVR.

I am feeding 1 volt into the adc channel 5.
Based on my understanding the ADC value reading should not change as long as the input is constant at 1V and the main PIC chip VDD is between 2.5 to 5 volts.
But, the ADC value keeps changing when I increase and decrease the main VDD to PIC. It seems like it is still referencing VDD as its higher voltage range and thus the 1 volt input adc value changes with the VDD change.

Am I missing something else on the code.
I have worked on it all day and cant seem to get it working.

Any help will be highly appreciated.

The compiler version I have is PCWH 4.129

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 2:17 pm     Reply with quote

Start by using setup_vref, instead of writing to fvrcon.

setup_vref(VREF_2v048);

Your setting is trying to write a '1' to a read only bit. Probably not the problem, but shouldn't be done....

Then sequence to read the ADC, is always
1) Select channel.
2) wait Tacq
3) read channel.

You are not pausing at any point between selecting the channel and reading the adc....

The include file talks for a long time about the optional second argument, but on most compilers, it works better to OR the values together.

So:
setup_adc_ports(sAN5|VSS_FVR);

Worth trying this instead.

Best Wishes
picprogrammer12345



Joined: 27 Jun 2013
Posts: 22

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 2:22 pm     Reply with quote

Tried it with
setup_vref(VREF_2v048);

and also tried it with both
setup_vref(VREF_2v048);
FVRCOn = 0xC2;

Also gave delay of 500ms after setting the channel.

No change. ADC value still changing when VDD is changed between 2.3 and 5 volts
picprogrammer12345



Joined: 27 Jun 2013
Posts: 22

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 2:23 pm     Reply with quote

FYI also tried it with
sAN5|VSS_FVR
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Fri Aug 09, 2013 2:34 pm     Reply with quote

Study bit 7 of FVRCON. This is a read only bit.

I'd suspect your compiler has problems with this chip it was fairly new when this was supplied.

Best Wishes
Grkan13



Joined: 06 Apr 2011
Posts: 14

View user's profile Send private message

PostPosted: Tue Sep 24, 2013 1:14 pm     Reply with quote

Hello,

I have the same problem with 16f721. Did you able to find a solution for that?

Thanks.

edit: compiler version 5.012
picprogrammer12345



Joined: 27 Jun 2013
Posts: 22

View user's profile Send private message

PostPosted: Tue Sep 24, 2013 1:22 pm     Reply with quote

Yes,
I contacted ccs and they said that the function VSS_FVR is been placed by mistake in the .h file. PIC16F720 is incapable of setting fixed Vdd as FVR for the ADC pins.

It cannot be done on this chip.
Grkan13



Joined: 06 Apr 2011
Posts: 14

View user's profile Send private message

PostPosted: Wed Sep 25, 2013 8:55 am     Reply with quote

Thank you picprogrammer12345
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