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.

Calculating delay



At first, I posted this question in Clock and Time forum then was asked to move here.


I am practising with Tiva C TM4C123G Launchpad. On page 4-15 of Lab Manual, I have to calculate Delay via programming but my concepts are not very clear, so I want someone help me to calculate delay manually (on a paper) for better understanding that what's going in background. Precisely, I want to imagine how MCU is calculating delay.

Thank you.

  • Anyone here who can help me out? Thanks.
  • Hi,

    First if I am not mistaken this is to blink an LED inside the handler?
    It's to "schedule" a task to happen every 0,1s - the 10Hz, right?
    Either way here is how that math works.

    Now imagine your System clock is a imaginary 1000Hz=1Khz.
    Now your timer works with the system clock speed, so also 1Khz. With this you know that each increment on the timer counter means 1/1000=0,001s has passed.
    You want the 10Hz interrupt rate then you do 0,1/0,001. This is how many value you need the timer to count so it passes the 0,1s.
    So the math is:
    (Period)/(1/SysClok) = (1/Frequency)/(1/SysClok) = SysClock/Frequency.


    Do you understand how the timer counts time now?


    Edit:
    Ah and about the objective proposed on the lab. I went ahead and checked it out and read with more attention.
    So the idea is to basically generate a PWM. It's 10Hz and 50% so it needs to toggle the LED at a rate of 20Hz (at the start of the 10Hz wave period and at the middle).




    If you really want to make a delay check this code example for how to set up a timer to track time in milliseconds and implement a delay function with the help of that time tracking.
    Later I advise you using the Systick Timer for that purpose. I advise you looking into it after you completer the chapters about the timers. 


  • You state that you seek guidance to, "Precisely imagine" - yet you don't define "precisely" nor your "imagination bounds nor process."   And - is not a word like, "precisely" a tad too harsh, too restrictive - for a free, voluntary response forum?   How ever would we know what you'll accept as adequately, "precise?"

    Words have meaning - many new posters don't spend enough time/effort in their composition - and (most often) this same "lack of clarity" inflicts other areas of their school, work, or home life.  (perhaps worth consideration...)   Run a small tech firm - see this often - offer this not to "beat you up" - but to provide guidance...

    Part of your confusion - imho (not too humble) is the fact that the hallowed lab violates KISS.   (too much, too soon - defeats singular focus)   I'd never mix GPIO, Timer & PWM in a "single go."  That's confusion-central - I understand "why" lab producers (likely) did that - but it's not ideal - causes much of your uncertainty.

    Poster Luis did a nice job of detailing for you - yet (again) I'd stick w/one subject item at a time.   When learning "Timers" we always start by requiring our new hires/interns to master simple GPIO first.  GPIOs may be inexpensively & efficiently observed/monitored via an Led(s).  Once you've mastered GPIO - only then would I open MCU manual to Timers - and slowly, methodically - starting w/easiest timer mode - start writing focused, timer code. 

    There's a "catch" there too - most often Timers require your understanding of interrupts - again not especially simple - and w/many pitfalls.  However - it should be possible for you to avoid interrupts - and simply "read" the proper Timer Registers - and take action (on/off GPIO controlled LED) based only upon the Timer Register's value!   Often this works best w/"slowed" system clock - and the largest Timer values - so that your "timer delay" is not too brief...

    Lot of detail here - suspect several readings will be required - although none are demanded to be, "precise."