[Resolved] BUG 16F1824 External Vref+ not working.

A forums to allow bugs and problems with Flowcode v7 to be reported and resolved.

Moderator: Benj

Post Reply
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:

[Resolved] BUG 16F1824 External Vref+ not working.

Post by medelec35 »

Attached is a very basic flowchart to test external Vref+
If using EB006 then connect:
POT (AN3) to A6
Vref (A1)Voltage to B6
LCD Port C (C0 to C5)
All working as expected with FC5 and below
Not working with FC6 and FC7

Martin
Attachments
16F1825 Vref Test_v7.fcfx
(8.18 KiB) Downloaded 215 times
16F1825 Vref Test.fcf
(9 KiB) Downloaded 241 times
Martin

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: BUG 16F1824 External Vref+ not working.

Post by medelec35 »

Looks like bits 0 & 1 of

Code: Select all

ADCON1: A/D CONTROL REGISTER 1 
not being assigned correctly.

I can get it working by modifying PIC_CAL_ADC.c
to:

Code: Select all

if (Vref = 1){											//assign VREF functionality
			ADCON1 = ADCON1 |  0x02;
    }	
But that does not sort out FVR
I'm guessing Vref = 1 is the value of selection?
So if Vref = 1 then external Vref is selected.
Vref = 0 then internal Vref is selected.
Vref = 2 then FVR is selected?
I could be totally wrong?

So this will probably not work:

Code: Select all

if (Vref = 1){											//assign VREF functionality
			ADCON1 = ADCON1 |  0x02;					          //Select Vref+
		}
		else
		if (Vref = 2){											//assign VREF functionality
			ADCON1 = ADCON1 | (Vref & 0x03);			//Mod to allow FVR as VREF
			FVRCON=FVRCON | 0xC1; }
Out of curiosity, how can I modify what code does depending on selection?
For example if VDD do a, or Vref+ do b or FVR is selected do c etc.
As it does nor appear to be Vref = 0, Vref = 1 or Vref = 2.

Martin

Edit: Going down the wrong lines since if use

Code: Select all

if (Vref = 1)
Then external Vref is used on all ADC components even if VDD is selected.
So had to use if

Code: Select all

 (Vref != 0)
so only ADC component that has Vref+ will use external Vref.
Martin

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: BUG 16F1824 External Vref+ not working.

Post by LeighM »

Hi Martin,
Thanks for your work on this, please try the attached.
Thanks,
Leigh

ps. btw, some of your problems are down to that "easy to do in C" typo
if (Vref = 1)
which will set Vref to 1 and always be true, should be (but I'm guessing you know already!)...

Code: Select all

if (Vref == 1)
Attachments
PIC_CAL_ADC.c
(105.08 KiB) Downloaded 233 times

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: BUG 16F1824 External Vref+ not working.

Post by medelec35 »

Hi Leigh,
Thanks for the update.
All three selections are working like a charm.
LeighM wrote:ps. btw, some of your problems are down to that "easy to do in C" typo
Ah yes I was assigning rather than comparing.

Thank you.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: BUG 16F1824 External Vref+ not working.

Post by jgu1 »

Hi Both!

This new cal file, is this for FC 6 and FC7 :?: Please

Br

Jorgen

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: BUG 16F1824 External Vref+ not working.

Post by medelec35 »

Hi Jorgen,
jgu1 wrote:This new cal file, is this for FC 6 and FC7 Please
No it can't be for both V6 and V7 since V6 uses Boost C compiler (uses lower case register names) and V7 uses XC8 compiler (uses upper case register names).
So I have attached an unofficial V6 version that's copied from LeighM Fix.

Martin
Attachments
PIC_CAL_ADC.c
(99.05 KiB) Downloaded 241 times
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: BUG 16F1824 External Vref+ not working.

Post by jgu1 »

Thank you Martin :D

Jorgen

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: BUG 16F1824 External Vref+ not working.

Post by medelec35 »

Your welcome Jorgen.
I did say based but have changed it to copied as it was just a direct copy of Leighs code.
So Leigh should have all the credit for that one.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: [Resolved] BUG 16F1824 External Vref+ not working.

Post by jgu1 »

Hi Martin!

I have played a little with your example with Vref. In test (simulation) before and after update. I see the same result before and after update. Maybe it only work in real world.

I see when I turn the pot from 0 to max. in display 0 - 1023 ok Int. But as I understand by using the Vref. in your example "Vref 250 Then I should see in the display 1023 when the pot is half "speed" (ajd. to 2.5V) but it is still 1023 by max after. Hope you understand my question. Or do I misunderstand concerning the use of Vref.

Br

Jorgen

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: [Resolved] BUG 16F1824 External Vref+ not working.

Post by medelec35 »

Hi Jorgen,
You will only see a difference with hardware, but you are getting the concept correct.
If you look at the datasheeet for 16F1825 you will see that ADCON1 register controls ADPREF (Analogue to Digital Positive REFerence voltage) bit.
On page 149 shows a switch controlled by ADPREF.
As its internal to 16F1825 the simulator won't show the difference between VDD and +REF unless you are using GetVoltage or GetString.
In those cases the VREF+ within properties will take effect.
If using VREF+ then you need to set a fixed voltage at the VREF+ pin by using two resistors as and example.
So VREF+ may not be +2.5V if two resistors are not identical values.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: [Resolved] BUG 16F1824 External Vref+ not working.

Post by jgu1 »

Hi Martin!

Thank you for your explanation, Then I understand it correct. I Will test it in Real " world " this weekend. I have never used Vref before.

Thank's

Br Jorgen

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: [Resolved] BUG 16F1824 External Vref+ not working.

Post by medelec35 »

Hi Jorgen,
At the time of writing, the following only applies to:

Code: Select all

12F1822, 16F1823, 16F1824, 16F1825, 16F1828, 16F1829
You have three Vref options to choose from:
VDD - This uses the microcontroller supply voltage as a reference.
The resolution for Byte (8 bit) = 5/256 = 19.53mV (so for every increase in voltage by 19.53mV, ADC value increases by 1)
The resolution for Int (10 bit) = 5/1024 = 4.88mV

VRef+ - This uses the microcontroller external pin for the voltage reference.
So if two resistors connected set the voltage on external pin to 2.5V.
The resolution for Byte (8 bit) = 2.5/256 = 9.77mV
The resolution for Int (10 bit) = 2.5/1024 = 2.44mV

FVR (Fixed Reference Voltage).
This uses an accurate internal voltage.
The default for Flowcode has set this voltage to 1.024V
The resolution for Byte (8 bit) = 1.024/256 = 4mV
The resolution for Int (10 bit) = 1.024/1024 = 1mV
It's the 1mV resolution which makes this setting very useful indeed!
For Example see this post.
Note: By changing values of

Code: Select all

FVRCON
within

Code: Select all

PIC_CAL_ADC.c
FVR can be

Code: Select all

1.024V, 2.048V & 4.096V
Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: [Resolved] BUG 16F1824 External Vref+ not working.

Post by jgu1 »

Hi again Martin!

Again thank´s for your great and big explanation. I will order a 16F18xx (have no in my stock) and make a test. :D

Best regard Jorgen

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: [Resolved] BUG 16F1824 External Vref+ not working.

Post by medelec35 »

No Problem.
18f1825 for example are cheap chips with loads of rom and functions.

By the way a small typo.
i posted
medelec35 wrote:The resolution for Byte (10 bit)
When it should of stated
The resolution for Int.
Now corrected text.
Martin

Post Reply