PIC12F1572 ADC problem (SOLVED)

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

Moderator: Benj

Post Reply
Lagoda
Posts: 170
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 69 times
Been thanked: 61 times
Contact:

PIC12F1572 ADC problem (SOLVED)

Post by Lagoda »

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 265 times
8_pin allocation table.jpg
8_pin allocation table.jpg (143.54 KiB) Viewed 5506 times
Last edited by Lagoda on Thu Sep 14, 2017 7:34 pm, edited 1 time in total.

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

Re: PIC12F1572 ADC problem

Post by medelec35 »

Hi Lagoda,
To set-up alternative pins, first look at the datasheet on page 101:
Alternative pins.png
(62.86 KiB) Downloaded 2947 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
Martin

Lagoda
Posts: 170
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 69 times
Been thanked: 61 times
Contact:

Re: PIC12F1572 ADC problem

Post by Lagoda »

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 253 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: PIC12F1572 ADC problem

Post by Benj »

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 237 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.

Lagoda
Posts: 170
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 69 times
Been thanked: 61 times
Contact:

Re: PIC12F1572 ADC problem

Post by Lagoda »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PIC12F1572 ADC problem

Post by Benj »

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 275 times

Lagoda
Posts: 170
Joined: Fri Jul 15, 2016 9:51 pm
Has thanked: 69 times
Been thanked: 61 times
Contact:

Re: PIC12F1572 ADC problem

Post by Lagoda »

And it works well !!! :D

Thank you very much!

Lagoda

Post Reply