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/EK-TM4C1294XL: Hibernate RTC not interrupting in the right way

Part Number: EK-TM4C1294XL

Tool/software: Code Composer Studio

Hi,

I'm trying to use the Hibernate RTC module to keep track of time, but when I set the interrupt time, instead of interrupting every 60 seconds, it seems that is interrupting many times faster (really, MANY times faster). Also, after setting up RTC I cannot exit the program by pressing enter, it "resets" the program everytime I do that. I've tried to copy similar examples from the internet, but it always gives me the same behaviour.

What might cause this? I'm configuring interrupts the wrong way?

/*
 * adc.c
 *
 *  Created on: 24 de jan de 2017
 *      Author: Helder Sales
 */

#include "adc.h"
#include "../wdog/wdog.h"
#include "../../includes.h"
#include "../../../command/read/read.h"

//To verify char
unsigned char ch;

//Number of input pins and type
uint8_t numarg, Inputs, pinPE, pinPK;

//Time
uint8_t minute, hour;

inline unsigned char ADC_InitADCPins(char *g_cInput)
{
    //argv
    static char *argv[8 + 1];

    char *pcChar;
    uint_fast8_t argc = 0;
    bool bFindArg = true;
    pcChar = g_cInput;

    while(*pcChar)
    {
        if(*pcChar == ' ')
        {
            *pcChar = 0;
            bFindArg = true;
        }

        else if(bFindArg)
        {
            argv[argc] = pcChar;
            argc++;
            bFindArg = false;
        }

        pcChar++;
    }

    char *num = argv[1];
    unsigned int aux;
    uint8_t condition = sscanf(num, "%u%c", &aux, &ch);
    pinPE = strcmp(argv[0], "PE");
    pinPK = strcmp(argv[0], "PK");
    numarg = argc;
    Inputs = aux;

    if((pinPE != 0 && pinPK != 0) || condition != 1)
    {
        Inputs = 0;
        return(Inputs);
    }

    //Enable pin J
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOJ));

    //Configures pin PJ0 as input
    ROM_GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);

    //General config (pull-up)
    GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    if(pinPE == 0)
    {
        //Enable pin E
        ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOE);
        ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
        while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE));

        if(Inputs == 1)
            //Enable pin PE0 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);
        if(Inputs == 2)
            //Enable pin PE0/PE1 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        if(Inputs == 3)
            //Enable pin PE0/PE1/PE2 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
        if(Inputs == 4)
            //Enable pin PE0/PE1/PE2/PE3 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    }

    else if(pinPK == 0)
    {
        //Enable pin K
        ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOK);
        ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOK);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
        while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOK));

        if(Inputs == 1)
            //Enable pin PK0 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_0);
        if(Inputs == 2)
            //Enable pin PK0/PK1 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1);
        if(Inputs == 3)
            //Enable pin PK0/PK1/PK2 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
        if(Inputs == 4)
            //Enable pin PK0/PK1/PK2/PK3 as ADC
            ROM_GPIOPinTypeADC(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
    }

    return(Inputs);
}

