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.

CCS/TM4C123GH6PM: Tiva C triggering ADC by GPIO event

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

Hello. I have next task. I receive 2 signals from compactors which looks like 50% PWM 100Hz and shifted by 90 degrees to each other. I need to make ADC sample each time than signals switched (4 times per period or 400hz). I wrote next code for this task.

static void adcInterruptHandler(){

    unsigned int state = ADCIntStatus(ADC0_BASE, 0, true);
    ADCIntClear(ADC0_BASE, 0);

    int32_t tmp[2];
    ADCSequenceDataGet(ADC0_BASE, 0, (uint32_t *)tmp);
    ADCSequenceDataGet(ADC0_BASE, 0, (uint32_t *)tmp+1);
}

static void initAdc(){
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0));

    ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_EXTERNAL, 0);
    //set up sequence
    ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH1);
    ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH0 |
                             ADC_CTL_IE | ADC_CTL_END);
    //interrupt settings
    ADCIntRegister(ADC0_BASE, 0, adcInterruptHandler);
    ADCIntEnable(ADC0_BASE, 0);
    ADCSequenceEnable(ADC0_BASE, 0);
    ADCIntClear(ADC0_BASE, 0);
}

static void initGpioInterrupt(){
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
    GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_BOTH_EDGES);
    GPIOIntTypeSet(GPIO_PORTF_BASE,GPIO_PIN_4,GPIO_BOTH_EDGES);


    GPIOADCTriggerEnable(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOADCTriggerEnable(GPIO_PORTF_BASE, GPIO_PIN_4);
}

This code run good while i emulate event using button, but at real enviroment it goes to FaultISR. Look like signals has gitter and triggering happend several times in one moment. I need to fix this fault by skipping redundant events but how to do it?

  • What is your input looked like? How do you know it is glitching?

    Try an experiment to use GPIO_FALLING_EDGE instead of GPIO_BOTH_EDGES. Do you still FaultISR?

    If you are sure that your input is glitches then you need to debounce your input. 

  • Hello Charles,

    Should it be noted - in addition:

    • 'Main' has somehow escaped poster's code listing
    • 'PF0' - when the MCU is 4C123 - requires 'Unlocking' - nowhere in evidence

    Scope caps during the failing conditions would vastly, 'Speed, Ease, Enhance' diagnostics.

    Minus PF0's unlocking - poster's report of (almost) working - seems 'up for debate.'

  • Hi cb1,

      Thanks again. You are correct. PF0 must be unlocked and committed first before it can be used as GPIO. 

    The GPIOCR register is the commit register. The value of the GPIOCR register determines which
    bits of the GPIOAFSEL, GPIOPUR, GPIOPDR, and GPIODEN registers are committed when a
    write to these registers is performed. If a bit in the GPIOCR register is cleared, the data being written
    to the corresponding bit in the GPIOAFSEL, GPIOPUR, GPIOPDR, or GPIODEN registers cannot
    be committed and retains its previous value. If a bit in the GPIOCR register is set, the data being
    written to the corresponding bit of the GPIOAFSEL, GPIOPUR, GPIOPDR, or GPIODEN registers
    is committed to the register and reflects the new value.