• AVR Freaks

Hot!ADC interrupt not firing on PIC32MZ2048EFH100

Author
Taïga
Starting Member
  • Total Posts : 31
  • Reward points : 0
  • Joined: 2015/03/17 14:00:17
  • Location: Belgium
  • Status: offline
2018/06/17 10:51:37 (permalink)
0

ADC interrupt not firing on PIC32MZ2048EFH100

Hello,
 
I am trying to test the interrupt on data ready event of the ADC, based on the sample code of the microchip datasheet DS60001344D, page 110 to 112. I did a few adaptation ( use of 2 ADC modules only, division of the clock ).
I try to turn on a led in the ADCHandler1() to check that the interrupt is called at least once, but the LED does not turn on at all.
I may forget something, but i do not see what...
Does some expert would have some idea why the interrupt is not firing?
I compile with XC32 (v2.05).
The code is in the following.
 
Kind regards,
 
Taïga
 
 
 
/* 
 * File: main.cpp
 *
 * Test of the ADC
 *
 * Created on 17/06/2018
 */

#include <cstdlib>
#include <sys/attribs.h> // for macro __ISR( )

#include "./Microchip/ports/plib_ports.h"
#include "./Microchip/ports/processor/ports_p32mz2048efh100.h"
#include "./Microchip/devcon/plib_devcon.h"
#include "./Microchip/devcon/processor/devcon_p32mz2048efh100.h"

using namespace std;


/* Core configuration fuse settings */
#pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = OFF, PMDL1WAY = OFF, IOL1WAY = OFF, FUSBIDIO = OFF
#pragma config FNOSC = SPLL
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable bit
#pragma config IESO = ON // Internal External Switchover bit
#pragma config POSCMOD = EC // Primary Oscillator Configuration bits; must be set to EC for PIC32MZEF...
#pragma config OSCIOFNC = OFF, FCKSM = CSECME, FWDTEN = OFF, FDMTEN = OFF
#pragma config DMTINTV = WIN_127_128, WDTSPGM = STOP, WINDIS= NORMAL
#pragma config WDTPS = PS1048576, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31


// F = 252 Mhz
#pragma config FPLLIDIV = DIV_1, FPLLRNG = RANGE_21_42_MHZ, FPLLICLK = PLL_POSC
#pragma config FPLLMULT = MUL_21, FPLLODIV = DIV_2, UPLLFSEL = FREQ_12MHZ //FPLLODIV: DIV_1 does not exist.

#pragma config EJTAGBEN = NORMAL // EJTAG Boot Enable bit
#pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission bits
#pragma config FSLEEP = OFF // Flash Sleep Mode bit
#pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration bits
#pragma config BOOTISA = MIPS32 //On PIC32MZ EF devices, the CPU can operate a mode called
                                 // microMIPS. microMIPS mode is an enhanced MIPS32®
                                 // instruction set that uses both 16-bit and 32-bit opcodes. This
                                 // mode of operation reduces memory size with minimum
                                 // performance impact.
#pragma config TRCEN = OFF // Trace features in the CPU are disabled
#pragma config ICESEL = ICS_PGx2, JTAGEN = OFF, DEBUG = OFF
#pragma config CP = OFF


#pragma config_alt FWDTEN=OFF
#pragma config_alt USERID = 0x1234u



#define SYSCLK (252000000) // Frequency of the System Clock

/* Number of ADC modules doing conversion */
#define ADC_MODULES 2

/* Declare functions for each ADC handler */
void ADC0Handler(void);
void ADC1Handler(void);


void(*jumpTable[ADC_MODULES * 2])(void);

int ADC0Result;
int ADC1Result;


/**
 * Initiliazation of the leds
 */
bool initLeds(){
    
   PLIB_DEVCON_SystemUnlock(DEVCON_ID_0);
   PLIB_DEVCON_DeviceRegistersUnlock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );

   // Configure LED A
   PLIB_PORTS_PinDirectionOutputSet( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );
   PLIB_PORTS_ChangeNoticePullUpPerPortDisable( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );
   PLIB_PORTS_PinModePerPortSelect( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6, PORTS_PIN_MODE_DIGITAL );
   PLIB_PORTS_PinClear( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );

   PLIB_DEVCON_DeviceRegistersLock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );
   PLIB_DEVCON_SystemLock(DEVCON_ID_0);
}



void vHardwareConfigurePerformance( void )
{
   PLIB_DEVCON_SystemUnlock(DEVCON_ID_0);
   PLIB_DEVCON_DeviceRegistersUnlock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );

   // IMPORTANT INFO (DS60001320D-page 153): Devices that support 252 MHz
   // operation should be configured for SYSCLK <= 200 MHz operation.
   // Adjust the dividers of the PBCLKs, and then increase the SYSCLK to the
   // desired speed.
   
   
   // IMPORTANT INFO ( DS60001320D-page 701 ) the maximum PBCLK speed is limited
   // to 100 MHz for all buses, with the exception of PBCLK7, which is 200 MHz.
   
   // UART uses PBCLK2
    // Division by 3 of the SYSCLK. We cannot divide by 2, since PBCLK is
    // limited at 100 Mhz for all buses, except PBCLK7. cf. PIC32MZEF datasheet
    // doc DS60001320D-page 701
    // WARNING: it also concerns the SPI bus, impact to check!
   PB2DIVbits.PBDIV = 0b10; // 0b10 means division by 3 (cf. doc DS60001320D-page 701)

   // ADC use clock PBCLK3. TODO: define frequency of PB3CLK
   // Timer use it also
   PB3DIVbits.PBDIV = 0b10; // divide SYSCLK by 3: 252 Mhz / 3 = 84 Mhz (cf. doc DS60001320D-page 701)

 /* Ports use PBCLK4. */
 //PB4DIVbits.PBDIV = 0b000;

 //SYSKEY = 0;

   PLIB_DEVCON_DeviceRegistersLock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );
   PLIB_DEVCON_SystemLock(DEVCON_ID_0);

}