inline void ADC_InitADC(unsigned char Inputs, unsigned char oversamplevalue)
{
    //Enable ADC0
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0));

    //Enable ADC1
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_ADC1);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_ADC1);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_ADC1));

    //Configures ADC0 sequence 2, trigger by the processor, priority 0 (highest)
    ROM_ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);

    //Configures ADC1 sequence 3, trigger by the processor, priority 1
    ROM_ADCSequenceConfigure(ADC1_BASE, 3, ADC_TRIGGER_PROCESSOR, 1);

    //Step 0 sequence 2, MCU's temp sampling, sequence (0 to the highest), configures interrupt after sampling, tells ADC1 this is the last conversion
    ROM_ADCSequenceStepConfigure(ADC1_BASE, 3, 0, ADC_CTL_TS | ADC_CTL_IE | ADC_CTL_END);

    if(pinPE == 0)
    {
        if(Inputs == 1)
        {
            //Step 0 sequence 2, sampling of channel 0, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            //(to know more about channels, see datasheet pg. 1056)
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);
        }

        else if(Inputs == 2)
        {
            //Step 0 sequence 2, sampling of channel 0/1, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH3);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH2 | ADC_CTL_IE | ADC_CTL_END);
        }

        else if(Inputs == 3)
        {
            //Step 0 sequence 2, sampling of channel 0/1/2, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH3);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH2);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
        }

        else if(Inputs == 4)
        {
            //Step 0 sequence 2, sampling of channel 0/1/2/3, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH3);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH2);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH1);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 3, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
        }
    }

    else if(pinPK == 0)
    {
        if(Inputs == 1)
        {
            //Step 0 sequence 2, sampling of channel 16, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH16 | ADC_CTL_IE | ADC_CTL_END);
        }

        else if(Inputs == 2)
        {
            //Step 0 sequence 2, sampling of channel 16/17, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH16);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH17 | ADC_CTL_IE | ADC_CTL_END);
        }

        else if(Inputs == 3)
        {
            //Step 0 sequence 2, sampling of channel 16/17/18, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH16);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH17);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH18 | ADC_CTL_IE | ADC_CTL_END);
        }

        else if(Inputs == 4)
        {
            //Step 0 sequence 2, sampling of channel 16/17/18/19, sequence (0 to the highest), configures interrupt after sampling, tells ADC that CH19 is the last conversion
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH16);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH17);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH18);
            ROM_ADCSequenceStepConfigure(ADC0_BASE, 2, 3, ADC_CTL_CH19 | ADC_CTL_IE | ADC_CTL_END);
        }
    }

    //Configures the ADC to 2MSPS (PLL/15 = 32MHz, Sampling rate full)
    ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 15);

    //Configures the ADC to 125KSPS (PLL/30 = 16MHz, Sampling rate 1/8th)
    ADCClockConfigSet(ADC1_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_EIGHTH, 30);

    //Oversampling (mean of samples, effective speed = (MSPS)*(oversample value))
    ROM_ADCHardwareOversampleConfigure(ADC0_BASE, oversamplevalue);
    ROM_ADCHardwareOversampleConfigure(ADC1_BASE, 64);

    //habilita ADC0 sequence 2
    ROM_ADCSequenceEnable(ADC0_BASE, 2);

    //habilita ADC1 sequence 3
    ROM_ADCSequenceEnable(ADC1_BASE, 3);
}

inline void ADC_InitHibernateRTC(void)
{
    //Enable Hibernation Module
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_HIBERNATE);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_HIBERNATE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_HIBERNATE));

    ROM_HibernateEnableExpClk(120000000);
    ROM_HibernateClockConfig(HIBERNATE_OSC_HIGHDRIVE);

    ROM_HibernateRTCSet(0);

    ROM_HibernateRTCMatchSet(0, 60);

    ROM_HibernateIntEnable(HIBERNATE_INT_RTC_MATCH_0);

    HibernateIntRegister(HibernateRTCIntHandler);
}

inline void Init_Timer1(unsigned int freq)
{
    //Enable Timer 1
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_TIMER1);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER1);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
    while(!ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER1));

    //Timer 1 clock = PIOSC
    ROM_TimerClockSourceSet(TIMER1_BASE, TIMER_CLOCK_PIOSC);

    ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);

    uint32_t uiPeriod = 16000000/freq;

    ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, uiPeriod -1);

    ROM_IntPrioritySet(INT_TIMER1A, 1);
    ROM_IntEnable(INT_TIMER1A);
    ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    ROM_TimerEnable(TIMER1_BASE, TIMER_A);
}

