PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Moderator: Benj

Post Reply
mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi Friends,
Project with PIC18F46K42 ADC and UART for measuring voltage with 12 bit resolution and display result in computer virtual terminal. There is no issues during simulation (0v to 5v), compilation and program flashing.

While programed PIC18F46K42 tested, got 10 bit resolution only instead of 12 bits. (0V - 0, 5v - 1023)

Relevant images and project file attached for your reference.
Attachments
PIC18F46K42_ADC.fcfx
(10.48 KiB) Downloaded 315 times
5V_REAL.jpg
5V_REAL.jpg (11.41 KiB) Viewed 15585 times
5V.jpg
5V.jpg (123.2 KiB) Viewed 15585 times
Thank you so much :!:
B.Senthil

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by stefan.erni »

Hi B.Senthil


With different PIC, for example PIC32MZ2048efg, you can choose the AD bit resolution (8,10,12), but not with this PIC18F46K42, this has always 12 bits.

Can you control, if your potmeter is on 5volt and not on 3.3volt?


regards

Stefan

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi Stefan,

Thanks for reply.

Actually i am expecting 12bit ADC output only from PIC18F46K42.

In simulation got expected 12bit result as expected.

Practically (PIC18F46K42, PDIP 40Pins, 5V) got 10bit result only and seems to be strange.

How can i get 12bit result in practice for getting better resolution.
Thank you so much :!:
B.Senthil

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi Stefan,

Actually planned to process 15 signals. I have selected 15th signal initially for testing resolution and repeatability.

VC15: and V are strings for representation of 15th signal through UART (5V_Real.jpg).
Thank you so much :!:
B.Senthil

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi Friends,

For analyzing purpose i have introduced single line C-code 'ADC_INT[15] = (ADRESH * 256)+ ADRESL;' after ADC component and realized below factors.
Now i got 0 for 0V and 65520 for 5V.

1. PIC18F46K42 ADC component linked with 10Bit ADC calculations (That is why got 1023 for 5V)
2. Flow code processing ADC result as Left Justified Manner (That is why got 65520 for 5V)

Now i got 12Bit result. But in the form of Left Justified.

Let me try to get Right Justified result from Left Justified one.
Thank you so much :!:
B.Senthil

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by stefan.erni »

Hi B.Senthil

Thats good news. You can have a look to the ADCON0 register

regards
Stefan
36.1.6 RESULT FORMATTING
The 12-bit ADC conversion result can be supplied in
two formats, left justified or right justified. The FM bits
of the ADCON0 register controls the output format.

bit 2 FM: ADC results Format/alignment Selection
1 = ADRES and PREV data are right-justified
0 = ADRES and PREV data are left-justified, zero-filled

User avatar
AbhijitR
Posts: 300
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 283 times
Been thanked: 80 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by AbhijitR »

Hello! Stefan and B.Senthil

Thanks for this information, to be honest i ordered few PIC18F26K42 (28 pin) from same range like PIC18F46K42, hoping i would be able to use the 12bit ADC available in this chip, previously i was using PIC18F26K22, but the ADC in this chip is 10bit, unfortunately the results were not as expected so was requested to use a 12bit ADC.

After reading the information provided by Stefan and B.Senthil it seems to me that i wont be able to use the ADC function with 12bit easily, i haven't tried anything yet as the chips are still not delivered, but now feeling little :(

Is it not possible to use the 12bit ADC function easily with flow chart, unfortunately i am not aware or can say zero with "C" so did not understand the explanation well, or may be someone can help with what exactly need to do.

Thank you, hear really soon, :D

Abhi

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi Abhi,

Hear is a solution for utilizing 12-bit resolution.

