Problem with the PIC16F648 ADC

Moderator: Benj

Post Reply
User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Problem with the PIC16F648 ADC

Post by Osta »

The high-case ADC "ADRESH"is not read.
Previously, everything worked and now it doesn't .
When using macros (Flowcode) everything works but the program
remains in interrupts while the ADC is running and this is 100-200 uS
lose time . You can return for the result in interrupts.
Please make an ADC interrupt macro!!!
Sincerely, Osta.
File attached
Attachments
IMG
IMG
ADC.jpg (58.57 KiB) Viewed 6711 times
ADC.fcfx
prog
(26.18 KiB) Downloaded 186 times

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: Problem with the PIC16F648 ADC

Post by Benj »

Hello,

I thinkt he problem was your interrupt enable code. You were using bit names such as GO = 1 whereas this should have been ADCON0bits.GO = 1

I've made some changes to your program inside the interrupt enable icon, hopefully it will improve things for you.

Also I've noticed your if statement had been converted to C with customised code to add a { after the decision. This should not be required but i've left as is as it doesn't seem to be causing issues in the generated code.
ADC.fcfx
(26.24 KiB) Downloaded 178 times

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Hi Benj!
It doesn't change anything...
My version of the program works
only if I read lowercase,
I attached a photo below.
Sincerely Osta
Attachments
Oscil
Oscil
ADC.jpg (248.2 KiB) Viewed 6694 times
ADRESL
ADRESL
ADRESL.jpg (62.62 KiB) Viewed 6694 times

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Hi Benj!
I apologize for making a typo.
I use the PIC16F684 controller

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Hi Benj!
Your recommendation doesn't work!
As before, the senior level is not readable.
Only the lower-level ADC is read.
Above is a picture of the lowercase operation
What to do?

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: Problem with the PIC16F648 ADC

Post by Benj »

Hi Osta,

You have set the ADC to be Right justified which means that the majority of the ADC result will reside in the ADRESL register (ADFM = 1).

Code: Select all

ADCON0 = 137;   // Настройка АЦПа
Justify.jpg
Justify.jpg (23.33 KiB) Viewed 6658 times
Maybe this should instead be (ADFM = 0).

Code: Select all

ADCON0 = 9;   // Настройка АЦПа

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Рш Benj
That's right, I need to move to the right.
otherwise, I will have to do an extra operation-shift the entire result by 6 bits
When the ADC is shifted to the right, it is 768
the first two bits must be used in upper case.
Attachments
ADRESH
ADRESH
ADRESH.jpg (62.04 KiB) Viewed 6655 times

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

The macro does this.
And I need to start the ADC and get out of interrupts as soon as possible.
Go back for the result, change the channel and exit again. This is a cycle that takes less time
, measurements run in parallel and there is no reason to wait for the result in interrupts.
Attachments
Code snippet
Code snippet
Безымянный.jpg (87.9 KiB) Viewed 6651 times

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: Problem with the PIC16F648 ADC

Post by LeighM »

Maybe try taking out the code that swaps ADC channel on every sample.
Just try sampling one channel to begin with and see if that works.

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Hi LeighM
The macro works fine!
I can't count the upper case
when shifting to the right .

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: Problem with the PIC16F648 ADC

Post by LeighM »

I just wondered if you were getting low value readings due to too short A/D acquisition time

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Thanks, I'll check it out.

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Does not work...

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: Problem with the PIC16F648 ADC

Post by LeighM »

Try a slower conversion clock in ADCON1 ?

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Hi LeighM
I did all three options the result is the same.
Attachments
ADCON1
ADCON1
ADCON1.jpg (86.03 KiB) Viewed 6617 times

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

This is the same solution implemented in Flowcode 6
and it works.
I did the same in Flowcode 7.
Attachments
FC6
FC6
FC6.jpg (53.64 KiB) Viewed 6614 times

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: Problem with the PIC16F648 ADC

Post by LeighM »

Does your Flowcode 7 program work?
If so, could you post it?

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

Hi LeighM
I still have the old FC6 file and the new FC8 file
in FC7 it is lost but I installed FC7 yesterday and tried IT
it doesn't work either.

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: Problem with the PIC16F648 ADC

Post by LeighM »

OK,
I've just noticed that ADRESH and ADRESL are in different memory banks, I wonder if this is a silicon/compiler issue :?

User avatar
Osta
Posts: 159
Joined: Tue Jul 05, 2016 9:42 am
Been thanked: 13 times
Contact:

Re: Problem with the PIC16F648 ADC

Post by Osta »

That may be so.
Well, if you can take that into account.
I can't change the controller
this is an old project, and I can
rely only on the software solution
and this version of the program.
Thanks for the help.
With respect Osta.

Post Reply