void Timer1IntHandler(void)
{
    ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    //Array with the length of the FIFO used (ver datasheet pag. 1056)
    uint32_t ADC0Values[4];
    uint32_t ADC1Values[1];
    //Convert ADC value to temp
    uint8_t TempValueC;

    //Convert ADC0Values to voltage
    uint16_t Value1, Value2, Value3, Value4;

    static uint16_t Value1max = 0;
    static uint16_t Value2max = 0;
    static uint16_t Value3max = 0;
    static uint16_t Value4max = 0;
    static uint16_t Value1min = 4095*0.8058608059;
    static uint16_t Value2min = 4095*0.8058608059;
    static uint16_t Value3min = 4095*0.8058608059;
    static uint16_t Value4min = 4095*0.8058608059;

    //Clears ADC interrupt status
    ROM_ADCIntClear(ADC0_BASE, 2);
    ROM_ADCIntClear(ADC1_BASE, 3);

    //Enable the triggers for the conversion
    ROM_ADCProcessorTrigger(ADC0_BASE, 2);
    ROM_ADCProcessorTrigger(ADC1_BASE, 3);

    //Waits the conversion to be completed
    while(!ROM_ADCIntStatus(ADC0_BASE, 2, false) || !ROM_ADCIntStatus(ADC1_BASE, 3, false));

    //Reads the values obtained by the ADC
    ROM_ADCSequenceDataGet(ADC0_BASE, 2, ADC0Values);
    ROM_ADCSequenceDataGet(ADC1_BASE, 3, ADC1Values);

    //Converts ADC values to temperature
    TempValueC = (uint8_t)(147.5 - ((75.0 * 3.3 * (float)ADC1Values[0])) / 4096.0);

    if(Inputs == 4)
    {
        //Converts ADC values to voltage
        Value1 = ADC0Values[0]*0.8058608059;
        Value2 = ADC0Values[1]*0.8058608059;
        Value3 = ADC0Values[2]*0.8058608059;
        Value4 = ADC0Values[3]*0.8058608059;

        if(Value1max < Value1)
            Value1max = Value1;

        if(Value2max < Value2)
            Value2max = Value2;

        if(Value3max < Value3)
            Value3max = Value3;

        if(Value4max < Value4)
            Value4max = Value4;

        if(Value1min > Value1)
            Value1min = Value1;

        if(Value2min > Value2)
            Value2min = Value2;

        if(Value3min > Value3)
            Value3min = Value3;

        if(Value4min > Value4)
            Value4min = Value4;

        if(pinPE == 0)
            //Print ADC results
            UARTprintf("PE0 reading = %04u mV || Max. PE0 = %04u mV || Min. PE0 = %04u mV\n"
                    "PE1 reading = %04u mV || Max. PE1 = %04u mV || Min. PE1 = %04u mV\n"
                    "PE2 reading = %04u mV || Max. PE2 = %04u mV || Min. PE2 = %04u mV\n"
                    "PE3 reading = %04u mV || Max. PE3 = %04u mV || Min. PE3 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[5A\r", Value1, Value1max, Value1min, Value2, Value2max, Value2min,
                    Value3, Value3max, Value3min, Value4, Value4max, Value4min, hour, minute, ROM_HibernateRTCGet(), TempValueC);

        else
            UARTprintf("PK0 reading = %04u mV || Max. PK0 = %04u mV || Min. PK0 = %04u mV\n"
                    "PK1 reading = %04u mV || Max. PK1 = %04u mV || Min. PK1 = %04u mV\n"
                    "PK2 reading = %04u mV || Max. PK2 = %04u mV || Min. PK2 = %04u mV\n"
                    "PK3 reading = %04u mV || Max. PK3 = %04u mV || Min. PK3 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[5A\r", Value1, Value1max, Value1min, Value2, Value2max, Value2min,
                    Value3, Value3max, Value3min, Value4, Value4max, Value4min, hour, minute, ROM_HibernateRTCGet(), TempValueC);
    }

    else if(Inputs == 3)
    {
        //Converts ADC values to voltage
        Value1 = ADC0Values[0]*0.8058608059;
        Value2 = ADC0Values[1]*0.8058608059;
        Value3 = ADC0Values[2]*0.8058608059;

        if(Value1max < Value1)
            Value1max = Value1;

        if(Value2max < Value2)
            Value2max = Value2;

        if(Value3max < Value3)
            Value3max = Value3;

        if(Value1min > Value1)
            Value1min = Value1;

        if(Value2min > Value2)
            Value2min = Value2;

        if(Value3min > Value3)
            Value3min = Value3;

        if(pinPE == 0)
            //Print ADC results
            UARTprintf("PE0 reading = %04u mV || Max. PE0 = %04u mV || Min. PE0 = %04u mV\n"
                    "PE1 reading = %04u mV || Max. PE1 = %04u mV || Min. PE1 = %04u mV\n"
                    "PE2 reading = %04u mV || Max. PE2 = %04u mV || Min. PE2 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[4A\r", Value1, Value1max, Value1min, Value2, Value2max, Value2min,
                    Value3, Value3max, Value3min, hour, minute, ROM_HibernateRTCGet(), TempValueC);

        else
            //Print ADC results
            UARTprintf("PK0 reading = %04u mV || Max. PK0 = %04u mV || Min. PK0 = %04u mV\n"
                    "PK1 reading = %04u mV || Max. PK1 = %04u mV || Min. PK1 = %04u mV\n"
                    "PK2 reading = %04u mV || Max. PK2 = %04u mV || Min. PK2 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[4A\r", Value1, Value1max, Value1min, Value2, Value2max, Value2min,
                    Value3, Value3max, Value3min, hour, minute, ROM_HibernateRTCGet(), TempValueC);
    }

    else if(Inputs == 2)
    {
        //Converts ADC values to voltage
        Value1 = ADC0Values[0]*0.8058608059;
        Value2 = ADC0Values[1]*0.8058608059;

        if(Value1max < Value1)
            Value1max = Value1;

        if(Value2max < Value2)
            Value2max = Value2;

        if(Value1min > Value1)
            Value1min = Value1;

        if(Value2min > Value2)
            Value2min = Value2;

        if(pinPE == 0)
            //Print ADC results
            UARTprintf("PE0 reading = %04u mV || Max. PE0 = %04u mV || Min. PE0 = %04u mV\n"
                    "PE1 reading = %04u mV || Max. PE1 = %04u mV || Min. PE1 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[3A\r", Value1, Value1max, Value1min, Value2, Value2max, Value2min,
                    hour, minute, ROM_HibernateRTCGet(), TempValueC);

        else
            //Print ADC results
            UARTprintf("PK0 reading = %04u mV || Max. PK0 = %04u mV || Min. PK0 = %04u mV\n"
                    "PK1 reading = %04u mV || Max. PK1 = %04u mV || Min. PK1 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[3A\r", Value1, Value1max, Value1min, Value2, Value2max, Value2min,
                    hour, minute, ROM_HibernateRTCGet(), TempValueC);
    }

    else if(Inputs == 1)
    {
        //Converts ADC values to voltage
        Value1 = ADC0Values[0]*0.8058608059;

        if(Value1max < Value1)
            Value1max = Value1;

        if(Value1min > Value1)
            Value1min = Value1;

        if(pinPE == 0)
            //Print ADC results
            UARTprintf("PE0 reading = %04u mV || Max. PE0 = %04u mV || Min. PE0 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[2A\r", Value1, Value1max, Value1min, hour, minute, ROM_HibernateRTCGet(), TempValueC);

        else
            //Print ADC results
            UARTprintf("PK0 reading = %04u mV || Max. PK0 = %04u mV || Min. PK0 = %04u mV\n\n"
                    "Elapsed time: %02uhrs %02umin %02usec  MCU Temp: %u*C\x1b[2A\r", Value1, Value1max, Value1min, hour, minute, ROM_HibernateRTCGet(), TempValueC);
    }

    if(Value1min == 0 && ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_WDOG0))
    {
        FeedWatchdog = false;
        while(1);
    }
}

