PIC12F1572 ADC problem (SOLVED)

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Lagoda
Posts: 152
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 66 times
Been thanked: 60 times
Contact:

PIC12F1572 ADC problem (SOLVED)

Postby Lagoda » Wed Sep 13, 2017 8:27 pm

Hi All,

I would like to use ADC and UART modul of PIC12F1572.
The problem is that +Vref pin of ADC and Rx pin of UART are same pins and I can not setup Alternate pin function in Flowcode7.
The +Vref pin is not active.

Can I get some help?

Best Regards,

Lagoda
Attachments
ADC_test_with_2.5Vref.fcfx
(10.14 KiB) Downloaded 73 times
8_pin allocation table.jpg
8_pin allocation table.jpg (143.54 KiB) Viewed 2833 times
Last edited by Lagoda on Thu Sep 14, 2017 7:34 pm, edited 1 time in total.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8600
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2469 times
Been thanked: 3557 times
Contact:

Re: PIC12F1572 ADC problem

Postby medelec35 » Thu Sep 14, 2017 1:09 am

Hi Lagoda,
To set-up alternative pins, first look at the datasheet on page 101:
Alternative pins.png
Alternative pins.png (62.87 KiB) Viewed 2829 times

See which pin you want to change the function of.
E.g TX which is what your currently using (not RX) from pin RA0 to RA4
Work out the required value = 4 as it's bit 2.
Add the following C code at the start of your flowchart:

Code: Select all

APFCON = APFCON | 4;

If you want to change both RX and TX = bits 2 and 7 = 4 + 128 = 132
Add the following C code at the start of your flowchart(witin same block as OSCCON will be suffice):

Code: Select all

APFCON = APFCON | 132;
etc.
Also, you don't want to sendChar as when the AD value is 32 then you are sending a space and not the number 32.
You should use SendNumber instead.
You may also want a space between numbers.
What I do is after sending a number I use

Code: Select all

SendChar 13
and

Code: Select all

SendChar 10

That makes each number appear on a new line

Martin
These users thanked the author medelec35 for the post (total 3):
kersing (Thu Sep 14, 2017 6:53 am) • Benj (Thu Sep 14, 2017 9:09 am) • Lagoda (Thu Sep 14, 2017 10:01 am)
Rating: 15%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

Lagoda
Posts: 152
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 66 times
Been thanked: 60 times
Contact:

Re: PIC12F1572 ADC problem

Postby Lagoda » Thu Sep 14, 2017 10:01 am

Hi Martin,

Thank you for your advices.

I modified the flowchart.
The Rx function of the UART is on the RA5 now.

But the "Vref+" pin is inactive, the ADC working with VDD reference. :(

Do you have any idea?
Best regards,

Lagoda
Attachments
ADC_test_with_2.5Vref_v2.fcfx
(10.16 KiB) Downloaded 81 times

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: PIC12F1572 ADC problem

Postby Benj » Thu Sep 14, 2017 10:54 am

Hi Lagoda,

I think I have found the problem. Please can you try copying the attached file into your "Flowcode 7/FCD/PIC" folder.

12F1572.fcdx
(16.23 KiB) Downloaded 90 times


Restart Flowcode and load your project and check that the ADC component properties are still set to Vref+, it might have changed thanks to the FCD changes.

Hopefully this should now work for you.

You can check by looking at the generated C code around line 629.

Code: Select all

    FC_CAL_ADC_Enable(3, 3, 1, 40);


If all has worked correctly then the 1 should now be a 2.

Let us know how you get on.
These users thanked the author Benj for the post (total 2):
medelec35 (Thu Sep 14, 2017 11:34 am) • Lagoda (Thu Sep 14, 2017 11:40 am)
Rating: 10%
 

Lagoda
Posts: 152
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 66 times
Been thanked: 60 times
Contact:

Re: PIC12F1572 ADC problem

Postby Lagoda » Thu Sep 14, 2017 11:55 am

Hi Ben,

Thank you for your help.

Unfortunately, the problem remains.

If i set the reference VDD then in the line 626 is: FC_CAL_ADC_Enable(3, 3, 0, 40);
If i set the reference Vref+ then in the line 626 is: FC_CAL_ADC_Enable(3, 3, 1, 40);

Best Regards,

Lagoda

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: PIC12F1572 ADC problem

Postby Benj » Thu Sep 14, 2017 1:00 pm

Thanks for letting us know. I accidentally changed the settings in the DAC instead of the ADC.

Here is the corrected definition file.

12F1572.fcdx
(16.39 KiB) Downloaded 109 times
These users thanked the author Benj for the post:
Lagoda (Thu Sep 14, 2017 1:32 pm)
Rating: 5%
 

Lagoda
Posts: 152
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 66 times
Been thanked: 60 times
Contact:

Re: PIC12F1572 ADC problem

Postby Lagoda » Thu Sep 14, 2017 1:31 pm

And it works well !!! :D

Thank you very much!

Lagoda
These users thanked the author Lagoda for the post:
Benj (Thu Sep 14, 2017 1:32 pm)
Rating: 5%