We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
oh yes, I have forget to include <intrins.h> I just have to try again .. but I have the variable as declared.
unsigned int Timer_alt; unsigned int Timer_Diff; double periode;
and it works I must write my program as Portila ? I will understand why when the works anyway? and apologised if I ask so many!
Thanks for the explanation
It works because reading the 16-bit value of Timer_Diff is atomic by the processor design. If you had a 32-bit value which you modify in the interrupt and read in the main loop, that would most certainly not work as it does now.
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.
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
I will write now my code with volatile
many thanks