void HibernateRTCIntHandler(void)
{
    ROM_HibernateIntClear(HIBERNATE_INT_RTC_MATCH_0);

    minute++;

    if(minute == 60)
    {
        hour++;
        minute = 0;
    }

    ROM_HibernateRTCSet(0);

    HibernateRTCMatchSet(0, 60);
}

inline void ADC_Loop(unsigned int freq)
{
    hour = 0;
    minute = 0;

    UARTFlushRx();

    Init_Timer1(freq);

    ADC_InitHibernateRTC();
    ROM_HibernateRTCEnable();

    while(UARTPeek('\r') == -1);

    UARTFlushRx();

    ROM_IntDisable(INT_TIMER1A);
    ROM_HibernateIntDisable(HIBERNATE_INT_RTC_MATCH_0);
    ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
    ROM_HibernateIntClear(HIBERNATE_INT_RTC_MATCH_0);
    ROM_TimerDisable(TIMER1_BASE, TIMER_A);
    HibernateIntUnregister();

    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_HIBERNATE);
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_TIMER1);

    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOJ);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER1);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_HIBERNATE);

    if(Inputs == 4)
        UARTprintf("\n\n\n\n\n\nProgram terminated.\n");

    if(Inputs == 3)
        UARTprintf("\n\n\n\n\nProgram terminated.\n");

    if(Inputs == 2)
        UARTprintf("\n\n\n\nProgram terminated.\n");

    if(Inputs == 1)
        UARTprintf("\n\n\nProgram terminated.\n");
}

