This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Two adc channels



I have two ADC channels A1 and A2 triggered by CPU Timer0 interrupt every 826us

I have also set EOC2 to trigger ADCINT1 for SOC conversion

AdcRegs.INTSEL1N2.bit.INT1E     = 1;                //Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT  = 0;                //Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL    = 2;                //setup EOC2 to trigger ADCINT1 to fire

AdcRegs.ADCSOC1CTL.bit.CHSEL     = 1; AdcRegs.ADCSOC2CTL.bit.CHSEL     = 2;

AdcRegs.ADCSOC1CTL.bit.TRIGSEL     = 1; AdcRegs.ADCSOC2CTL.bit.TRIGSEL     = 1;

PieVectTable.TINT0 = &adc_isr;

__interrupt void  adc_isr(void)
{
    Voltage2 = AdcResult.ADCRESULT2;
    Voltage1[ConversionCount] = AdcResult.ADCRESULT1;

AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;                    //Clear TINT0 flag reinitialize for next SOC
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;                   // Acknowledge interrupt to PIE
    return;
}

Can anyone confirm if this is the right way to do?

Are there any other registers I need to set?

Thanks in advance

Sandhya

  • Sandhya Jetti said:

    Can anyone confirm if this is the right way to do?

    Are there any other registers I need to set?

    Sandhya, other than missing timer configuration rest all seem fine.

    Regards,

    Gautam

  • Thanks a lot Gautam. I have the Cpu timer configuration

    ConfigCpuTimer(&CpuTimer0, 60, 826);


    But I am a little confused about the interrupt in PIE table, Because my adc conversion starts with Timer0 interrupt but also ADCINT1 interrupt allows the SOC conversion, code seems to work by either definition. Could you clarify this for me?

    PieVectTable.TINT0 = &adc_isr;

    or

    PieVectTable.ADCINT1 = &adc_isr;

  • Sandhya,

    Two notes:
    1) The code you posted only configured ADC-A1 to convert.  I assume that you may know this though :).
    2) Both configurations are valid (using the ADC EOC or using the CpuTimer to drive your interrupt).  It just depends on how you want things to work. 

    If you choose to trigger the interrupt based on the timer event, both the ADC and interrupt will trigger simultaneously which means you may need to add some junk code (or worthwhile code that doesn't read the ADC) to make sure that you read the most recent ADC conversion and not the sample from the interrupt prior. 

    If you choose to trigger the interrupt on the ADC EOC, you can read the ADC results register immediately in the interrupt and be confident that you are getting the most recent sample.


    Thank you,
    Brett

  • Hello Brett,

    I thought I configured both A-1 and A-2 channels by CHSEL register

    Thanks for explaining the difference, greatly appreciated! 

    -Sandhya