[Resolved] BUG 16F1824 External Vref+ not working.
Moderator: Benj
-
- 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.
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
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
-
- 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.
Looks like bits 0 & 1 of not being assigned correctly.
I can get it working by modifying PIC_CAL_ADC.c
to:
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:
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
Then external Vref is used on all ADC components even if VDD is selected.
So had to use if so only ADC component that has Vref+ will use external Vref.
Code: Select all
ADCON1: A/D CONTROL REGISTER 1
I can get it working by modifying PIC_CAL_ADC.c
to:
Code: Select all
if (Vref = 1){ //assign VREF functionality
ADCON1 = ADCON1 | 0x02;
}
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; }
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)
So had to use if
Code: Select all
(Vref != 0)
Martin
- 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.
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
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
which will set Vref to 1 and always be true, should be (but I'm guessing you know already!)...if (Vref = 1)
Code: Select all
if (Vref == 1)
- Attachments
-
- PIC_CAL_ADC.c
- (105.08 KiB) Downloaded 233 times
-
- 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.
Hi Leigh,
Thanks for the update.
All three selections are working like a charm.
Thank you.
Martin
Thanks for the update.
All three selections are working like a charm.
Ah yes I was assigning rather than comparing.LeighM wrote:ps. btw, some of your problems are down to that "easy to do in C" typo
Thank you.
Martin
Martin
-
- 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.
Hi Both!
This new cal file, is this for FC 6 and FC7 Please
Br
Jorgen
This new cal file, is this for FC 6 and FC7 Please
Br
Jorgen
-
- 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.
Hi Jorgen,
So I have attached an unofficial V6 version that's copied from LeighM Fix.
Martin
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).jgu1 wrote:This new cal file, is this for FC 6 and FC7 Please
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
-
- Posts: 1333
- Joined: Tue Oct 06, 2009 9:39 am
- Has thanked: 1135 times
- Been thanked: 299 times
- Contact:
-
- 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.
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
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
-
- 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.
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
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
-
- 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.
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
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
-
- 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.
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
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
-
- 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.
Hi Jorgen,
At the time of writing, the following only applies to:
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 within FVR can be
Martin
At the time of writing, the following only applies to:
Code: Select all
12F1822, 16F1823, 16F1824, 16F1825, 16F1828, 16F1829
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
Code: Select all
PIC_CAL_ADC.c
Code: Select all
1.024V, 2.048V & 4.096V
Martin
-
- 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.
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.
Best regard Jorgen
Again thank´s for your great and big explanation. I will order a 16F18xx (have no in my stock) and make a test.
Best regard Jorgen
-
- 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.
No Problem.
18f1825 for example are cheap chips with loads of rom and functions.
By the way a small typo.
i posted
The resolution for Int.
Now corrected text.
18f1825 for example are cheap chips with loads of rom and functions.
By the way a small typo.
i posted
When it should of statedmedelec35 wrote:The resolution for Byte (10 bit)
The resolution for Int.
Now corrected text.
Martin