Page 1 of 1

PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Fri Nov 20, 2020 6:53 am
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.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Fri Nov 20, 2020 12:04 pm
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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Fri Nov 20, 2020 1:36 pm
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.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Fri Nov 20, 2020 1:45 pm
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).

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Fri Nov 20, 2020 4:07 pm
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.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Fri Nov 20, 2020 4:33 pm
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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Sat Nov 21, 2020 9:13 am
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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Sun Nov 22, 2020 3:17 pm
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.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Mon Nov 23, 2020 5:28 am
by mit2003
Hi Friends,

If any other easiest option available, kindly guide us.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Mon Nov 23, 2020 8:02 am
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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Mon Nov 23, 2020 1:56 pm
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.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Mon Nov 23, 2020 7:28 pm
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?

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Tue Nov 24, 2020 8:08 am
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.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Tue Nov 24, 2020 8:43 am
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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Tue Nov 24, 2020 10:01 am
by mit2003
Hi medelec,

Really nice, you fixed the bug. Now 12-Bit ADC resolution accessed.
Great :!: :!: :!:

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Tue Nov 24, 2020 10:43 am
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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Tue Nov 24, 2020 1:18 pm
by medelec35
Hi Guys.
Thank you for the confirmation and nice words.
All appreciated.

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Fri Nov 27, 2020 5:46 pm
by Benj
Hello,

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

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Sat Nov 28, 2020 8:33 am
by AbhijitR
Hi! Ben

Thanks for the update.

Abhi

Re: PIC18F46K42 ISSUE WITH 12 BIT ADC RESULT

Posted: Thu Dec 24, 2020 6:04 am
by mit2003
Hi Benj,
Thanks a lot. Regret for delayed reply.