Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] ADC interrupt not generated in PIC24FJ128GB204

Status
Not open for further replies.

ThanosTheAvenger

Newbie level 4
Joined
Mar 16, 2019
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
41
This is the generated code from MCC...

Code:
void ADC1_Initialize (void)
{
    // ASAM disabled; DMABM disabled; ADSIDL disabled; DONE disabled; DMAEN disabled; FORM Absolute decimal result, unsigned, right-justified; SAMP disabled; SSRC Clearing sample bit ends sampling and starts conversion; MODE12 12-bit; ADON enabled; 

   AD1CON1 = 0x8400;

    // CSCNA disabled; NVCFG0 AVSS; PVCFG AVDD; ALTS disabled; BUFM disabled; SMPI 8; OFFCAL disabled; BUFREGEN disabled; 

   AD1CON2 = 0x001C;

    // SAMC 8; EXTSAM disabled; PUMPEN disabled; ADRC FOSC/2; ADCS 7; 

   AD1CON3 = 0x0807;

    // CH0SA AN1; CH0SB AN1; CH0NB AVSS; CH0NA AVSS; 

   AD1CHS = 0x0101;

    // CSS31 disabled; CSS30 disabled; CSS29 disabled; CSS28 disabled; CSS27 disabled; 

   AD1CSSH = 0x0000;

    // CSS9 disabled; CSS7 disabled; CSS6 disabled; CSS5 disabled; CSS4 disabled; CSS3 disabled; CSS2 disabled; CSS1 disabled; CSS14 disabled; CSS0 disabled; CSS13 disabled; CSS12 disabled; CSS11 disabled; CSS10 disabled; 

   AD1CSSL = 0x0000;

    // VBG2EN disabled; VBGEN disabled; 

   ANCFG = 0x0000;

AD1CON2bits.SMPI = 1;
   adc1_obj.intSample = AD1CON2bits.SMPI;
   ADC1_ChannelSelect(1);
   ADC1_Start();
   // Enabling ADC1 interrupt.
   IEC0bits.AD1IE = 1;
}

void ADC1_Start(void)
{
   AD1CON1bits.SAMP = 1;
}
void ADC1_Stop(void)
{
   AD1CON1bits.SAMP = 0;
}
uint16_t ADC1_ConversionResultBufferGet(uint16_t *buffer)
{
    int count;
    uint16_t *ADC16Ptr;

    ADC16Ptr = (uint16_t *)&(ADC1BUF0);

    for(count=0;count<=adc1_obj.intSample;count++)
    {
        buffer[count] = (uint16_t)*ADC16Ptr;
        ADC16Ptr++;
    }
    return count;
}
uint16_t ADC1_ConversionResultGet(void)
{
    return ADC1BUF0;
}
bool ADC1_IsConversionComplete( void )
{
    return AD1CON1bits.DONE; //Wait for conversion to complete   
}
void ADC1_ChannelSelect( ADC1_CHANNEL channel )
{
    AD1CHS = channel;
}


void __attribute__ ( ( __interrupt__ , auto_psv ) ) _ADC1Interrupt ( void )
{
    // clear the ADC interrupt flag
    IFS0bits.AD1IF = false;
}

This is main...

Code:
int main(void)
{
    // initialize the device
    SYSTEM_Initialize();

    while (1)
    {
        // Add your application code
    }

    return -1;
}

void SYSTEM_Initialize(void)
{
    PIN_MANAGER_Initialize();
    INTERRUPT_Initialize();
    OSCILLATOR_Initialize();
    ADC1_Initialize();
    
}

Now, whether or not MCU pins are reading analog voltages properly, the Interrupt has to be generated.
But, the breakpoint when set in the ADC1Interrupt function is never hit.

Please help me.
 

Do yo enable interrupts globally somewhere, e.g. by _IPL = 0 ?
 

Do yo enable interrupts globally somewhere, e.g. by _IPL = 0 ?

Nope...
Actually I used generated code as is. My guess was it should be working at least generating interrupts... values read could be wrong.

- - - Updated - - -

Do yo enable interrupts globally somewhere, e.g. by _IPL = 0 ?

I just verified that it's not the issue of global interrupt enabling.
I have actually copied this code to another project as is, where the Timer interrupt is working.
But, I didn't get any interrupt of ADC at all.
 

Hi,

debug: check the state of the interrupt flag by polling.

Klaus
 

O.K., apparently it's a problem of the ADC setup. Did you verify that the ADC is converting at all and showing reasonable status information?
 

O.K., apparently it's a problem of the ADC setup. Did you verify that the ADC is converting at all and showing reasonable status information?

I checked... the ADIF flag is not set at all so there is no interrupt.
I think ADC configuration is problem.. they way you said.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top