ADC Component change ref voltage

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

ADC Component change ref voltage

Post by Steve001 »

Afternoon all

using a PIC16F18875 and I want to change the internal ref voltage to 1.024 volts

http://www.matrixtsl.com/wikiv7/index.p ... a0dd265bce

I am not 100% sure on how to change this, don't fully under stand the wiki

If someone could advise

Steve
Attachments
ADC TEST.fcfx
(10.92 KiB) Downloaded 337 times
Capture.JPG
Capture.JPG (26.77 KiB) Viewed 17961 times
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by Benj »

Hi Steve,

Change the VRefOption to FVR.
Change the VRefVoltage to 102.

Then use the following C code to configure the FVR peripheral.

Code: Select all

FVRCON = 0x81;
Hopefully that should be all that is required.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Cheers Ben

Will have a go later and get back to you

Steve
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Afternoon

trying to get analogue input working, reading not making any sense at all

Connected LM35CAZto port E0

http://uk.farnell.com/texas-instruments ... st=9494529

test program reading not stable what so ever 0.000031 - 1.015899 voltage on scope 256mv which is probably correct for temperature in room

not 100 % sure if I have analogue port settings correct

if someone can advise

Steve

:edit

the plot thickens :?

1) tried the example file from the wiki - "Reading a sample as a Voltage" changed target device to PIC16F18875 and 4 x 16 display - example didn't work read rubbish

2) exact same example and setup - target device ECIO40P - working correctly

changed back to test 1

measured voltage with scope on chip input pin - correct

changed analogue inputs to different pin - not working (AN32 - RE0)

so is the problem with my device setup or is there something else a miss ?
Attachments
analougue test.fcfx
(10.75 KiB) Downloaded 315 times
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve,
Steve001 wrote: test program reading not stable what so ever 0.000031 - 1.015899 voltage on scope 256mv which is probably correct for temperature in room

not 100 % sure if I have analogue port settings correct
To me that sounds like the port is floating so wrong pin is being read or there is a bug with ADC.
What chip pin number have you connected the analogue signal to?
Benj wrote: Then use the following C code to configure the FVR peripheral.

Code: Select all

FVRCON = 0x81;
I would have thought since this is set within

Code: Select all

PIC_CAL_ADC.c
then adding C code code block with

Code: Select all

FVRCON = 0x81;
would not work?

Steve,
Have you read this thread?

In your case you will need to search for

Code: Select all

TYPE_34
instead of

Code: Select all

TYPE_26
Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Hi Martin

I am using port E0 (pin8) - i have checked the pin voltage is correct with my scope

I was looking at that post this afternoon, wasn't too confident in looking into that or fiddling with the code.

I will sit down tomorrow and have a go through it when i have a clear head :lol:

Steve

:edit

I also checked by using the example file in the wiki AN0, AN1, AN32 using standard analogue port settings - readings meaning less
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve,
This is a long shot.
Can you connect the voltage to be measured to Pin 2 (AN0) and see what the Display reads?

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Hi Martin,

I checked by using the example file in the wiki AN0, AN1, AN32 using standard analogue port settings - readings meaning less

Steve
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve, I was suspecting registers not being assigned with correct values?
There is a way to find out.
You could read the registers then send value to LCD.
Would you know how to do that?

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Hi Martin
To be honest I don't have a clue :(
If you can help me out with that one please

Steve
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Sure,
I will put something together tomorrow for you.

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Thank you :D

Steve
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve,
Don't know if the attached file will help?
It will display the register name and below will display the register value in binary which makes it easier to compare with the data sheet.

Martin
Attachments
analougue test 2.fcfx
(22.05 KiB) Downloaded 270 times
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Hi Martin

Connected my LM35 to E0 - measured 233.1mv on scope