1. Allow flowcode coding to initiate and finish ADC conversion (1st block in the flowcode image)
2. Create variables NEW_ADRESH & NEW_ADRESL FOR GETTING 12-BIT RESULT (variable declaration in flowcode image)
3. To access real ADC result, move ADRESH & ADRESL TO NEW_ADRESH & NEW_ADRESL (2nd block in the flowcode image)
4.Now we get left justified ADC result, which can't able to use directly.
5.create variable PROCESS_BYTE1 (for temporary data access)
6. create variable INT_ADC (storing 12-bit Right justified result)
7. create constant MUL15 (multiplication factor for calculating actual voltage) (I used float array MUL[15] for assigning multiple values)
8. create variable CV15 (For storing calculated voltage)
9.For converting left justified ADC result to right justified ADC result use 3rd & 4th blocks in the flowcode image
10.For converting right justified ADC results into Integer use 5th blocks in the flowcode image
11. To calculate voltage use 6th blocks in the flowcode image

I am sure you will utilize 12-bit ADC Result.

Note:
You can't get result while simulation. No need to worry.
Use display such as LCD / UART and display INT_ADC in real-time for ensuring 12-bit result
I have tested, working well.

Have a nice day.
Attachments
solution.jpg
solution.jpg (22.17 KiB) Viewed 15531 times
Thank you so much :!:
B.Senthil

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi Friends,

If any other easiest option available, kindly guide us.
Thank you so much :!:
B.Senthil

User avatar
AbhijitR
Posts: 300
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 283 times
Been thanked: 80 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by AbhijitR »

Hello! B.Senthil
good afternoon

Kindly excuse for the delayed reply, the beginning of the week is always very busy.

First of all, many many thanks to you for spending your time to write to me and to explain, i am obliged. To be honest with you i was little worried since i read your earlier post but now i am :D

Probably by the end of this week i hope to receive the chips, i am so eager to take the trials since i read your yesterdays post, i keep you posted.

Once again humbly, thank you for all your efforts and time, have a wonderful following day.

Abhi

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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by medelec35 »

Hi,
This evening when I get home from work,
I will see if I can post an unofficial fix to get the ADC component working.
Martin

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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by medelec35 »

Hi All,
I have an unofficial fix for you.
Note Run an update before applying fix, as the update will override the fix.

You will need to place the attached file in C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\PIC which is hidden by default.
If file was added when Flowcode was running then flowchart will require reloading.
With the attached file you will not require any C code to get the full 12 bits.
Could someone who has the PIC18F46K42 test the fix please?
Attachments
PIC_CAL_ADC.c
(149.05 KiB) Downloaded 314 times
Martin

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi medelec,

Thanks a lot for your effort and glad to see your participation in this post. I go through the forum and really impressed about efforts.
I will check and let you today evening.
Thank you so much :!:
B.Senthil

User avatar
AbhijitR
Posts: 300
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 283 times
Been thanked: 80 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by AbhijitR »

Hello! Martin
good morning

Thanks for your efforts, i am desperately waiting for the chips, hope to receive those soon and i could take the trials.

Abhi

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi medelec,

Really nice, you fixed the bug. Now 12-Bit ADC resolution accessed.
Great :!: :!: :!:
Thank you so much :!:
B.Senthil

User avatar
AbhijitR
Posts: 300
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 283 times
Been thanked: 80 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by AbhijitR »

Hi! B.Senthil
good afternoon

Many many thanks for the confirmation, cheers....

Hi! Martin

As usual you are a SAVIOUR for me, on contrary many on the forum, cheers to you too.

Abhi

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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by medelec35 »

Hi Guys.
Thank you for the confirmation and nice words.
All appreciated.
Martin

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: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by Benj »

Hello,

I've added Martins fix to the official update release today.

User avatar
AbhijitR
Posts: 300
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 283 times
Been thanked: 80 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by AbhijitR »

Hi! Ben

Thanks for the update.

Abhi

mit2003
Posts: 18
Joined: Wed Oct 14, 2020 11:37 am
Been thanked: 2 times

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Post by mit2003 »

Hi Benj,
Thanks a lot. Regret for delayed reply.
Thank you so much :!:
B.Senthil

Post Reply