ADC Vref hardware setting

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

ADC Vref hardware setting

Post 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

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC Vref hardware setting

Post by jadiflow »

Nobody? I should add that when I reset the component property to use Vdd as ref all works as intended.

Jan

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: ADC Vref hardware setting

Post 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
Attachments
PIC_CAL_ADC.c
(89.73 KiB) Downloaded 601 times
Martin

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC Vref hardware setting

Post 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

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC Vref hardware setting

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: ADC Vref hardware setting

Post 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.

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: ADC Vref hardware setting

Post by jadiflow »

Clear.

Thanks,

Jan

Post Reply