Jump to content
43oh

Learning Interrupts


Recommended Posts

I am learning MSP430 programming with the tutorial at http://mspsci.blogspot.com/2010/07/tutorial-01-getting-started.html. I had trouble getting one of the first interrupt-driven programs to work, so I debugged it by adding a write to a RAM location to the interrupt service routine. Then I could see (by printing out that location with mspdebug) whether the ISR was ever entered. Indeed, the reason that program did not seem to run at all was precisely that the ISR was not entered.

 

Now I have progressed to CMeterG2211.c and wanted to use the same trick (if it can be called that). There are three ISR's and, correspondingly, I added three global variables at the start of the C file, like this:

unsigned char mark1 = 0;
unsigned char mark2 = 0;
unsigned char mark3 = 0;

I also added something like this

 mark1++;

at the start of each ISR.

 

Now, the program worked almost out of the box, and there has been no particular need to debug it. However, out of curiosity, I checked the markx variables after a successful run and found them all to be 0 (zero). How can that be? The fact that the program runs OK must indicate that all the ISR's are entered at least once, so how can the variables still be zero?

 

Link to post
Share on other sites

My first thought would be to agree about the use of volatile. External variables should be treated as volatile by default, but not all compilers do.

 

My next thought would be that a reset is being done before you are looking at the values. Can you watch the vlue during operation?

Link to post
Share on other sites

 

My first thought would be to agree about the use of volatile. External variables should be treated as volatile by default, but not all compilers do.

 

My next thought would be that a reset is being done before you are looking at the values. Can you watch the vlue during operation?

 

 

 

No, I am not familiar enough with the debugger, at least not yet.

 

The program sits in an infinite loop waiting for interrupts. First, it is the button that starts the measurement. Then, it is overflows from TIMER0 while the capacitor is charged. Last, the interrupt is from TIMER1 when the capacitor voltage falls to 0.25VREF. Then the loop restarts - there does not seem to be a reset.

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...