Jump to content
43oh

Basic timer usage


Recommended Posts

I want to "clock" how many cycles it takes for my code to get from line x to line y.  Could someone please advise me on how to set this up.  I've tried 

TACTL = TASSEL_2 + ID_0 + MC_0;   // Set up source (SMCLK), divider (1), timer halted
 
  
TACTL = MC_2;                     // Start timer in continuous mode
__delay_cycles(2345);           // Do stuff 
x=TAR;                          // Copy timer register into x 
TACTL = MC_0;                   // Stop timer

 

As it stands, x always has a value of 0.

 

Obviously I'm missing important code, but I don't know what.  Code examples I've seen use external signals, but I want this to measure from internal states.

 

Any help?  

 

I can't really use an IDE function to do this, as I'm wanting to measure the clock cycles between sending a message over RF, then receiving an acknowledge.

 

What I want to do in pseudo code.

 

1.  Start timer

2.  Tx over RF

3.  Rx Acknowledge

4.  Stop timer

5. Read timer.

 

Thanks in advance :smile:

Link to post
Share on other sites

when you set  "TACTL = MC_2;"  you are setting the entire 16 bits...  so you are in effect turning off the flags you set earlier, and TASSEL = 0 (what you are setting it back to) is looking for the TACLK signal which is an external pulse, so your timer is never pulsing

 

for that same reason, use | when setting multiple flags to prevent some strange behavior sometimes. 

TACTL = TASSEL_2 | ID_0 | MC_0;

 

try writing it with a |=    (or equals)  so that you are only affecting the bits you want and leaving the rest alone

 

"TACTL |= MC_2;"   (enable timer, while leaving other bits alone)

"TACTL &= ~MC_2;"   (disable timer, while leaving other bits alone)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...