Analog input not working on PIC32MZ EFx Device

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Analog input not working on PIC32MZ EFx Device

Post by stefan.erni »

Hi Ben

In the PIC32MZ EF device are a lot of AD converter. The bad thing is if I read AN0,AN1,AN2 I have on all the tree converter just the signal from AN0

I had a look in the PIC32BIT_CAL_ADC.c and for me looks like there is a wrong line.

iRetVal = ADCDATA0;// but the PIC32MZ EF has ADCDATA0 to ADCDATA44 for the AD result

Is this the problem ? Or is there a command to set the all the result to ADCDATA0 ?

Code: Select all

	MX_UINT16 FC_CAL_ADC_Sample (MX_UINT8 Sample_Mode)
	{
		MX_UINT16 iRetVal;

		/* Wait the conversions to complete */
		while (ADCDSTAT1bits.ARDY0 == 0);

		/* fetch the result */
		iRetVal = ADCDATA0;

         /* fetch the result */
		if (Sample_Mode)
		{
			iRetVal = ADCDATA0;
		}
		else
			iRetVal = ADCDATA0 >> 4;							//8-bit ADC

		delay_us(1);											//Required or processor locks up using Raw functions

		return (iRetVal);
	}

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: Analog input not working on PIC32MZ EFx Device

Post by Benj »

Hello,

The chip has multiple analogue pins and multiple analogue to digital converters. Currently we only support converter channel 0 but this should work with any of the analogue pins.

We specify the analogue pin here.

ADCCON3bits.ADINSEL = Channel; //Select ADC Channel

It does however look like we might not be toggling the ANSEL bit correctly. Which device specifically are you using and I'll focus on that to try and get things correct for you.

You can test if it's an ANSEL problem by setting the pins that are used as analogue inputs using a C icon before you do the ADC sample. for example here is setting bits B0, B1, B2.

Code: Select all

ANSELBbits.ANSB0 = 1;
ANSELBbits.ANSB1 = 1;
ANSELBbits.ANSB2 = 1;

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ EFx Device

Post by stefan.erni »

Hi Ben

The PIC is an PIC32MZ2048EFH100.

I think
AN0 - AN4 are connected to ADC0...ADC4
AN5 - AN44 are connected to ADC7
there is no ADC5 or ADC6
and I'm not sure if all the result can go to ADCDATA0

I wrote a c code for the ADC0...ADC4 converter and it's working for (AN0...AN4)
but the for AN5 ...AN44 not yet (ADC7)

It's looks not so easy..




Yes I will test if it's an adinsel problem and give you a feedback.


AD0-andAD7.PNG
AD0-andAD7.PNG (90.93 KiB) Viewed 2462 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: Analog input not working on PIC32MZ EFx Device

Post by Benj »

Hello,

Yes that block diagram is very confusing but I beleive it is showing the ADC trigger pins and reference pins not the ADC input pins. ADC0 should be able to connect to all ADC input pins and then the result will go into the ADCDATA0 register.

Let me know regarding the ANSEL.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times
Contact:

Re: Analog input not working on PIC32MZ EFx Device

Post by stefan.erni »

Hi Ben

You are right. It's possible to use the AN Input on an ADCDATA register.
but...
Not all AN are possible and it's not ADCDATA0 it's ADCDATA7.

I trie to explain..

The Pic has 49 AN Pin (Analog Pin) and 6 ADC (Analog Digital Converter)

ADC0...ADC4 are fix for AN0...AN4 with an alternate AN Input (microchip call it Class1)
The command is to choose the alternate input:
ADCTRGMODEbits.SH0ALT = 0; // ADC0 = AN0
ADCTRGMODEbits.SH0ALT = 1; // ADC0 = AN45

ADC5 and ADC6 don't exist

ADC7 can be used for AN5...AN44 (microchip call it Class2)
The command is to choose the AN input:
ADCCON3bits.ADINSEL = 22; // working for AN22 on ADCDATA7 !!!!
ADCCON3bits.SAMP = 1;

Microchip wrote also about Class3 but
there is a problem with some register what are not avaible.
• ADCTRG4: ADC Trigger Source 4 Register
• ADCTRG5: ADC Trigger Source 5 Register
• ADCTRG6: ADC Trigger Source 6 Register

This register ADCTRG6 controls the trigger source selection for AN20 through AN23 analog inputs.
But this register are not avaible in the actual Pic32.h. I found it just in the attached pdf.

And additional there is a problem in the config.
Each PIC32 has an own calibration for the AD Converter saved in the hardware.
In the manual it's wroten this line enable the AD Converter, but it's working even the line is not included.

ADC0CFG = DEVADC0; // give an error
I suspect, this is the same problem that I already had with reading the serial number from the PIC32.
If the PIC32 is programmed with FC8, the serial number can no longer be read.


I hope it will help a litle to use AD Converter on this PIC32MZ EFx Serie

regards

Stefan
60001344D.pdf
(915.82 KiB) Downloaded 157 times

Post Reply