• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » MSP430™ Microcontrollers » MSP430 Ultra-Low Power 16-bit Microcontroller Forum » interrupt serving process
Share
MSP430™ Microcontrollers
  • Forum
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
MSP430 Resources
  • MSP430 Product Folder
  • MSP-EXP430G2 - MSP430 LaunchPad Value Line Development kit
  • MSP430 Getting Started Guide
  • MSP430 Microcontroller Projects
  • More Resources >
  • interrupt serving process

    interrupt serving process

    This question is answered
    Carloalberto Torghele
    Posted by Carloalberto Torghele
    on Apr 13 2012 07:26 AM
    Intellectual685 points

    Hi.


    I'm using a MSP430F5308.

    If I enable the interrupt for a timer with an assignment like:
    TA1CCTL1 = CCIE;   // istruction A (it also clear CCIFG)

    can i avoid to clear the interrupt flag with

    TA1CCTL1 &= ~CCIFG;

    before instruction A?

    With istruction A, are all TA1CCTL1 bit get updated all together?

    Do interrupt get accepted in synchrony with MCLK? I think that they are accepted asynchronaly because when you are in Low Power MCLK could be off.

    I know that when an interrupt is accepted, any currently executing instruction is completed before serve the interrupt. But can an interrupt be accepted asynchronaly in the middle of a MCLK clock period (and actually served at the end of the current istruction)? In that case, if during the execution of istruction A, CCIE is set a little bit before CCIFG get cleared, i can get a unwanted interrupt.

    I know that everything it's a little bit confused but i can not think a proper answear about that.


    Regards,

    Carloalberto

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Jeff Tenney
      Posted by Jeff Tenney
      on Apr 13 2012 11:12 AM
      Verified Answer
      Verified by Carloalberto Torghele
      Guru10805 points

      Hello Carloalberto,

      Yes, you can use instruction A to both clear and enable the interrupt.  You do not need to clear CCIFG first.

      Assuming CCIE was clear before that instruction, you will definitely not get a TA1CCTL1 interrupt at the end of that instruction.

      Carloalberto Torghele
      if during the execution of instruction A, CCIE is set a little bit before CCIFG get cleared, i can get a unwanted interrupt.

      No, that can't happen.  There is no race condition between the clearing CCIFG and setting CCIE as long as both occur on the same MCLK edge.

      Interrupts are accepted on MCLK edges.  When considering low-power modes, it helps to remember that an active interrupt request actually enables MCLK.

      Here's an example for you to consider.  Let's say CCIFG is already set, and we do this:

          TA1CCTL1 |= CCIE;
          NOP();

      The ISR doesn't actually execute until after the NOP.  You can't enable the interrupt and acknowledge it on the same MCLK edge.

      Now consider another example.  Let's say again that CCIFG is already set, and we do this:

          TA1CCTL1 |= CCIE;
          TA1CCTL1 &= ~CCIFG;

      The interrupt still happens after the CCIFG instruction!  The CPU has already decided to acknowledge the interrupt.

      Hope that helps.

      Jeff

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Apr 13 2012 11:25 AM
      Verified Answer
      Verified by Carloalberto Torghele
      Guru140650 points

      with
      x=y;
      you assign the complete value y to the variable or register x, overwriting all bits in teh target.

      if you just want to set a single bit, leaving the others untouched, use
      x |= y; (it sets all bits in x that are set in y, but doesn't clear bits in x which aren't set in y. This is a logical OR operation and is performed as a bit set instruciton (BIS) by the processor.

      The opposite is the bit clear (BIC) isntruction, which does not have a direct coutnerpart in C.
      The logical AND operation (& or &=) clears all bits that are not present in both operands. However, it can be achieved by binary inverting (~) y first, so all bits are set except the onces in Y, before performing the AND. This way all bits in x remain untouchedexcept for the ones that were set in y.

      Carloalberto Torghele
      Do interrupt get accepted in synchrony with MCLK? I think that they are accepted asynchronaly because when you are in Low Power MCLK could be off.

      Well, they are accepted asynchronous. But once accepted, tehy are executed synchronous to MCLK (after all, it is the CPU which has to perform them, and even fetching the ISR address msu tbe done through the memory bus and therefore synchronous to MCLK).
      It may happen that an interrupt is accepted, but when the ISR is actually called, the IFG bit that caused the interrupt is already clear again. A typical applicaiton where this may happen is the I2C bus.
      Also, if you write to a register that clears the IE or IFG bit, the interrupt may have happened before the processor has finished, the interrupt is accepted and the ISR is executed despite the fact you just cleared the bits and therefore disabled the interrupt.
      In case of GIE, where the target is a register, the next isntruction is already fetched before GIE is actually cleared, so an interrupt may happen after the next isntruction. Hence the NOPs in many source codes after clearing GIE.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Carloalberto Torghele
      Posted by Carloalberto Torghele
      on Apr 20 2012 03:17 AM
      Intellectual685 points

      Thank you all for your reply.

      Therefore i can be sure that it is not dangerous to clean IFG flag and enable the interrupt in the same assignment.

      To be clear:

      suppose that CCIFG is set in TA1CCTL1 and that i want to enable CCIE but that i want to service an interrupt just for a event that will follow the interrupt enable instruction.

      I can do

      TA1CCTL1  = CCIE;    // zzz

      and be sure that even if CCIFG was set before zzz, there will not be any interrupt (until another future event will trigger it).

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Apr 20 2012 07:56 AM
      Verified Answer
      Verified by Carloalberto Torghele
      Guru140650 points

      Carloalberto Torghele
      I can do
      TA1CCTL1  = CCIE;    // zzz
      and be sure that even if CCIFG was set before zzz, there will not be any interrupt (until another future event will trigger it).


      Yes.
      In theory, there might be a small timeframe (a racing condition) that may cause the system to assume an interrupt while the new values are written, but this happens at a moment when the CPU won't accept an interrupt anyway. When the CPU is checking for a pending interrupt, this moment is long gone, so it is safe.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Carloalberto Torghele
      Posted by Carloalberto Torghele
      on Apr 26 2012 01:10 AM
      Intellectual685 points

      Jens-Michael Gross

      Yes.


      Perfect :-)

      Jens-Michael Gross

      In theory, there might be a small timeframe (a racing condition) that may cause the system to assume an interrupt while the new values are written, but this happens at a moment when the CPU won't accept an interrupt anyway. When the CPU is checking for a pending interrupt, this moment is long gone, so it is safe.

      Do you now where can I read a detailed explanation about all this things? The mcu reference manual doesn't go in detail.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Apr 26 2012 11:01 AM
      Guru140650 points

      Carloalberto Torghele
      Do you now where can I read a detailed explanation about all this things

      This is ratehr low-level microcontroller design than MSP specific.

      Carloalberto Torghele
      The mcu reference manual doesn't go in detail.

      Indeed. And in the very most cases you don't need this information at all. However, much can be 'read between the lines'. And more becomes obvious as the only available explanation when you look at the available description and compare it against each other or the documented errata.

      After all, the MSP is no consumer product (even if it is used in consumer products). Remember, 'engineer' comes from 'ingenious' and not from 'engine operator' :)

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Carloalberto Torghele
      Posted by Carloalberto Torghele
      on Apr 27 2012 02:05 AM
      Intellectual685 points

      I know that it's low level mcu design and probably I will never really need this information.

      But It was just for curiosity. Of course I have some guess about it, but it'd like to read something "official" and reliable.

      Anyway, I can imaging that there is not any document that explain low level implementation in detail. I have just tried.

      Thanks for everything!

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Apr 27 2012 08:14 AM
      Guru140650 points

      Carloalberto Torghele
      I know that it's low level mcu design

      Actually, it goes even deeper: synchronous and asynchronous digital logic design. Which is where microcontrollers are based on.
      At university, we once did a 4-bit microcontroller based on plain standard TTL chips and an EEPROM for the microcode. It had 16 instructions including addition and conditional brancing, and the wire-wrapped design worked with >100kHz clock speed. It didn't provide interrupts/stack, but it was a good starting point to thing about the basic design and internal relations of a CPU.
      (note, this was just an execise during digital electronics course, not a "final project" or such.)

      Carloalberto Torghele
      But It was just for curiosity

      Curiosity is the main source for discoveries, while lazyness is the main source for inventions. (this one is from me, but Konrad Zuse once stated that he invented the compuer because he was too lazy to do all those calculations by himself over and over again)

      Carloalberto Torghele
      I can imaging that there is not any document that explain low level implementation in detail.

      There certainly is one! Deep in the drawers of the engineers who designed the MSPs. And of course not meant for the public. :)

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use