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 v 6.1.0.00104 and Timer module

Hi all,

 

I am using CCS v 6.1 and with TM4C123G development Board. Recently I wrote down a code to toggle LED at every 1 Sec with systick. It was working fine, then for some reason I had to reset my PC and had to reinstall CCS . I also updated CCS after installation.

Now the problem is, with the same program LED is toggling on every 3 sec rather than one sec. I tried with other timer modules as well by loading timer with  “SysCtlClockGet() -1” and getting the same results. Is my assumption is right that CCS is doing something wrong?

Below is the code.

------------------------------------------------

#include <stdio.h>

#include <stdbool.h>

#include <stdint.h>

#include "inc/hw_memmap.h"

#include "driverlib/gpio.h"

#include "driverlib/interrupt.h"

#include "driverlib/pin_map.h"

#include "driverlib/sysctl.h"

#include "driverlib/systick.h"

#include "driverlib/uart.h"

 

//*****************************************************************************

// Counter to count the number of interrupts that have been called.

//*****************************************************************************

volatile uint32_t g_ui32Counter = 0;

 

//*****************************************************************************

// The interrupt handler for the for Systick interrupt.

//*****************************************************************************

void SysTickIntHandler(void)

{

   g_ui32Counter++;

}

 

//*****************************************************************************

// Configure the SysTick and SysTick interrupt with a period of 1 second.

//*****************************************************************************

int main(void)

{

 

   // Set the clocking to run directly from the external crystal/oscillator.

   SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

   SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);

   GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);

 

   // Set up the period for the SysTick timer. The SysTick timer period will

   // be equal to the system clock, resulting in a period of 1 second.

   SysTickPeriodSet(SysCtlClockGet());

 

   // Enable interrupts to the processor.

 

   IntMasterEnable();

 

   // Enable the SysTick Interrupt.

   //

   SysTickIntEnable();

 

   // Enable SysTick.

   //

   SysTickEnable();

 

   //

   // Loop forever while the SysTick runs.

   //

   while(1)

   {

 

      if(g_ui32Counter >= 3)

      {

             // Read the current state of the GPIO pin and

         // write back the opposite state

         if(GPIOPinRead(GPIO_PORTG_BASE, GPIO_PIN_2))

             {

               GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0);

             }

             else

               {

                 GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 4);

               }

 

         g_ui32Counter = 0;

      }

 

   }

}