P32MZ2048EFH064 ADC

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Post Reply
Author
Message
mkrumov
Posts: 16
Joined: 26 Jun 2011 22:27

P32MZ2048EFH064 ADC

#1 Post by mkrumov » 08 Jan 2021 10:15

Hi,

I use P32MZ2048EFH064 and would like to read analog input AN48 and AN49, but thay are on ADC3 and ADC4.
Do you have any example how I can do this?

Regards,
Mario Krumov

mkrumov
Posts: 16
Joined: 26 Jun 2011 22:27

Re: P32MZ2048EFH064 ADC

#2 Post by mkrumov » 08 Jan 2021 17:39

Hi,
I found s solution, it work for me.
Here is it:

Code: Select all

ADC1_Init_Advanced(_ADC_REF_AVDD_AVSS);           //_ADC_VREFH_EXTERNAL_VREFL_INTERNAL
ADCCON3.VREFSEL0 = 1;
ADCCON3.VREFSEL1 = 0;
ADCCON3.VREFSEL2 = 0;

// Configure ADCFLTR1
ADCFLTR1.AFEN = 0;
ADCFLTR2.AFEN = 0;
ADCFLTR3.AFEN = 0;
ADCFLTR4.AFEN = 0;
ADCFLTR5.AFEN = 0;
ADCFLTR6.AFEN = 0;

ADC3TIMEbits.ADCDIV = 2; // ADC3 clock frequency is half of control clock = TAD0 [Tad=Tq/4 (20ns/50MHz)]
    ADC3TIMEbits.SAMC = 3; // ADC3 sampling time = 5 * TAD3 [Tsamp=Tad*(SAMC+2)]
    ADC3TIMEbits.SELRES = 2; // ADC3 resolution is 10 bits

ADC4TIMEbits.ADCDIV = 2; // ADC4 clock frequency is half of control clock = TAD0 [Tad=Tq/4 (20ns/50MHz)]
    ADC4TIMEbits.SAMC = 3; // ADC4 sampling time = 5 * TAD4 [Tsamp=Tad*(SAMC+2)]
    ADC4TIMEbits.SELRES = 2; // ADC4 resolution is 10 bits

ADCTRGMODEbits.SH3ALT = 1; // ADC3 = AN48
    ADCTRGMODEbits.SH4ALT = 1; // ADC4 = AN49

ADCIMCON1bits.SIGN3 = 0; // unsigned data format
    ADCIMCON1bits.DIFF3 = 0; // Single ended mode
    ADCIMCON1bits.SIGN4 = 0; // unsigned data format
    ADCIMCON1bits.DIFF4 = 0; // Single ended mode

ADCGIRQEN1bits.AGIEN3=1;
    ADCGIRQEN1bits.AGIEN4=1;

ADCTRGSNSbits.LVL3 = 0; // Edge trigger
    ADCTRGSNSbits.LVL4 = 0; // Edge trigger

ADCTRG1bits.TRGSRC3 = 1; // Set AN3 to trigger from software.
ADCTRG2bits.TRGSRC4 = 1; // Set AN4 to trigger from software.

while(!ADCCON2bits.BGVRRDY); // Wait until the reference voltage is ready
    while(ADCCON2bits.REFFLT); // Wait if there is a fault with the reference voltage

while(!ADCANCONbits.WKRDY3); // Wait until ADC3 is ready
    while(!ADCANCONbits.WKRDY4); // Wait until ADC4 is ready

ADCCON3bits.DIGEN3 = 1; // Enable ADC3
    ADCCON3bits.DIGEN4 = 1; // Enable ADC4


while
{
    //ADC1_Get_Sample(48);
  //ADC1_Get_Sample(49);
}

Post Reply

Return to “PIC32 PRO Compilers”