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.

TM4C123GH6PM: if statement causing a fault

Part Number: TM4C123GH6PM

Tool/software:

Hi,

My if statement is causing a fault when a Timer0A interrupt is implemented (but not enabled yet). Whenever the below if-statement is checking if ADCvoltage is >= 939, it enters the FaultISR, but it works fine when I comment out the following code (Timer0Init and Timer0IntHandler) for Timer0A interrupt. 

void Timer0Init(void){
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);

    uint32_t ui32Period = (80000000/10);
    TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period - 1);

//    NVIC_PRI4_R = (NVIC_PRI4_R & 0x00FFFFFF) | (7 << 29);

    IntEnable(INT_TIMER0A);
    TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    IntMasterEnable();

    TimerEnable(TIMER0_BASE, TIMER_A);
}

void Timer0IntHandler(void) {
    // Clear the timer interrupt
    TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);

    counter++;

    if (counter == 1 | counter == 2) {
        // Perform the action for 0.1 seconds
        SPIWritePacket(0x10, 0x03, PrevChannelStatus | BUZZER_FAST_ON);                      // Buzzer (fast) On
        PrevChannelStatus |= BUZZER_FAST_ON;
    } else if (counter == 3) {
        SPIWritePacket(0x10, 0x03, PrevChannelStatus & ~(BUZZER_FAST_ON));                      // Buzzer (fast) On
        PrevChannelStatus &= ~(BUZZER_FAST_ON);
    } else if (counter >= 20) {
        counter = 0; // Reset the counter every 2 seconds
    }
}

    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // System clock: 16*12.5/2.5 = 80MHz (MAX)

    ui32PWMClock = SysCtlClockGet();                                        // PWM clock is SysClk
    ui32Load = (ui32PWMClock / PWM_FREQUENCY) - 1;                          // Calculate load value

    InitOE();
    InitSPI();
    InitADC();
    InitUART();
    InitPWM(ui32Load, 0);                    // Duty Cycle = 0 initially
    MagneticInterlockTest();
    OverrideTest();


    while(1){
        tempC = GetInternalTemp();
        tempF = (1.8 * ulTemp_ValueC) + 32;                            // Celsius to Fahrenheit

        ADCvoltage = GetVoltage();                                     // For solenoid lock
        ambientTemp = GetTemp();
        fanSpeed = GetFanSpeed();

        IntToFloatVolt(ADCvoltage);
        IntToFloatTemp(ambientTemp);

        MagneticInterlockStatus = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_6);
        OverrideStatus = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5);

        if(ADCvoltage >= 939){                           // this causes fault                                        // 939/4095 * 3.3 = 0.7567V (About 55V in a 1500V scale)   // Voltage >= 55V
            if(MagneticInterlockStatus & GPIO_PIN_6){                                           // Enclosure closed
                if(OverrideStatus & GPIO_PIN_5){                                                // Override On (Enclosure was open & Override is enabled)
//                    Timer0Init();
////////////////////////////// omitted
}

What's the issue here?