int main(int argc, char** argv) {

   initLeds();
   vHardwareConfigurePerformance();
   
 jumpTable[0] = &ADC0Handler; // Set up jump table
 jumpTable[2] = &ADC1Handler;
 
 /* Configure ADCCON1 */
 ADCCON1 = 0; // No ADCCON1 features are enabled including: Stop-in-Idle, turbo,
 // CVD mode, Fractional mode and scan trigger source.
 
 /* Configure ADCCON2 */
 ADCCON2 = 0; // Since, we are using only the Class 1 inputs, no setting is
 // required for ADCDIV
 
 /* Initialize warm up time register */
 ADCANCON = 0;
 ADCANCONbits.WKUPCLKCNT = 5; // Wakeup exponent = 32 * TADx
 
 /* Clock setting */
 ADCCON3 = 0;
 //ADCCON3bits.ADCSEL = 1; // Select SYSCLK input clock source ( DS60001320D-page 716 )
   // ADC clock shall be maximum 28 MhZ. SYSCLK is 252 Mhz
   //ADCCON3bits.CONCLKDIV = 5; // Control clock frequency is divided by 10

   ADCCON3bits.ADCSEL = 0; // Select PBCLK3 input clock source ( DS60001320D-page 716 )
   // ADC clock shall be maximum 28 MhZ. PBCLK3 is 84 Mhz
   ADCCON3bits.CONCLKDIV = 2; // Control clock frequency is divided by 4
   
 ADCCON3bits.VREFSEL = 0; // Select AVDD and AVSS as reference source
 
 /* Select ADC sample time and conversion clock */
 ADC0TIMEbits.ADCDIV = 1; // ADC0 clock frequency is half of control clock = TAD0
 ADC0TIMEbits.SAMC = 5; // ADC0 sampling time = 5 * TAD0
 ADC0TIMEbits.SELRES = 3; // ADC0 resolution is 12 bits
 ADC1TIMEbits.ADCDIV = 1; // ADC1 clock frequency is half of control clock = TAD1
 ADC1TIMEbits.SAMC = 5; // ADC1 sampling time = 5 * TAD1
 ADC1TIMEbits.SELRES = 3; // ADC1 resolution is 12 bits
 
 /* Select analog input for ADC modules, no presync trigger, not sync sampling */
 ADCTRGMODEbits.SH0ALT = 0; // ADC0 = AN0
 ADCTRGMODEbits.SH1ALT = 0; // ADC1 = AN1

 
 /* Select ADC input mode */
 ADCIMCON1bits.SIGN0 = 0; // unsigned data format
 ADCIMCON1bits.DIFF0 = 0; // Single ended mode
 ADCIMCON1bits.SIGN1 = 0; // unsigned data format
 ADCIMCON1bits.DIFF1 = 0; // Single ended mode

 
 /* Configure ADCGIRQENx */
 ADCGIRQEN1 = 0;
 ADCGIRQEN2 = 0;
 ADCGIRQEN1bits.AGIEN0 = 1; // Enable data ready interrupt for AN0
 ADCGIRQEN1bits.AGIEN1 = 1; // Enable data ready interrupt for AN1

 
 /* Configure ADBASE */
 ADCBASE = (int)(&jumpTable[0]); // Initialize ADCBASE with starting address of jump table
 ADCCON1bits.IRQVS = 0; // No left shift of address
 
 /* Configure ADCCSSx */
 ADCCSS1 = 0; // No scanning is used
 ADCCSS2 = 0;
 
 /* Configure ADCCMPCONx */
 ADCCMPCON1 = 0; // No digital comparators are used. Setting the ADCCMPCONx
 ADCCMPCON2 = 0; // register to '0' ensures that the comparator is disabled.
 ADCCMPCON3 = 0; // Other registers are “don't care”.
 ADCCMPCON4 = 0;
 ADCCMPCON5 = 0;
 ADCCMPCON6 = 0;

 /* Configure ADCFLTRx */
 ADCFLTR1 = 0; // No oversampling filters are used.
 ADCFLTR2 = 0;
 ADCFLTR3 = 0;
 ADCFLTR4 = 0;
 ADCFLTR5 = 0;
 ADCFLTR6 = 0;

 /* Set up the trigger sources */
 ADCTRGSNSbits.LVL0 = 0; // Edge trigger
 ADCTRGSNSbits.LVL1 = 0; // Edge trigger
 ADCTRG1bits.TRGSRC0 = 1; // Set AN0 to trigger from software.
 ADCTRG1bits.TRGSRC1 = 1; // Set AN1 to trigger from software.


 /* Early interrupt */
 ADCEIEN1 = 0; // No early interrupt
 ADCEIEN2 = 0;
 ADCCON2bits.ADCEIOVR = 1; // Override early interrupt
 
 /* Turn the ADC on */
 ADCCON1bits.ON = 1;
 
 /* Wait for voltage reference to be stable */
 while(!ADCCON2bits.BGVRRDY); // Wait until the reference voltage is ready
 while(ADCCON2bits.REFFLT); // Wait if there is a fault with the reference voltage
 
 /* Enable clock to analog circuit */
 ADCANCONbits.ANEN0 = 1; // Enable the clock to analog bias and digital control
 ADCANCONbits.ANEN1 = 1; // Enable the clock to analog bias and digital control

 
 /* Wait for ADC to be ready */
 while(!ADCANCONbits.WKRDY0); // Wait until ADC0 is ready
 while(!ADCANCONbits.WKRDY1); // Wait until ADC1 is ready

 
 /* Enable the ADC module */
 ADCCON3bits.DIGEN0 = 1; // Enable ADC0
 ADCCON3bits.DIGEN1 = 1; // Enable ADC1

   INTCONbits.MVEC = 1; // Enable Multi-vectored Interrupts
 
 /* Trigger a conversion */
 ADCCON3bits.GSWTRG = 1;
   

   
 while (1);
 
 return (1);
}

/* Handler for the ADC interrupt */
extern "C" { void __ISR(_ADC_VECTOR, /*ipl3*/IPL3AUTO) ADCHandler1(void)
{
// turn LED on
   LATAbits.LATA6 = 1;
   
 /* call the corresponding ADC module handler */
 ((void(*)())*((int *)ADCBASE))();
}

}

void ADC0Handler(void)
{
 /* Verify if data for AN0 is ready. This bit is self cleared upon data read */
 if(ADCDSTAT1bits.ARDY0)
 {
  ADC0Result = ADCDATA0;
 }
}

void ADC1Handler(void)
{
 /* Verify if data for AN1 is ready. This bit is self cleared upon data read */
 if(ADCDSTAT1bits.ARDY1)
 {
  ADC1Result = ADCDATA1;
 }
}





#1

