CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Timer 1 problem with re-entrancy

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ömer Faruk



Joined: 15 Nov 2018
Posts: 42
Location: Çanakkale

View user's profile Send private message Send e-mail

Timer 1 problem with re-entrancy
PostPosted: Sun May 19, 2019 4:34 am     Reply with quote

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: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun May 19, 2019 4:40 am     Reply with quote

Not on my 'PIC PC' so I can't copy and test but...
have a look here..
http://www.ccsinfo.com/forum/viewtopic.php?t=26177
.. It's a RTC based on Timer1 and it works !
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sun May 19, 2019 7:04 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu May 23, 2019 8:51 am     Reply with quote

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 .
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group