Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:52:41+00:00 2026-06-11T14:52:41+00:00

I have a while loop implemented in C for an MSP430 processor that currently

  • 0

I have a while loop implemented in C for an MSP430 processor that currently looks like this:

register unsigned int sw_loop_count = 0U;
...

while (TACCL0 & CCIE)
{
    ++sw_loop_count;
}

...
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A(void)
{
    // Disable the timer interrupt flag and enable.
    TACCTL0 &= ~CCIFG;
    TACCTL0 &= ~CCIE;
}

I’m using this loop for calibration purposes, the context of which I don’t think matters too much for my question. I’ve calculated that each iteration of the loop, including the check TACCL0 & CCIE takes 11 clock cycles. For purposes of granularity, I would really like to get this number as low as possible, and programmatically if possible. I might be being a complete moron, but I can’t think of a way of reducing the cycle count for the loop, so any advice would be appreciated. I need the sw_loop_count value, one way or another.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:52:42+00:00Added an answer on June 11, 2026 at 2:52 pm

    Hmm, after I put a comment I realized that there may be something you can do 😉 In your while() condition you are checking two values. From the looks of it both those values must be defined as volatile so that they are ready from memory every single time they are used…

    Can you reduce those two into a single one? Have your interrupt handler do the necessary comparison and set a single flag that you will be checking in your loop.

    Or you can get really fancy and do it another way around, like that:

    // signed and global (or you can pass it's address into your interrupt's routine)
    volatile signed int sw_loop_count = 0;
    

    Then there’s your “measurement” loop:

    while(++sw_loop_count) {}
    

    and in your interrupt routine:

    if(TACCL0 & CCIE)
    {
      real_count = sw_loop_count; // save the value for future use before we destroy it
      sw_loop_count = -1; // this will turn into 0 in that while's pre-increment, ending the loop
    }
    

    OTOH… introducing the volatile may get so much hit from memory access that it may in fact slow down the while() loop. It really does all depend on your actual architecture (down to what type of memory controller and cache controllers there are) and I still maintain that you may be better off running it through an assembler mode and looking at what the compiler is doing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function creating entries via grid() like this: (replace while-loop with function,
I have a while loop that goes while a BuffedReader still has data, what
I have a while loop that loops through 3 results and echo's these out
So with pygame you have a while loop that loops continuously, then your event
Currently, I have a while loop for listening the port. When a socket accepta
I have a script that uses a simple while loop to display a progress
I have implemented a simple server-client script like this: Server: class Server(Protocol): def connectionMade(self):
I have a while loop that decodes a video file by retrieving each frame,
The while loop I have while reading in from a file doesn't break. I'm
hi i have a while loop: var i = 0; while(i < 20) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.