inline int ADC_main(int argc, char *argv[])
{
    //text to indicate which pins are active
    char text[8][32] = {"PE0", "PE0/PE1", "PE0/PE1/PE2", "PE0/PE1/PE2/PE3", "PK0", "PK0/PK1", "PK0/PK1/PK2", "PK0/PK1/PK2/PK3"};

    unsigned int freq, oversamplevalue;
    char *num1 = argv[1];
    char *num2 = argv[3];
    uint8_t condition = sscanf(num1, "%u%c", &freq, &ch);

    if(freq <= 0 || argc == 1 || argc == 3 || argc > 4 || condition != 1)
        return(CMD_ERROR);

    else if(strcmp(argv[2], "oversample") == 0)
    {
        uint8_t condition2 = sscanf(num2, "%u%c", &oversamplevalue, &ch);

        if((oversamplevalue == 2 || oversamplevalue == 4 || oversamplevalue == 8 || oversamplevalue == 16 || oversamplevalue == 32 || oversamplevalue == 64) && condition2 == 1)
        {
            UARTprintf("\nAnalog Digital Converter\n"
                    "Type: Single Ended.\n"
                    "Oversampling: %u\n"
                    "Update rate: %u Hz\n\n"
                    "Choose the port and the number of inputs (PE/PK, 1-4)\n\n"
                    ">>", oversamplevalue, freq);

            Read_Command();

            Inputs = ADC_InitADCPins(g_cInput_Read());
            ADC_InitADC(Inputs, oversamplevalue);

            if(Inputs < 1 || Inputs > 4 || numarg > 2)
                return(CMD_ERROR);
        }

        else if(condition2 != 1)
            return(CMD_ERROR);

        else
        {
            UARTprintf("\nOnly 2, 4, 8, 16, 32 and 64 are accepted for HW oversampling\n");
            return(CMD_ERROR);
        }
    }

    else if(argc == 2)
    {
        UARTprintf("\nAnalog Digital Converter\n"
                "Type: Single Ended.\n"
                "Oversampling: Deactivated\n"
                "Update rate: %u Hz\n\n"
                "Choose the port and the number of inputs (PE/PK, 1-4)\n\n"
                ">>", freq);

        Read_Command();

        Inputs = ADC_InitADCPins(g_cInput_Read());
        ADC_InitADC(Inputs, 0);

        if(Inputs < 1 || Inputs > 4 || numarg > 2)
            return(CMD_ERROR);
    }

    if(pinPE == 0)
        UARTprintf("\nNumber of inputs: %u\n"
                "Inputs: %s\n\n"
                "Press \"Enter\" or User Switch 1 to initiate.\n"
                "After the program is running, press \"Enter\" again to exit.\n", Inputs, &text[Inputs-1]);

    else
        UARTprintf("\nNumber of inputs: %u\n"
                "Inputs: %s\n\n"
                "Press \"Enter\" or User Switch 1 to initiate.\n"
                "After the program is running, press \"Enter\" again to exit.\n", Inputs, &text[Inputs+3]);

    while(1)
    {
        //GPIOPinRead = 0 or GPIO_PIN_0
        if(!ROM_GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0))
        {
            UARTprintf("\n");
            break;
        }

        if(UARTPeek('\r') != -1)
            break;
    }

    ADC_Loop(freq);

    return(CMD_SUCESS);
}

  • Hi Helder,

    You might want to first try out the example shown in the TivaWare Peripheral Driver Library user's guide. The example is shown in page 313. There is also an example project under the TivaWare/examples/boards/ek_tm4c1294xl/hibernate.

    Is the interrupt only coming from Hibernate module and not others such as Timers? Have you tried to disable the Timers interrupt and see if it makes a difference?

    In the TivaWare user's guide for the Hibernate Module it says to call the HibernateRTCEnable() before using any of the RTC features. Currently you have ADC_InitHibernateRTC() called before ROM_HibernateRTCEnable(). Can you try to reverse them and see if they make a difference?

    Also in your HibernateRTCHandler() I wonder if it will make a difference if call:

    HibernateRTCMatchSet(0, HibernateRTCGet() + 60) instead of

    ROM_HibernateRTCSet(0);

    HibernateRTCMatchSet(0, 60);

    15.2.2.27 HibernateRTCEnable

    Description:
    This function enables the RTC in the Hibernation module. The RTC can be used to wake the
    processor from hibernation at a certain time, or to generate interrupts at certain times. This
    function must be called before using any of the RTC features of the Hibernation module.
  • Hi Charles Tsai,

    I'm not sure what happened, but after a quite a lot of tries, I've managed to make it work today, with the same code. Maybe the compiler was bugged until I restarted it?

    Charles Tsai said:

    Description:
    This function enables the RTC in the Hibernation module. The RTC can be used to wake the
    processor from hibernation at a certain time, or to generate interrupts at certain times. This
    function must be called before using any of the RTC features of the Hibernation module.

    From what I understood, this function must be called before using HibernateRTCGet() or HibernateRTCSSGet(). I was aprehensive about that, but it seems that the config functions are not affected. Perhaps this is something to be considered in the future TivaWare releases.

    Thanks for trying to help!