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.

TM4C129 System Tick

So i wanted to make sometigh to keep track of time, almost like a RTC but in mili-seconds and maybe even micro-seconds.

I never done sometigh like that with the timers so i started reading and decided to try to use System Tick since it seemed realy easy to implement.

My question is, is this a bad usage of System Tick? am i in some way, i guess hurting my uControler run time and interrupt execution?

i use the folowing to just get some kind of delay. No i don't like SysCtlDelay();, Also i itend to use this to check time lapses

void SysTickbegin(){
  SysTickPeriodSet(120000);
  SysTickIntRegister(SycTickInt); 
  SysTickIntEnable();
}


void SycTickInt(){
  milis++;
}


void Wait(int time){
  milis=0;
  while(milis < time);

}

  • Hello Luois,

    It is ok to use the SysTick Timer the way you have mentioned. If the accuracy is a concern then I would suggest using the Hibernate RTC block which works on 32KHz and gives 30us timer resolution. The value read from it an be converted to the time w/o the requirement for a SysTick Interrupt Handler.

    Regards

    Amit

  • I was just needing that 1 milisecond delay wasn't 5 milisecond. Sometimes i would even get 3 second delay istead of 1 second delay with the  SysCtlDelay()

    I'm begining to work with TivaWare so that kinda of implementation with the RTC will have to wait 

    Thanks

  • Hello Luois,

    When using the SysCtlDelay, the actual delay would be different based on the System Clock Frequency. The minimum delay is 3 times the value programmed in the SysCtlDelay.

    Since you are a beginner on TIVA, a SysTick would do as well. Hibernate would be more accurate and less cumbersome in the long run.

    Regards

    Amit

  • yes but systemclock depends alot on interrupt enviroment for what i read.

    i did the math, 1/CPUfrequency*3 to know the time of each value but i still was just to inacurate.

  • Hello Luois,

    No. The System Clock does not depend on the interrupt environment,

    For SysCtlDelay the calculation is not correct as with change in wait state at higher frequency and placement of the code in the Flash, there would be certain additional penalty. I would suggest you go ahead with the SysTick Method.

    Regards

    Amit

  • Thank you for the info. Always a great help

  • I got the RTC clock to work, the TivaWare actualy makes it quite easy. Thanks for the sugestion. 

  • Hello Luois,

    Yes, the TIVAWare makes some of these lesser known items very easy to integrate. Also using the RTC has a clear advantage of reduced interrupt overhead.

    I wish I2C would be resolved that fast.

    Regards

    Amit

  • Amit Ashara said:

    I wish I2C would be resolved that fast.

    Do not we all friend Amit - do not we all...  (the "special I2C handling" demanded by this new, 129 device is especially disturbing)

    Your 2nd post this thread rated, "most excellent" by our small, tech group.   You addressed poster's specific issue - then, "alerted" to a "special/advantaged" MCU feature (better able to manage poster's need) and then you outlined that feature's, "care/handling."   Good,caring stuff - appreciated...

  • Belive me when i say all this is being solved, answered or  simply brought into atention realy fast.

    In other platforms (arduino and other ineficient coding is out of the equation) any of this would take forever. I am learning more and faster than most of my colegues that are 3-4 years above me in college due to all this information and support.

    Altough i got to say that some facts about this calendar mode should be more clear. AT least to me it wasn't clear to me that the "tm" struct type was a alredy defined one or we had to define it, and to look into driverlib source files to find out. Also i found out that by default the hour was 26h. It was just the default, if you set it below 24 (in 24hr mode of course) the driverlib would automaticly limit it to the 24h limit

    Also didn't find any example codes about it so here it is in case anyone tries to search:

    /*
    
      Code made with energia-0101E0012
    
      This code is suposed to help clarify anyone with doubts of how to use very basic fuctions of the RTC
      in the hibernation peripheral and also the hardware calendar mode. Any sugestions and improvements are always welcome
      
      This example only changes and show hour, minutes and seconds but there's:
        psTime->tm_min
        psTime->tm_sec 
        psTime->tm_mon 
        psTime->tm_mday 
        psTime->tm_wday 
        psTime->tm_year
        psTime->tm_hour
    
    */
    #include "driverlib/hibernate.c"
    
    
    void HibernateHandler(void)
    {
      //Use this to reset interrupt flag
      uint32_t ui32Status = HibernateIntStatus(1);
      HibernateIntClear(ui32Status);
      
      //Place here code to execute every second, ex: LCD or 7 segment display
      //Altough it should be as fastest as possible
      
      
      //To keep the interrupt hapening every second you need this
      HibernateRTCMatchSet(0,HibernateRTCGet()+1);  
    }
    
    /*It's need a struct pointer of the type "tm" so i use new to do that. This type of struct is defined in the driverlib/hibernation
      you could also create it like this: tm temp; and then use &temp and temp.values in the fuctions                              
    */
    tm *temp = new tm;
    
    
    
    void setup()
    {
      Serial.begin(9600);
      // put your setup code here, to run once:
      
      //Enable Hibernate peripheral. I'm using Energia so i use F_CPU for geting the clock frequency
      HibernateEnableExpClk(F_CPU);
      HibernateRTCEnable();
      
      //We set a interrupt for the RTC after second. You can change the value
      HibernateRTCMatchSet(0,HibernateRTCGet()+1);
      HibernateIntRegister(HibernateHandler);
      HibernateIntEnable(HIBERNATE_INT_RTC_MATCH_0);
      
      //Set up calender mode. HibernateCounterMode() is always needed but can be set to 12hr mode
      HibernateCounterMode(HIBERNATE_COUNTER_24HR);
      HibernateCalendarSet(temp); //<-- the struct declared
      
      //We change the hour, minutes and seconds
      temp->tm_hour= 23;
      temp->tm_min=59;
      temp->tm_sec = 50;
      //This fuction below is what actualy updates the values inside the peripheral. 
      //if you don't use it, the value changes above won't do anytigh
      HibernateCalendarSet(temp);
      
    }
    
    void loop()
    {
      //This is to take the "live" values that the RTC keeps updating into our struct
      HibernateCalendarGet(temp);
      Serial.print(temp->tm_hour);
       Serial.print(':'); 
       Serial.print(temp->tm_min);
      Serial.print(':'); 
      Serial.println(temp->tm_sec);
      delay(1000);
    }

  • Hello cb1,

    The MasterBusy was a hindsight to the implications that running at higher frequency with a low baud rate brought out. But actually I2C on TM4C129 is better due to FIFO and DMA capability. This is in addition with more sources of interrupt makes implementation of I2C Peripheral handler better. But then this is my "vendor" view.

    Thanks for the appreciation.

    Regards

    Amit

  • Since we're bringing i2c here... i was going to do only FIFO implementation, but first i wanted to go here and check if i was going to waste time if i only needed basic fuction. Thanks for reminding me about that