This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

CC1_CC8IC interrupt

Hello
can someone tell me why my interrupt does not respond, with the debugger, I always get z = 0

double z;

main {
.
.
.
.
.
.

while(1)
 {
CC1_M2      =  0x0001;//  001=>capture on posirtive Flanke
CC1_T01CON  =  0x0047;
CC1_CC8IC   =  0x00C0; // Interrupt enable und
z = Periode ;
 }//end of while
 }// end of main


 void Drehzahl_messung(void) interrupt(0x18)
  {

Periode = 100;
  }


or what I have since forgotten
Thanks

Parents
  • You do not understand why, because you have not spent the time reading our posts, or reading the C and/or C++ language standard or any good C/C++ programming book.

    The word volatile IS REQUIRED. With volatile specified, the main loop is required to always pick up the current value of the variable. Without the volatile keyword, the compiler MAY (but are not required to) pick up a changed variable.

    Right now, it is just a question of optimization and register allocations that controls if your program "works" or not.

    Are you satisfied with a program that "looks like it works", or do you want a program "that works"?

    Now, please do add the volatile keyword for any variable that is written to by an interrupt hander and that is read from outside an interrupt handler. If you have nested interrupts, then variables read in interrupt handlers may also require the 'volatile' keyword.

    An important difference for you to learn:
    - A program that is correct will produce correct results.
    - A program that produces correct results need not be correct. You might just have failed to find the combination where it will produce incorrect results.

Reply
  • You do not understand why, because you have not spent the time reading our posts, or reading the C and/or C++ language standard or any good C/C++ programming book.

    The word volatile IS REQUIRED. With volatile specified, the main loop is required to always pick up the current value of the variable. Without the volatile keyword, the compiler MAY (but are not required to) pick up a changed variable.

    Right now, it is just a question of optimization and register allocations that controls if your program "works" or not.

    Are you satisfied with a program that "looks like it works", or do you want a program "that works"?

    Now, please do add the volatile keyword for any variable that is written to by an interrupt hander and that is read from outside an interrupt handler. If you have nested interrupts, then variables read in interrupt handlers may also require the 'volatile' keyword.

    An important difference for you to learn:
    - A program that is correct will produce correct results.
    - A program that produces correct results need not be correct. You might just have failed to find the combination where it will produce incorrect results.

Children
  • First, thank you for this honest response
    I have already read c programming. but sometimes I do not really understand the meaning of things.
    but I am now convinced. with what you have written me. the two sentences were convincingly

    
    An important difference for you to learn:
    - A program that is correct will produce correct results.
    - A program that produces correct results need not be correct. You might just have failed to find the combination where it will produce incorrect results.
    
    

    I will write now my code with volatile

    many thanks