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
ADC Vref hardware setting
Moderator: Benj
-
- 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
Nobody? I should add that when I reset the component property to use Vdd as ref all works as intended.
Jan
Jan
-
- 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
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
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
-
- 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
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
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
-
- 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
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel