Page 1 of 1

Problem with the PIC16F648 ADC

Posted: Sun Mar 01, 2020 1:25 pm
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

Re: Problem with the PIC16F648 ADC

Posted: Mon Mar 02, 2020 10:55 am
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 315 times

Re: Problem with the PIC16F648 ADC

Posted: Mon Mar 02, 2020 11:52 am
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

Re: Problem with the PIC16F648 ADC

Posted: Mon Mar 02, 2020 12:43 pm
by Osta
Hi Benj!
I apologize for making a typo.
I use the PIC16F684 controller

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 7:33 am
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?

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 11:56 am
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 8646 times
Maybe this should instead be (ADFM = 0).

Code: Select all

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

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 12:15 pm
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.

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 12:43 pm
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.

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 12:55 pm
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.

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 1:08 pm
by Osta
Hi LeighM
The macro works fine!
I can't count the upper case
when shifting to the right .

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 1:18 pm
by LeighM
I just wondered if you were getting low value readings due to too short A/D acquisition time

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 1:23 pm
by Osta
Thanks, I'll check it out.

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 1:43 pm
by Osta
Does not work...

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 4:35 pm
by LeighM
Try a slower conversion clock in ADCON1 ?

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 4:53 pm
by Osta
Hi LeighM
I did all three options the result is the same.

Re: Problem with the PIC16F648 ADC

Posted: Tue Mar 03, 2020 5:13 pm
by Osta
This is the same solution implemented in Flowcode 6
and it works.
I did the same in Flowcode 7.

Re: Problem with the PIC16F648 ADC

Posted: Wed Mar 04, 2020 11:51 am
by LeighM
Does your Flowcode 7 program work?
If so, could you post it?

Re: Problem with the PIC16F648 ADC

Posted: Wed Mar 04, 2020 12:31 pm
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.

Re: Problem with the PIC16F648 ADC

Posted: Wed Mar 04, 2020 1:15 pm
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 :?

Re: Problem with the PIC16F648 ADC

Posted: Wed Mar 04, 2020 4:10 pm
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.