I'm using PIC32MZ2048EFH064, and now I'm trying to use ADC with it!
the resources about the topic are very insufficient, and I feel that the library is missing a lot of parts!
like for example, how to change the ADC resolution from the library! my PIC32 supports 12bit and the library stick to 10bits.
that's not even the problem, my PIC32 have 8 ADC modules on the datasheet, but the library only supports ADC1! and whenever I type ADC2, for example, it gives an error.
I tried reading ADC with ADC1 by setting the number of Analog channel I have like "AN5" which is connected to module #0, but it gave a fixed value 0X0FFF!
can you please give an example about the ADC, or direct me to solve the issue by MikroC.
I know I can solve this issue referring to the original registers! but what's the use of MikroC if so!
Here is the code I used for ADC:
Code: Select all
unsigned int adcValue;
unsigned char adcBytes[2];
void main() {
UART1_Init(115200);
U1RXR |= 0x0002;
RPF5R |= 0x0001;
TRISB.B10 = 1; //AN5 Pin
ANSELB.ANSB10 = 1;
ADC1_Init(); //[here if I type ADC0_Init() it gives error]
while(1)
{
adcValue = ADC1_Read(AN5); //[tried also //adcValue = ADC1_Get_Sample(AN5);]
adcBytes[0] = adcValue>>8;
adcBytes[1] = adcValue;
UART1_Write(adcBytes[0]);
UART1_Write(adcBytes[1]);
}
}