PIC32MZ ADC (garbage data)

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
KriszAime
Posts: 24
Joined: 31 Oct 2017 15:38

PIC32MZ ADC (garbage data)

#1 Post by KriszAime » 29 May 2019 21:42

Hi!

I would like to use ADC1 in my PIC32MZ1024ECG.
This is my source code:

Code: Select all

void main() {

	//ANS 
	ANSELF.RF0 = 0; //digi
	ANSELF.RF1 = 0; //digi

	ANSELE.RE8 = 1; //analog (AN25)

	//TRIS
	TRISF.RF0 = 1;
	TRISF.RF1 = 0;

	TRISE.RE8 = 1; //an input

	//Uart settings
	Unlock_IOLOCK();

	PPS_Mapping_NoLock(_RPF0, _OUTPUT, _U1TX); //Uart1(RPF0 - U1TX)
	PPS_Mapping_NoLock(_RPF1, _INPUT, _U1RX); //Uart1(RPF1 - U1RX)

	Lock_IOLOCK();

	//end

	//inits
	ADC1_Init();
	UART1_Init(115200);
	delay_ms(100);

	while (1)
	{
		if (UART1_Data_Ready())
		{
			char a[230];
			if (UART1_Read() == 'k')
			{
				//unsigned int i = (unsigned int)ADC1_Read(25);
				sprintf(a, "%u\r\n", ADC1_Read(25));
				UART1_Write_Text(a);
			}

		}
	}

	return;
}
The Uart workd fine, but i get Garbage data, or we could say that the value changes even if the analog value is unchanged. for example, once '63' and then '3065' then '1536' then '0' then '576' etc ..

The value returned should represent the measured value, not random values.

Maybe I missed something?

marcus
Posts: 101
Joined: 12 Sep 2006 08:58

Re: PIC32MZ ADC (garbage data)

#2 Post by marcus » 31 May 2019 07:17

The ADC on the PIC32MZ EC is broken. Use the EF instead

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: PIC32MZ ADC (garbage data)

#3 Post by jovana.medakovic » 31 May 2019 15:13

Hello,

Thank you @marcus for the answer.

@KriszAime
Unfortunately, @marcus is right.
In the attachment, you can find an example for PIC32MZ2048EFH144.
Also, there you can find .emcl file which you have to put in the folder where your compiler is installed on the path:
\Mikroelektronika\mikroC PRO for PIC32\Uses

Kind regards,
Jovana
Attachments
ADC_PIC32MZ2048EFH144.zip
(396.6 KiB) Downloaded 103 times

Post Reply

Return to “mikroC PRO for PIC32 General”