cannot make end or tail of this :(

I let it run for 4 passes and got different results

Looking at the FVRCON Register 11000001

Fixed Voltage Reference is enabled
Fixed Voltage Reference output is ready for use
Temperature Indicator is disabled
VOUT = VDD - 2VT (Low Range)
Comparator FVR Buffer is off
ADC FVR Buffer Gain is 1x, (1.024V)

or have I read this the wrong way round ? and why is ADC different values :cry: :?

looking at page 267 on data sheet

http://www.farnell.com/datasheets/22452 ... 1501615565


Steve
Attachments
test results.xlsx
(10.29 KiB) Downloaded 195 times
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve,
From your results it looks like ADCON0 is either not being assigned correctly or it's being cleared within PIC_CAL_ADC.c
On further investigation its the latter.
In order to view ADCON0 SFR:
Can you make a back up copy of PIC_CAL_ADC.c in

Code: Select all

C:\Program Files (x86)\Flowcode 7\CAL\PIC\PIC_CAL_ADC.c
if 64 bit windows
or

Code: Select all

C:\Program Files\Flowcode 7\CAL\PIC\PIC_CAL_ADC.c
if 32 bit windows.
Then replace original with attached version, which will be for diagnostics only.

Martin
Attachments
PIC_CAL_ADC.c
(117.19 KiB) Downloaded 212 times
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

cheers martin will have a go tonight

do I reprogram device with new file and re run ?

Steve
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve,
Steve001 wrote:do I reprogram device with new file and re run ?
Yes or else there will be no difference in your results.
I'm interested in what the new ADCON0 results are.

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Doh ... had a blonde moment then sorry ... :oops:
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

here you go martin

measured 233.1mv on scope

Steve
Attachments
test2 results.xlsx
(10.31 KiB) Downloaded 180 times
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve,
I have noticed some confusion with the datasheet;
It shows on page 344:
ADC Conversion.png
(95.65 KiB) Downloaded 10822 times
Which shows to use ADCON0 for analogue channel selection.
Yet further down the datasheet it shows:
ADC Channel selection.png
(87.54 KiB) Downloaded 10822 times
Can you change one of the registers in the flowchart to

Code: Select all

ADPCH
and recompile.
Don't forget to refresh flowchart before compiling.
From the results, we could get further.

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Hi Martin

do you want me to use the original cal file or your modified one ?

I was reading that data sheet too last night but not as far down as that page, I did notice something that FVR is on port AN1 ???? I was getting confused at this point also too

I will have another go tonight

Steve
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

Hi Steve,
Steve001 wrote:do you want me to use the original cal file or your modified one ?
Nothing requires changing on cal file:
medelec35 wrote:Can you change one of the registers in the flowchart to
CODE: SELECT ALL
ADPCH
and recompile.
There are two different ways.
1) Go in to a switch branch of flowchart.
Change a name of both C code and calculation box to desired register.
E.g change

Code: Select all

FCV_REGISTER_VALUE=ADCON1;
&

Code: Select all

RegisterName = "ADCON1"
to

Code: Select all

FCV_REGISTER_VALUE=ADPCH;
&

Code: Select all

RegisterName = "ADPCH"
Or
2) Add an additional Switch from the flowchart symbols and double click on it.
Change the default

Code: Select all

0
to

Code: Select all

Count
In

Code: Select all

Cases:
change

Code: Select all

1
to

Code: Select all

11
Copy any of the two icons e.g

Code: Select all

FCV_REGISTER_VALUE=ADCON1;
&

Code: Select all

RegisterName = "ADCON1"
Paste in the

Code: Select all

11
branch of the new switch icon.
Just change the the register names of both icons so you have:

Code: Select all

FCV_REGISTER_VALUE=ADPCH;
&

Code: Select all

RegisterName = "ADPCH"
for branch 11.
Finally cut the

Code: Select all

Count = 0
from branch 10 and paste in the new branch 11.

Recompile flowchart.

Martin
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

cheers martin will have a go tonight all been well

Steve
Success always occurs in private and failure in full view.

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 Component change ref voltage

Post by medelec35 »

No problem.
One thing.
Can you make sure the ADC channel being used within flowchart and hardware is not An0.

Cheers
Martin

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times
Contact:

Re: ADC Component change ref voltage

Post by Steve001 »

Hi Martin

i get the following error when I compile now

Launching the compiler...
C:\Program Files (x86)\Flowcode 7\compilers\pic\bin\xc8.exe --chip=16F18875 "analougue test 2.01.c" --MSGDISABLE=359,1273,1388
Microchip MPLAB XC8 C Compiler (Free Mode) V1.41
Build date: Jan 24 2017
Part Support Version: 1.41
Copyright (C) 2017 Microchip Technology Inc.
License type: Node Configuration

analougue test 2.01.c: main()
1245: FCV_REGISTER_ADPCH;
^ (192) undefined identifier "FCV_REGISTER_ADPCH"
(908) exit status = 1
(908) exit status = 1

C:\Program Files (x86)\Flowcode 7\compilers\pic\bin\xc8.exe reported error code 1



FINISHED

have I done something stupid :oops: cannot see anything

input connected to E0 - pin 8 still (AN32)

Steve
Attachments
analougue test 2.01.fcfx
(22.04 KiB) Downloaded 215 times
Success always occurs in private and failure in full view.

Post Reply