11 Replies Related Threads

    maxruben
    Super Member
    • Total Posts : 3305
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/18 12:52:05 (permalink)
    0
    I can't see that you are actually setting the ADC interrupt priority to 3 anywhere.
     
    /Ruben
    #2
    Taïga
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2015/03/17 14:00:17
    • Location: Belgium
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/19 13:39:07 (permalink)
    0
    Hello Ruben,
     
    thank you for your reply.
     
    So, i added the following lines to configure the priority, but the interrupt is still not firing :
     
    /* Configure ADC interrupt priority */
    IPC11bits.ADCIP = 3;
    IPC11bits.ADCIS = 1;

     
    I hope that this is correct, since i did not find definition on ADCIP in the ADC manual, in the PIC32MZEF manual and in the interrupt manual.
     
    My code is now:
     
    /* 
     * File: main.cpp
     *
     * Test of the ADC
     *
     * Created on 16 mai 2018, 21:08
     */

    #include <cstdlib>
    #include <sys/attribs.h>
    #include <proc/p32mz2048efh100.h> // for macro __ISR( )

    #include "./Microchip/ports/plib_ports.h"
    #include "./Microchip/ports/processor/ports_p32mz2048efh100.h"
    #include "./Microchip/devcon/plib_devcon.h"
    #include "./Microchip/devcon/processor/devcon_p32mz2048efh100.h"

    using namespace std;


    /* Core configuration fuse settings */
    #pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = OFF, PMDL1WAY = OFF, IOL1WAY = OFF, FUSBIDIO = OFF
    #pragma config FNOSC = SPLL
    #pragma config FSOSCEN = OFF // Secondary Oscillator Enable bit
    #pragma config IESO = ON // Internal External Switchover bit
    #pragma config POSCMOD = EC // Primary Oscillator Configuration bits; must be set to EC for PIC32MZEF...
    #pragma config OSCIOFNC = OFF, FCKSM = CSECME, FWDTEN = OFF, FDMTEN = OFF
    #pragma config DMTINTV = WIN_127_128, WDTSPGM = STOP, WINDIS= NORMAL
    #pragma config WDTPS = PS1048576, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31


    // F = 252 Mhz
    #pragma config FPLLIDIV = DIV_1, FPLLRNG = RANGE_21_42_MHZ, FPLLICLK = PLL_POSC
    #pragma config FPLLMULT = MUL_21, FPLLODIV = DIV_2, UPLLFSEL = FREQ_12MHZ //FPLLODIV: DIV_1 does not exist.

    #pragma config EJTAGBEN = NORMAL // EJTAG Boot Enable bit
    #pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission bits
    #pragma config FSLEEP = OFF // Flash Sleep Mode bit
    #pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration bits
    #pragma config BOOTISA = MIPS32 //On PIC32MZ EF devices, the CPU can operate a mode called
                                     // microMIPS. microMIPS mode is an enhanced MIPS32®
                                     // instruction set that uses both 16-bit and 32-bit opcodes. This
                                     // mode of operation reduces memory size with minimum
                                     // performance impact.
    #pragma config TRCEN = OFF // Trace features in the CPU are disabled
    #pragma config ICESEL = ICS_PGx2, JTAGEN = OFF, DEBUG = OFF
    #pragma config CP = OFF


    #pragma config_alt FWDTEN=OFF
    #pragma config_alt USERID = 0x1234u



    #define SYSCLK (252000000) // Frequency of the System Clock

    /* Number of ADC modules doing conversion */
    #define ADC_MODULES 2

    /* Declare functions for each ADC handler */
    void ADC0Handler(void);
    void ADC1Handler(void);


    void(*jumpTable[ADC_MODULES * 2])(void);

    int ADC0Result;
    int ADC1Result;


    /**
     * Initiliazation of the leds
     */
    bool initLeds(){
        
       PLIB_DEVCON_SystemUnlock(DEVCON_ID_0);
       PLIB_DEVCON_DeviceRegistersUnlock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );

       // Configure LED A
       PLIB_PORTS_PinDirectionOutputSet( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );
       PLIB_PORTS_ChangeNoticePullUpPerPortDisable( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );
       PLIB_PORTS_PinModePerPortSelect( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6, PORTS_PIN_MODE_DIGITAL );
       PLIB_PORTS_PinClear( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );

       PLIB_DEVCON_DeviceRegistersLock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );
       PLIB_DEVCON_SystemLock(DEVCON_ID_0);
    }



    void vHardwareConfigurePerformance( void )
    {
       PLIB_DEVCON_SystemUnlock(DEVCON_ID_0);
       PLIB_DEVCON_DeviceRegistersUnlock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );

       // IMPORTANT INFO (DS60001320D-page 153): Devices that support 252 MHz
       // operation should be configured for SYSCLK <= 200 MHz operation.
       // Adjust the dividers of the PBCLKs, and then increase the SYSCLK to the
       // desired speed.
       
       
       // IMPORTANT INFO ( DS60001320D-page 701 ) the maximum PBCLK speed is limited
       // to 100 MHz for all buses, with the exception of PBCLK7, which is 200 MHz.
       
       // UART uses PBCLK2
        // Division by 3 of the SYSCLK. We cannot divide by 2, since PBCLK is
        // limited at 100 Mhz for all buses, except PBCLK7. cf. PIC32MZEF datasheet
        // doc DS60001320D-page 701
        // WARNING: it also concerns the SPI bus, impact to check!
       PB2DIVbits.PBDIV = 0b10; // 0b10 means division by 3 (cf. doc DS60001320D-page 701)

       // ADC use clock PBCLK3. TODO: define frequency of PB3CLK
       // Timer use it also
       PB3DIVbits.PBDIV = 0b10; // divide SYSCLK by 3: 252 Mhz / 3 = 84 Mhz (cf. doc DS60001320D-page 701)

     /* Ports use PBCLK4. */
     //PB4DIVbits.PBDIV = 0b000;

     //SYSKEY = 0;

       PLIB_DEVCON_DeviceRegistersLock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );
       PLIB_DEVCON_SystemLock(DEVCON_ID_0);

    }



    int main(int argc, char** argv) {

       initLeds();
       vHardwareConfigurePerformance();
       
     jumpTable[0] = &ADC0Handler; // Set up jump table
     jumpTable[2] = &ADC1Handler;
     
     /* Configure ADCCON1 */
     ADCCON1 = 0; // No ADCCON1 features are enabled including: Stop-in-Idle, turbo,
     // CVD mode, Fractional mode and scan trigger source.
     
     /* Configure ADCCON2 */
     ADCCON2 = 0; // Since, we are using only the Class 1 inputs, no setting is
     // required for ADCDIV
     
     /* Initialize warm up time register */
     ADCANCON = 0;
     ADCANCONbits.WKUPCLKCNT = 5; // Wakeup exponent = 32 * TADx
     
     /* Clock setting */
     ADCCON3 = 0;
     //ADCCON3bits.ADCSEL = 1; // Select SYSCLK input clock source ( DS60001320D-page 716 )
       // ADC clock shall be maximum 28 MhZ. SYSCLK is 252 Mhz
       //ADCCON3bits.CONCLKDIV = 5; // Control clock frequency is divided by 10

       ADCCON3bits.ADCSEL = 0; // Select PBCLK3 input clock source ( DS60001320D-page 716 )
       // ADC clock shall be maximum 28 MhZ. PBCLK3 is 84 Mhz
       ADCCON3bits.CONCLKDIV = 2; // Control clock frequency is divided by 4
       
     ADCCON3bits.VREFSEL = 0; // Select AVDD and AVSS as reference source
     
     /* Select ADC sample time and conversion clock */
     ADC0TIMEbits.ADCDIV = 1; // ADC0 clock frequency is half of control clock = TAD0
     ADC0TIMEbits.SAMC = 5; // ADC0 sampling time = 5 * TAD0
     ADC0TIMEbits.SELRES = 3; // ADC0 resolution is 12 bits
     ADC1TIMEbits.ADCDIV = 1; // ADC1 clock frequency is half of control clock = TAD1
     ADC1TIMEbits.SAMC = 5; // ADC1 sampling time = 5 * TAD1
     ADC1TIMEbits.SELRES = 3; // ADC1 resolution is 12 bits
     
     /* Select analog input for ADC modules, no presync trigger, not sync sampling */
     ADCTRGMODEbits.SH0ALT = 0; // ADC0 = AN0
     ADCTRGMODEbits.SH1ALT = 0; // ADC1 = AN1

     
     /* Select ADC input mode */
     ADCIMCON1bits.SIGN0 = 0; // unsigned data format
     ADCIMCON1bits.DIFF0 = 0; // Single ended mode
     ADCIMCON1bits.SIGN1 = 0; // unsigned data format
     ADCIMCON1bits.DIFF1 = 0; // Single ended mode

     
       /* Configure ADC interrupt priority */
       IPC11bits.ADCIP = 3;
       IPC11bits.ADCIS = 1;
          
     /* Configure ADCGIRQENx */
     ADCGIRQEN1 = 0;
     ADCGIRQEN2 = 0;
     ADCGIRQEN1bits.AGIEN0 = 1; // Enable data ready interrupt for AN0
     ADCGIRQEN1bits.AGIEN1 = 1; // Enable data ready interrupt for AN1
     
     /* Configure ADBASE */
     ADCBASE = (int)(&jumpTable[0]); // Initialize ADCBASE with starting address of jump table
     ADCCON1bits.IRQVS = 0; // No left shift of address
     
     /* Configure ADCCSSx */
     ADCCSS1 = 0; // No scanning is used
     ADCCSS2 = 0;
     
     /* Configure ADCCMPCONx */
     ADCCMPCON1 = 0; // No digital comparators are used. Setting the ADCCMPCONx
     ADCCMPCON2 = 0; // register to '0' ensures that the comparator is disabled.
     ADCCMPCON3 = 0; // Other registers are ?don't care?.
     ADCCMPCON4 = 0;
     ADCCMPCON5 = 0;
     ADCCMPCON6 = 0;

     /* Configure ADCFLTRx */
     ADCFLTR1 = 0; // No oversampling filters are used.
     ADCFLTR2 = 0;
     ADCFLTR3 = 0;
     ADCFLTR4 = 0;
     ADCFLTR5 = 0;
     ADCFLTR6 = 0;

     /* Set up the trigger sources */
     ADCTRGSNSbits.LVL0 = 0; // Edge trigger
     ADCTRGSNSbits.LVL1 = 0; // Edge trigger
     ADCTRG1bits.TRGSRC0 = 1; // Set AN0 to trigger from software.
     ADCTRG1bits.TRGSRC1 = 1; // Set AN1 to trigger from software.


     /* Early interrupt */
     ADCEIEN1 = 0; // No early interrupt
     ADCEIEN2 = 0;
     ADCCON2bits.ADCEIOVR = 1; // Override early interrupt
     
     /* Turn the ADC on */
     ADCCON1bits.ON = 1;
     
     /* Wait for voltage reference to be stable */
     while(!ADCCON2bits.BGVRRDY); // Wait until the reference voltage is ready
     while(ADCCON2bits.REFFLT); // Wait if there is a fault with the reference voltage
     
     /* Enable clock to analog circuit */
     ADCANCONbits.ANEN0 = 1; // Enable the clock to analog bias and digital control
     ADCANCONbits.ANEN1 = 1; // Enable the clock to analog bias and digital control

     
     /* Wait for ADC to be ready */
     while(!ADCANCONbits.WKRDY0); // Wait until ADC0 is ready
     while(!ADCANCONbits.WKRDY1); // Wait until ADC1 is ready

     
     /* Enable the ADC module */
     ADCCON3bits.DIGEN0 = 1; // Enable ADC0
     ADCCON3bits.DIGEN1 = 1; // Enable ADC1

       INTCONbits.MVEC = 1; // Enable Multi-vectored Interrupts
     
     /* Trigger a conversion */
     ADCCON3bits.GSWTRG = 1;
       

       //LATAbits.LATA6 = 1;
       
     while (1);
     
     return (1);
    }

    /* Handler for the ADC interrupt */
    extern "C" { void __ISR(_ADC_VECTOR, /*ipl3*/IPL3AUTO) ADCHandler1(void)
    {
       LATAbits.LATA6 = 1;
       
     /* call the corresponding ADC module handler */
     ((void(*)())*((int *)ADCBASE))();
    }

    }

    void ADC0Handler(void)
    {
     /* Verify if data for AN0 is ready. This bit is self cleared upon data read */
     if(ADCDSTAT1bits.ARDY0)
     {
      ADC0Result = ADCDATA0;
     }
    }

    void ADC1Handler(void)
    {
     /* Verify if data for AN1 is ready. This bit is self cleared upon data read */
     if(ADCDSTAT1bits.ARDY1)
     {
      ADC1Result = ADCDATA1;
     }
    }




     
     
     
     
     
     
     
    post edited by Taïga - 2018/06/19 13:40:19
    #3
    Taïga
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2015/03/17 14:00:17
    • Location: Belgium
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/21 14:02:31 (permalink)
    0
    Hello,
     
    I would like to solve the issue of the interrupt not firing during this week end.
    Does somebody has an idea on the issue, or could suggest some paths of investigation ?
     
    Kind regards,
     
    Taïga
     
    #4
    maxruben
    Super Member
    • Total Posts : 3305
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/22 05:35:50 (permalink)
    4 (1)
    Try to set the interrupt flag manually in code or by the debugger and check that this actually fires the interrupt and code ends up in the expected interrupt vector.
     
    /Ruben
    #5
    Taïga
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2015/03/17 14:00:17
    • Location: Belgium
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/24 08:26:30 (permalink)
    0
    Hello,
     
    So, at the beginning the debugger was not working, but finally the debugger issue itself is solved and i can now use the debugger (with the pickit3).
    I put some break point in the interrupt fonction ADCHandler1() and i can see that this fonction is never called.
    i tried to set the bit ADCDSTAT1bits.ARDY0 manually in the program and also with the debugger, to trigger the interrupt, but it seems impossible to set it: the value remains always at zero. Maybe is this bit protected, since it should be set by the ADC only.
    Do you see a way to force it to 1 ?
     
     
    post edited by Taïga - 2018/06/24 08:27:39
    #6
    maxruben
    Super Member
    • Total Posts : 3305
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/25 03:28:47 (permalink)
    0
    I think this method only works for IF (Interrupt Flag) bits in an interrupt register (not an ADC register).
     
    /Ruben
    #7
    Taïga
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2015/03/17 14:00:17
    • Location: Belgium
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/27 13:53:59 (permalink)
    0
    Hello,
     
    I am still blocked to get the interrupt firing.
    I can have the ADC conversion working when the interrupt is disabled and when i trigger the conversion by software and by polling the conversion to be complete :
     
    // Trigger a conversion
    ADCCON3bits.GSWTRG = 1;

    // Wait for the conversion to be complete
    while( ADCDSTAT1bits.ARDY0 == 0 );

    // Fetch the result
    result = ADCDATA0;

     
    But when i enable the interruption, the interrupt never fires.
     
    I am wondering: is there a way to check at least if the conversion process is started, right after setting ADCCON3bits.GSWTRG to 1 ? Maybe, for some reason i ignore, when the interrupt is enabled, the conversion is not starting after setting ADCCON3bits.GSWTRG to 1 ?
     
    Any suggestion is really welcome!
     
    Taïga
     
    #8
    Taïga
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2015/03/17 14:00:17
    • Location: Belgium
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2018/06/27 14:16:58 (permalink)
    0
    Curiously, when i set manually  ADCCON3bits.GSWTRG to 1 with the debugger, i can observe that after some time, ADCDSTAT1bits.ARDY0 = 1 and ADCDSTAT1bits.ARDY1 = 1.
     
    But the interrupt ADCHandler1() is not called (i put a break point in the interruption, but the debugger does not halt at this break point)...
     
    I will put my latest version of the code in the following:
     
     
    /* 
     * File: main.cpp
     *
     * Test of the ADC
     *
     * Created on 16 mai 2018, 21:08
     */

    #include <cstdlib>
    #include <sys/attribs.h>
    #include <proc/p32mz2048efh100.h> // for macro __ISR( )

    #include "./Microchip/ports/plib_ports.h"
    #include "./Microchip/ports/processor/ports_p32mz2048efh100.h"
    #include "./Microchip/devcon/plib_devcon.h"
    #include "./Microchip/devcon/processor/devcon_p32mz2048efh100.h"

    using namespace std;


    /* Core configuration fuse settings */
    #pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = OFF, PMDL1WAY = OFF, IOL1WAY = OFF, FUSBIDIO = OFF

    #pragma config FSOSCEN = OFF // Secondary Oscillator Enable bit
    #pragma config IESO = ON // Internal External Switchover bit

    #pragma config OSCIOFNC = OFF, FCKSM = CSECME, FDMTEN = OFF
    #pragma config DMTINTV = WIN_127_128, WDTSPGM = STOP, WINDIS= NORMAL
    #pragma config WDTPS = PS1048576, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31


    // Configuration of the primary oscillator clock
    // External clock is 24 MHz in the flip & click board
    // F = 252 Mhz
    #pragma config FNOSC = SPLL // Select primary oscillator as default oscillator (with System PLL)
    #pragma config POSCMOD = EC // POSC operating mode: External Clock input
    #pragma config FPLLICLK = PLL_POSC // SYSCLK is driven by the PLL & POSC
    #pragma config FPLLIDIV = DIV_1 // PLL input divider
    #pragma config FPLLRNG = RANGE_21_42_MHZ // range of frequency going into the multiplier
    #pragma config FPLLMULT = MUL_21 // PLL multiplier ratio
    #pragma config FPLLODIV = DIV_4 // temporar reduction of speed for interrupt ADC issue //DIV_2 : for 252 Mhz // PLL output divider : DIV_1 does not exist.
    #pragma config UPLLFSEL = FREQ_12MHZ // USB PLL (not used yet)


    #pragma config EJTAGBEN = NORMAL // EJTAG Boot Enable bit
    #pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission bits
    #pragma config FSLEEP = OFF // Flash Sleep Mode bit
    #pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration bits
    #pragma config BOOTISA = MIPS32 //On PIC32MZ EF devices, the CPU can operate a mode called
                                     // microMIPS. microMIPS mode is an enhanced MIPS32®
                                     // instruction set that uses both 16-bit and 32-bit opcodes. This
                                     // mode of operation reduces memory size with minimum
                                     // performance impact.
    #pragma config TRCEN = ON // Trace features in the CPU are enabled
    #pragma config ICESEL = ICS_PGx2 // OK: checked connections
    #pragma config JTAGEN = OFF // for debug
    #pragma config DEBUG = OFF // for debug, should be kept OFF...
    #pragma config CP = OFF // For debug, no code protect


    #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled)
    #pragma config USERID = 0x1234u



    #define SYSCLK (252000000) // Frequency of the System Clock

    /* Number of ADC modules doing conversion */
    #define ADC_MODULES 2

    /* Declare functions for each ADC handler */
    void ADC0Handler(void);
    void ADC1Handler(void);


    void(*jumpTable[ADC_MODULES * 2])(void);

    int ADC0Result;
    int ADC1Result;


    /**
     * Initiliazation of the leds
     */
    bool initLeds(){
        
       PLIB_DEVCON_SystemUnlock(DEVCON_ID_0);
       PLIB_DEVCON_DeviceRegistersUnlock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );

       // Configure LED A
       PLIB_PORTS_PinDirectionOutputSet( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );
       PLIB_PORTS_ChangeNoticePullUpPerPortDisable( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );
       PLIB_PORTS_PinModePerPortSelect( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6, PORTS_PIN_MODE_DIGITAL );
       PLIB_PORTS_PinClear( PORTS_ID_0, PORT_CHANNEL_A, PORTS_BIT_POS_6 );

       PLIB_DEVCON_DeviceRegistersLock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );
       PLIB_DEVCON_SystemLock(DEVCON_ID_0);
    }



    void vHardwareConfigurePerformance( void )
    {
       PLIB_DEVCON_SystemUnlock(DEVCON_ID_0);
       PLIB_DEVCON_DeviceRegistersUnlock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );

       // IMPORTANT INFO (DS60001320D-page 153): Devices that support 252 MHz
       // operation should be configured for SYSCLK <= 200 MHz operation.
       // Adjust the dividers of the PBCLKs, and then increase the SYSCLK to the
       // desired speed.
       
       
       // IMPORTANT INFO ( DS60001320D-page 701 ) the maximum PBCLK speed is limited
       // to 100 MHz for all buses, with the exception of PBCLK7, which is 200 MHz.
       
       // UART uses PBCLK2
        // Division by 3 of the SYSCLK. We cannot divide by 2, since PBCLK is
        // limited at 100 Mhz for all buses, except PBCLK7. cf. PIC32MZEF datasheet
        // doc DS60001320D-page 701
        // WARNING: it also concerns the SPI bus, impact to check!
       PB2DIVbits.PBDIV = 0b10; // 0b10 means division by 3 (cf. doc DS60001320D-page 701)

       // ADC use clock PBCLK3. TODO: define frequency of PB3CLK
       // Timer use it also
       PB3DIVbits.PBDIV = 0b10; // divide SYSCLK by 3: 252 Mhz / 3 = 84 Mhz
                                  // (cf. doc DS60001320D-page 701)

     /* Ports use PBCLK4. Not clear if the ADC is using it : its claimed on page 716 of DS60001320D */
     PB4DIVbits.PBDIV = 0b10; // divide SYSCLK by 3: 252 Mhz / 3 = 84 Mhz

       PLIB_DEVCON_DeviceRegistersLock( DEVCON_ID_0, DEVCON_PPS_REGISTERS );
       PLIB_DEVCON_SystemLock(DEVCON_ID_0);

    }



    /**
     * Configuration of the ADC without interrupt
     */
     void initADC()
     {
       // AN0 on RB0
       PLIB_PORTS_PinDirectionInputSet( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_0 );
       //PLIB_PORTS_ChangeNoticePullUpPerPortEnable( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_0 );
       PLIB_PORTS_PinModePerPortSelect( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_0, PORTS_PIN_MODE_ANALOG );
        
       // Initialize ADC calibration setting
       // Prior to enabling the ADC module, the user application must copy the ADC
       // calibration data (DEVADCx) from the Configuration memory into the ADC
       // Configuration registers (ADC0CFG-ADC7CFG)
       ADC0CFG = DEVADC0;
       ADC1CFG = DEVADC1;
       ADC2CFG = DEVADC2;
       ADC3CFG = DEVADC3;
       ADC4CFG = DEVADC4;
       //ADC5CFG = DEVADC5;
       //ADC6CFG = DEVADC6;
       ADC7CFG = DEVADC7;

       // Configure ADCCON1
       ADCCON1 = 0; // No ADCCON1 feature is enabled.
       
       // Configure ADCCON2
       ADCCON2 = 0; // Since we are using only the Class 1 inputs, no setting is
                      // required for ADCDIV
       
       // Initialize warm up time register
       ADCANCON = 0;
       //ADCANCONbits.WKUPCLKCNT = 5;
       
       // Clock settings
       ADCCON3 = 0;
       ADCCON3bits.ADCSEL = 0; // Select input clock source: 0 selects PBCLK3 (cf. figure 28-1 page 428 of DS60001320D)
       ADCCON3bits.CONCLKDIV = 1; // Control clock frequency = pb3 frequency /CONCLKDIV (1: divide by 2) TODO: adapt if necessary;
       ADCCON3bits.VREFSEL = 0; // Select AVDD and AVSS as reference source
       
     /* Clock setting */
     //ADCCON3 = 0;
     //ADCCON3bits.ADCSEL = 1; // Select SYSCLK input clock source ( DS60001320D-page 716 )
     // ADC clock shall be maximum 28 MhZ. SYSCLK is 252 Mhz
     //ADCCON3bits.CONCLKDIV = 5; // Control clock frequency is divided by 10
     //ADCCON3bits.VREFSEL = 0; // Select AVDD and AVSS as reference source
       
       
       // Select ADC sample time and conversion clock
       ADC0TIMEbits.ADCDIV = 1; // ADC0 clock frequency is half of control clock = TAD0
       ADC0TIMEbits.SAMC = 5; // ADC0 sampling time = 5 * TAD0
       ADC0TIMEbits.SELRES = 3; // ADC0 resolution is 12 bits.
       
       // Select analog input for ADC modules, no presync trigger, not sync sampling
       ADCTRGMODEbits.SH0ALT = 0; // ADC0 = An0
       
       // Select ADC input mode
       ADCIMCON1bits.SIGN0 = 0; // unsigned data format
       ADCIMCON1bits.DIFF0 = 0; // single ended mode
       
       // Configure ADCGIRQENx
       ADCGIRQEN1 = 0; // TODO clarify
       ADCGIRQEN2 = 0;
       
       // Configure ADCCSSx
       ADCCSS1 = 0; // No scanning is used
       ADCCSS2 = 0;
       
       // Configure ADCCMPCONx
       ADCCMPCON1 = 0; // No digital comparator are used. Setting the ADCCMPCONX
                                  // register to '0' ensures that the comparator is disabled.
                                  // Other registers are "don't care".
       
       // Configure ADCFLTRx
       ADCFLTR1 = 0; // No oversampling filters are used
       
       // Set up the trigger sources
       ADCTRGSNSbits.LVL0 = 0; // Edge trigger - TODO: clarify
       ADCTRG1bits.TRGSRC0 = 1; // Set AN0 to trigger from global software trigger (GSWTRG)
               
       // Early interrupt
       ADCEIEN1 = 0; // No early interrupt
       ADCCON2bits.ADCEIOVR = 1; // Override early interrupt
       
       // Turn the ADC on
       ADCCON1bits.ON = 1;
       
       // Wait for voltage reference to be stable
       while( !ADCCON2bits.BGVRRDY ); // Wait until the reference voltage is ready
       while( ADCCON2bits.REFFLT ); // Wait if there is a fault with the reference voltage
       
       // Enable clock to analog circuit
       ADCANCONbits.ANEN0 = 1; // Enable the clock to analog bias and digital control
       
       // Wait for ADC to be ready
       while( !ADCANCONbits.WKRDY0 ); // Wait until ADC0 is ready
       
       // Enable the ADC module
       ADCCON3bits.DIGEN0 = 1; // Enable ADC0
     }


     /**
      * ADC measure
      *
      * flip & click board: AN0 (pin 25) is connected to connector ANALOG-A3.
      *
      */
    void performADCmeasurement()
    {
       int result;
       
       // Trigger a conversion
       ADCCON3bits.GSWTRG = 1;
       
       // Wait for the conversion to be complete
       while( ADCDSTAT1bits.ARDY0 == 0 );
       
       // Fetch the result
       result = ADCDATA0;
       
       //printf("result: %d \n", result );
     
    }
     
     

    void configureADCwithInterrupts( void )
    {
       // AN0 on RB0
       PLIB_PORTS_PinDirectionInputSet( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_0 );
       PLIB_PORTS_PinModePerPortSelect( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_0, PORTS_PIN_MODE_ANALOG );

       // AN1 on RB1
       PLIB_PORTS_PinDirectionInputSet( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_1 );
       PLIB_PORTS_PinModePerPortSelect( PORTS_ID_0, PORT_CHANNEL_B, PORTS_BIT_POS_1, PORTS_PIN_MODE_ANALOG );
       
     jumpTable[0] = &ADC0Handler; // Set up jump table
     jumpTable[2] = &ADC1Handler;
     
     /* Configure ADCCON1 */
     ADCCON1 = 0; // No ADCCON1 features are enabled including: Stop-in-Idle, turbo,
     // CVD mode, Fractional mode and scan trigger source.

      ADCCON1bits.AICPMPEN = 0; // Charge pump disabled. TODO: clarify
     
     /* Configure ADCCON2 */
     ADCCON2 = 0; // Since, we are using only the Class 1 inputs, no setting is
                      // required for ADCDIV
     
     /* Initialize warm up time register */
     ADCANCON = 0;
     ADCANCONbits.WKUPCLKCNT = 5; // Wakeup exponent = 32 * TADx
     
     /* Clock setting */
     ADCCON3 = 0;
     ADCCON3bits.ADCSEL = 1; // Select SYSCLK input clock source ( DS60001320D-page 716 )
       // ADC clock shall be maximum 28 MhZ. SYSCLK is 252 Mhz
       ADCCON3bits.CONCLKDIV = 5; // Control clock frequency is divided by 10

       //ADCCON3bits.ADCSEL = 0; // Select PBCLK4 input clock source ( DS60001320D-page 716 )
       // ADC clock shall be maximum 28 MhZ. PBCLK3 is 84 Mhz
       //ADCCON3bits.CONCLKDIV = 2; // PBCLK4 is divided by 4 => ADC control clock
                                  // frequency is 84/4 = 21 MHz
          
       
     ADCCON3bits.VREFSEL = 0; // Select AVDD and AVSS as reference source
     
     /* Select ADC sample time and conversion clock */
     ADC0TIMEbits.ADCDIV = 1; // ADC0 clock frequency is half of ADC control clock
     ADC0TIMEbits.SAMC = 5; // ADC0 sampling time = 5 * TAD0; TODO: is it correct?

     ADC1TIMEbits.ADCDIV = 1; // ADC1 clock frequency is half of ADC control clock
     ADC1TIMEbits.SAMC = 5; // ADC1 sampling time = 5 * TAD1; TODO: is it correct?

       // Resolution of the ADC:
     ADC0TIMEbits.SELRES = 3; // ADC0 resolution is 12 bits
     ADC1TIMEbits.SELRES = 3; // ADC1 resolution is 12 bits
     
     /* Select analog input for ADC modules, no presync trigger, not sync sampling */
     ADCTRGMODEbits.SH0ALT = 0; // ADC0 = AN0
     ADCTRGMODEbits.SH1ALT = 0; // ADC1 = AN1

     
     /* Select ADC input mode */
     ADCIMCON1bits.SIGN0 = 0; // unsigned data format
     ADCIMCON1bits.DIFF0 = 0; // Single ended mode
     ADCIMCON1bits.SIGN1 = 0; // unsigned data format
     ADCIMCON1bits.DIFF1 = 0; // Single ended mode

     /* Configure ADCCSSx */
     ADCCSS1 = 0; // No scanning is used
     ADCCSS2 = 0;
     
     /* Configure ADCCMPCONx */
     ADCCMPCON1 = 0; // No digital comparators are used. Setting the ADCCMPCONx
     ADCCMPCON2 = 0; // register to '0' ensures that the comparator is disabled.
     ADCCMPCON3 = 0; // Other registers are ?don't care?.
     ADCCMPCON4 = 0;
     ADCCMPCON5 = 0;
     ADCCMPCON6 = 0;

     /* Configure ADCFLTRx */
     ADCFLTR1 = 0; // No oversampling filters are used.
     ADCFLTR2 = 0;
     ADCFLTR3 = 0;
     ADCFLTR4 = 0;
     ADCFLTR5 = 0;
     ADCFLTR6 = 0;

     /* Set up the trigger sources */
     ADCTRGSNSbits.LVL0 = 0; // Edge trigger; not sure it is usefull TODO: clarify
                               // Analog input is sensitive to the positive edge of
                               // its trigger (this is the value after a reset)
                               // DS60001344D page 54
     ADCTRGSNSbits.LVL1 = 0; // Edge trigger; not sure it is usefull TODO: clarify
     ADCTRG1bits.TRGSRC0 = 1; // Set AN0 to trigger from software.
     ADCTRG1bits.TRGSRC1 = 1; // Set AN1 to trigger from software.

       // TODO: is the following necessary ? i do not think, since we will trig by software.
       // from: https://www.microchip.com/forums/m1020951.aspx?high=PIC32MZ+ADC+interrupt
      // ADCTRGMODE=0;
      //Apparently with multiple conversions that need to be triggered simultaneously, the ADC must operate in pre-synchronized and asynchronous mode.
      //ADCTRGMODEbits.STRGEN0 = 0 /*1*/; // AN0 uses pre-synchronized trigger.
      //ADCTRGMODEbits.SSAMPEN0 = 0; // AN0 uses asynchronous sampling.
      //ADCTRGMODEbits.STRGEN1 = 0 /*1*/; // AN1 uses pre-synchronized trigger.
      //ADCTRGMODEbits.SSAMPEN1 = 0; // AN1 uses asynchronous sampling.
      
       
       
     /* Early interrupt */
     ADCEIEN1 = 0; // No early interrupt
     ADCEIEN2 = 0;
     ADCCON2bits.ADCEIOVR = 1; // Override early interrupt. Once this bit is set,
                                  // setting the bits in the in the ADCEIEN1 or
                                  // ADCEIEN2 register has no effect on interrupt
                                  // generation. The interrupt generation is then
                                  // controlled by the setting of ADCGIRQEN1 and
                                  // ADCGIRQEN2 registers (DS60001344D page 113).

       
      /* Configure ADC interrupt priority */
       IPC11bits.ADCIP = 3; // IPC11 checked in DS60001320D page 119.
       IPC11bits.ADCIS = 1;
          
       


       // utile pour enabler interrupt?
       //IEC1bits.ADCIE = 1;
       //IEC1bits.ADCD0IE = 1;
       //IEC1bits.ADCD1IE = 1;
     
     /* Configure ADBASE */
     ADCBASE = (int)(&jumpTable[0]); // Initialize ADCBASE with starting address of jump table
     ADCCON1bits.IRQVS = 0; // No left shift of address
       
     /* Turn the ADC on */
     ADCCON1bits.ON = 1;
     
     /* Wait for voltage reference to be stable */
     while( !ADCCON2bits.BGVRRDY ); // Wait until the reference voltage is ready
     while( ADCCON2bits.REFFLT ); // Wait if there is a fault with the reference voltage
     
     /* Enable clock to analog circuit */
     ADCANCONbits.ANEN0 = 1; // Enable the clock to analog bias and digital control
     ADCANCONbits.ANEN1 = 1; // Enable the clock to analog bias and digital control

     
     /* Wait for ADC to be ready */
     while( !ADCANCONbits.WKRDY0 ); // Wait until ADC0 is ready
     while( !ADCANCONbits.WKRDY1 ); // Wait until ADC1 is ready

     /* Enable the ADC module */
     ADCCON3bits.DIGEN0 = 1; // Enable ADC0
     ADCCON3bits.DIGEN1 = 1; // Enable ADC1
       
     /* Configure ADCGIRQENx */
     ADCGIRQEN1 = 0;
     ADCGIRQEN2 = 0;
     ADCGIRQEN1bits.AGIEN0 = 1; // Enable data ready interrupt for AN0
     ADCGIRQEN1bits.AGIEN1 = 1; // Enable data ready interrupt for AN1
       
     /* Trigger a conversion */
     //ADCCON3bits.GSWTRG = 1; // Global software trigger
    }


    int main(int argc, char** argv) {

       initLeds();
       vHardwareConfigurePerformance();
       configureADCwithInterrupts();
       //initADC();
       
       // Necessary to enable ADC interrupt?
       IEC1bits.ADCIE = 1;
       
       INTCONbits.MVEC = 1; // Enable Multi-vectored Interrupts
        __asm__ volatile ("ei");
       

     
     /* Trigger a conversion */
     ADCCON3bits.GSWTRG = 1; // Global software trigger; self cleared: only one conversion is triggered
       
       LATAbits.LATA6 = 1;

       LATAbits.LATA6 = 0;
       
       

       while(1){
          
          //performADCmeasurement();
          
          //for( unsigned i =0; i < 1000000; ++i){
          //}
          LATAbits.LATA6 = 1;


          //for( unsigned i =0; i < 1000000; ++i){
          //}
          LATAbits.LATA6 = 0;

       }
     
     return (1);
    }

    /* Handler for the ADC interrupt */
    extern "C" { void __ISR( _ADC_VECTOR, IPL3SRS/*IPL3SOFT*/ /*ipl3*//*IPL3AUTO*/ ) ADCHandler1(void)
    {
       LATAbits.LATA6 = 1;
       
     /* call the corresponding ADC module handler */
     ((void(*)())*((int *)ADCBASE))();
    }

    }



    void ADC0Handler(void)
    {
     /* Verify if data for AN0 is ready. This bit is self cleared upon data read */
     if(ADCDSTAT1bits.ARDY0)
     {
      ADC0Result = ADCDATA0;
     }
    }



    void ADC1Handler(void)
    {
     /* Verify if data for AN1 is ready. This bit is self cleared upon data read */
     if(ADCDSTAT1bits.ARDY1)
     {
      ADC1Result = ADCDATA1;
     }
    }





     
     
    #9
    alimerido
    ME & EEE
    • Total Posts : 6
    • Reward points : 0
    • Joined: 2018/03/31 15:59:04
    • Location: 0
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2019/03/14 04:15:33 (permalink)
    0
    Hi, 
     
    Did you figure it out the problem? I am having the same problem. I firing the interrupt by giving IFS1.ADCIF = 1 manually in every timer interrupt and clearing at the end of ISR. If you solved, please let me know. I spent a lot of time to solve this issue.
    #10
    Taïga
    Starting Member
    • Total Posts : 31
    • Reward points : 0
    • Joined: 2015/03/17 14:00:17
    • Location: Belgium
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2019/03/14 14:27:38 (permalink)
    5 (1)
    Hello,
     
    Yes. I will try to put an example of code this week end.
    I must clean a bit the code before...
     
    Best regards,
    #11
    GARETH_71
    Senior Member
    • Total Posts : 145
    • Reward points : 0
    • Joined: 2006/11/18 13:46:50
    • Location: UK
    • Status: offline
    Re: ADC interrupt not firing on PIC32MZ2048EFH100 2019/05/20 02:14:03 (permalink)
    0
    Any news on this? I am having the same issue...?
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5