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 support@ccsinfo.com

FVR setup_vref() does not work

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



Joined: 26 Sep 2020
Posts: 51

View user's profile Send private message

FVR setup_vref() does not work
PostPosted: Fri Mar 05, 2021 1:40 pm     Reply with quote

Hello!
PIC16F1705 does not work the function of setting the reference voltage for the ADC. I tried as a source of reference voltage VDD or Vref, with them the ADC works great. But I need an VRF. How do I fix this problem?
Version 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 05, 2021 2:36 pm     Reply with quote

Post the lines of code that you're using to setup the ADC.
dmitrboristuk



Joined: 26 Sep 2020
Posts: 51

View user's profile Send private message

PostPosted: Fri Mar 05, 2021 2:48 pm     Reply with quote

Code:

setup_vref ( VREF_ON | VREF_ADC_4v096 |
             VREF_COMP_DAC_2v048 |
             TEMPERATURE_INDICATOR_DISABLED );

SETUP_ADC_PORTS( sAN6  )          // ะก2
setup_adc_reference(VSS_VREF);
setup_adc(ADC_CLOCK_INTERNAL);   
set_adc_channel( 6 );
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Mar 05, 2021 10:27 pm     Reply with quote

Look again at the .h file.

The FVR is called FVR, not VREF. You are currently setting up the ADC to
use the external VREF, not the FVR.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 06, 2021 12:01 am     Reply with quote

Here is a test program that demonstrates what Ttelmah is saying.
I was testing this in hardware and it works.
Code:
#include <16F1705.h>
#device ADC=10
#use delay(internal=4M)

#pin_select TX1=PIN_C4
#pin_select RX1=PIN_C5
#use rs232(UART1, baud=9600, ERRORS)

//===================================
void main()
{
int16 adc_result;

setup_vref ( VREF_ON | VREF_ADC_4v096 |
             VREF_COMP_DAC_OFF |
            TEMPERATURE_INDICATOR_DISABLED );

setup_adc_ports(sAN6);
setup_adc_reference(VSS_FVR);
setup_adc(ADC_CLOCK_DIV_4);
set_adc_channel(6);   // PIN_C2
delay_us(5);

while(TRUE)
  {
   adc_result = read_adc();
   printf("%lu \n\r", adc_result);
   delay_ms(1000);
  }
}
dmitrboristuk



Joined: 26 Sep 2020
Posts: 51

View user's profile Send private message

PostPosted: Sat Mar 06, 2021 12:06 am     Reply with quote

This function does not turn on the FVR for any value of the argument. Moreover, the voltage from the FVR does not come to the comparator either.
You can somehow enable FVR using assembler commands
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 06, 2021 2:14 am     Reply with quote

dmitrboristuk wrote:

This function does not turn on the FVR for any value of the argument.

What do you mean by "this function" ? Do you mean this one:
Code:
setup_adc_reference(VSS_FVR);

The line above produces this .LST file:
Quote:
....... setup_adc_reference(VSS_FVR);
00AC: MOVLB 01
00AD: BSF 1E.0 // ADCON1.0 = 1
00AE: BSF 1E.1 // ADCON1.1 = 1
00AF: BCF 1E.2 // ADCON1.2 = 0

The 16F1705 data sheet shows this is the correct setting to use the FVR:
Quote:

1-0 ADPREF<1:0>: ADC Positive Voltage Reference Configuration bits
11 = VREF+ is connected to internal FVR_buffer1(1)
10 = VREF+ is connected to external VREF+ pin(1)
01 = Reserved
00 = VREF+ is connected to VDD
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Mar 06, 2021 2:31 am     Reply with quote

Yes, it does.

It does not go to the comparator, VREF_COMP_DAC_OFF says to not send
it there.
However as posted, I've checked the listing, and this:
setup_adc_reference(VSS_FVR);
turns on the Vref set to *4, and sends this to the ADC.
As PCM also says, the ADC setup selects this.

You do realise that the Vref output cannot be above the supply, and in fact
needs about 0.6v headroom in the supply voltage to work.

I checked with your compiler version.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Mar 06, 2021 6:30 am     Reply with quote

As Mr. T points out there are 'specs' for it !
What we don't know is what voltage you're running the PIC on ?
That PIC is good for both 3 and 5 v operation but....
you can't have it run at 3 volt and expect the ADC to read 5 volts !

Jay
dmitrboristuk



Joined: 26 Sep 2020
Posts: 51

View user's profile Send private message

PostPosted: Sun Mar 07, 2021 1:29 pm     Reply with quote

Is it possible to somehow disrupt the operation mode of the FVR by incorrectly setting the fuse bits?
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 07, 2021 4:28 pm     Reply with quote

I don't see how a 'fuse' could affect the FVR but.......
hmm, it'd be a good idea to post your current, complete program.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Mar 08, 2021 2:24 am     Reply with quote

Agreed on seeing some demo code.

Though there are no fuses that affect the FVR, there are things that
could make it look as if it was not working. For example your original
ADC clock (INTERNAL) will make the ADC results inaccurate. Then things
like not allowing sufficient Tacq between selecting a channel and reading,
could also lead to erratic results.
The compiler generated code does correctly enable the FVR on this chip.
You need to give us a chance to see what 'else' is wrong.
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