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.

TM4C123G ADC digital comparator didn't work

I am stuck on digital comparator for couple days. I need some help..... The system has 4 analog inputs with timer trigger for ADC. An interrupt is triggered after ADC finished. One of anlogy input also sent to digital comparator. If the input value is higher than some value, then make count. The ADC and interrupt work good, but the digital comparator int status not right (or not triggered). I check the comparator int staus in the interrupt. Below is the code for ADC initial and interrupt. 

#define ADC_CTL_CT      ADC_CTL_CH15
#define ADC_CTL_PT      ADC_CTL_CH14
#define ADC_CTL_IN1     ADC_CTL_CH13
#define ADC_CTL_IN2     ADC_CTL_CH12

void
InitADC()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
ADCHardwareOversampleConfigure(ADC1_BASE, 2);

GPIOPinTypeADC(GPIO_PORTD_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);

ADCSequenceDisable(ADC1_BASE,0);
ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CT|ADC_CTL_CMP0);
ADCSequenceStepConfigure(ADC1_BASE, 0, 1, ADC_CTL_CT);
ADCSequenceStepConfigure(ADC1_BASE, 0, 2, ADC_CTL_PT);
ADCSequenceStepConfigure(ADC1_BASE, 0, 3, ADC_CTL_IN1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 4, ADC_CTL_IN2 | ADC_CTL_END | ADC_CTL_IE);

ADCSequenceEnable(ADC1_BASE, 0);


ADCComparatorConfigure(ADC1_BASE,0,ADC_COMP_TRIG_NONE|ADC_COMP_INT_HIGH_HONCE);
ADCComparatorRegionSet(ADC1_BASE, 0, 2100, 2200);
ADCComparatorReset(ADC1_BASE, 0, true, true);
ADCComparatorIntEnable(ADC1_BASE,0);

ADCIntEnable(ADC1_BASE, 0);
IntEnable(INT_ADC1SS0);

//set timer for adc1 converter trigger 50us
TimerConfigure(TIMER2_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC));
TimerLoadSet(TIMER2_BASE, TIMER_A, (SysCtlClockGet() * ADCTIMERPERIOD) - 1);
TimerControlTrigger(TIMER2_BASE, TIMER_A, true);
TimerEnable(TIMER2_BASE, TIMER_A);

}

uint32_t g_ui32ADC1Result[5];

//
void
ADC1IntHandler()
{

uint32_t ui32ComINTFlag;
static uint8_t ui8NumCycle=0;

ADCIntClear(ADC1_BASE, 0);

ADCSequenceDataGet(ADC1_BASE, 0, g_ui32ADC1Result);

ui32ComINTFlag=ADCComparatorIntStatus(ADC1_BASE);   //The comparatorInt status always zero ?????

if(ui32ComINTFlag!=0) 
{
ADCComparatorIntClear(ADC1_BASE, ui32ComINTFlag);
ui8NumCycle++;
}

}

  • Hello Liqin,

    The first thing to check is that the timer is triggering the ADC correctly. So step-by-step

    1. Remove the comparator code and then check if when using just the ADC you get the interrupt on conversion
    2. Also check that the ADC trigger must be at least 4*16 clocks apart. 16 clocks for conversion for 1 channel and 4 because there are 4 channels. To ensure safety from conversion perspective make it 5*16. This is where I am having concerns as well. The timer is configured in split mode which means 16-bit counter, The System Clock Frequency may not fit in 16 bits.

    What is the value of ADCTIMERPERIOD?

    Regards
    Amit