Page 1 of 1

ADC Vref hardware setting

Posted: Tue Dec 08, 2015 4:12 pm
by jadiflow
I searched the forums and though several users had this issue I didn't see a solution for this.

I want to use the Vref input pin for the ADC reference (16PIC886).

I set the Component properties for the ADC to +Vref.
I assume I also need to set up the appropriate input ports, so right after the macro call to RAW_configure the ADC I place an asm block:

asm
{
bsf _adcon1,5 //PCFG1
bsf _adcon1,4 //PCFG0
bsf _trisa,2 //adc ref-
bsf _trisa,3 //adc ref+
bsf _ansel,2 //analog in ref-
bsf _ansel,3 //analog in ref+
}

However, the ADC output is erratic indicating that the Vref isn't read from the pin (which is at 4.096V with Vcc being 5V).
What did I overlook?

Jan

Re: ADC Vref hardware setting

Posted: Thu Dec 10, 2015 1:09 pm
by jadiflow
Nobody? I should add that when I reset the component property to use Vdd as ref all works as intended.

Jan

Re: ADC Vref hardware setting

Posted: Sat Dec 12, 2015 1:33 am
by medelec35
Hi Jan,
I have just looked into why enabling Vref+ within ADC properties (Right click ADC component on the panel and click Ext properties & change Vref option) is not working.
I have found a bug with PIC_CAL_ADC.c

If you make a backup copy and replace:
PIC_CAL_ADC.c that's in:
C:\Program Files (x86)\Flowcode\v5\CAL\PIC\ (If 64 bit windows)
or
C:\Program Files\Flowcode\v5\CAL\PIC(If 32 bit windows.)
With the attached file, then hopefully ADC should read correct with pin5 connected to a fixed voltage.
No C code is required and you can choose any ADC channel.

Tested with 16F883

Martin

Re: ADC Vref hardware setting

Posted: Tue Jan 26, 2016 2:42 pm
by jadiflow
Martin, thank you! I cannot test it right now but will and report if there are other issues - but I trust this will fix it!

Jan
medelec35 wrote:Hi Jan,
I have just looked into why enabling Vref+ within ADC properties (Right click ADC component on the panel and click Ext properties & change Vref option) is not working.
I have found a bug with PIC_CAL_ADC.c

If you make a backup copy and replace:
PIC_CAL_ADC.c that's in:
C:\Program Files (x86)\Flowcode\v5\CAL\PIC\ (If 64 bit windows)
or
C:\Program Files\Flowcode\v5\CAL\PIC(If 32 bit windows.)
With the attached file, then hopefully ADC should read correct with pin5 connected to a fixed voltage.
No C code is required and you can choose any ADC channel.

Tested with 16F883

Martin

Re: ADC Vref hardware setting

Posted: Mon Apr 11, 2016 1:26 pm
by jadiflow
Better late than never - just got around to checking whether the Vref for the ADC works - and it indeed does, thanks again Martin!

But as is often the case, one answer brings up another question.
In the ADC dialog box there is a field where you can set the Vref voltage per 10mV chunks; for a 5V ref you would set that at 500.
I played with that setting (I am using a 4.096V ref) but it doesn't seem to make any difference in the application.
Is this only for the simulation runs?

Jan

Re: ADC Vref hardware setting

Posted: Mon Apr 11, 2016 1:34 pm
by Benj
Hi Jan,

The VRef Voltage Property effects the ReadAsVoltage and ReadAsString macros where you get a voltage out rather than a direct numeric ADC reading. Should work for both sim and download.

Re: ADC Vref hardware setting

Posted: Thu Apr 14, 2016 2:18 pm
by jadiflow
Clear.

Thanks,

Jan