View previous topic :: View next topic |
Author |
Message |
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
Timer 1 problem with re-entrancy |
Posted: Sun May 19, 2019 4:34 am |
|
|
Hello all,
I am having problem with interrupts disabled during call to prevent re-entrancy in Timer1 code. This is my code:
Code: |
float toplam1=0;
float sicaklik = 0;
#int_timer1
void timer1_kesme (void)
{
set_timer1(1);
if(++second_val == 10)
{
second_val = 0;
//if(minute_val == 0) ilk_sicaklik = sicaklik;
//toplam1 = toplam1 +sicaklik;
if(++minute_val == 64)
{
minute_val = 0;
//if( (toplam/64)< sicaklik) heat_error = 1;
}
}
}
|
Why this is happennig ? Timer1 ticks in 0.262 second. If i take out the // part from the code i got no warning. I need your help.
Last edited by Ömer Faruk on Sun May 19, 2019 4:46 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sun May 19, 2019 7:04 am |
|
|
The problem is using floats.
Float arithmetic is large, and slow. It is all dependant on code libraries
(no hardware instructions).
So having 'float' additions in your code means any other float additions
in the code will trigger the interrupt disabled warning.
As PCM_programmer says, look at the library code which does the
adaption to give accurate times 'sneakily'.
If you feel you must use a equivalent to your code, then use int32
instead of float, and add a uSec value in integer.
Remember though this is only a _warning_. It is saying "you might
want to re-think what you are doing", but it will still work. It means the
handling of the Timer1 interrupt will be delayed to after each float
addition in the main code completes. |
|
|
Ömer Faruk
Joined: 15 Nov 2018 Posts: 42 Location: Çanakkale
|
|
Posted: Thu May 23, 2019 8:51 am |
|
|
Ttelmah wrote: | Remember though this is only a _warning_. It is saying "you might
want to re-think what you are doing", but it will still work. It means the
handling of the Timer1 interrupt will be delayed to after each float
addition in the main code completes. |
You are right my code works well despite the warnings . |
|
|
|