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 interrupt issues PCM - but really all pics

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



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

timer interrupt issues PCM - but really all pics
PostPosted: Sat Jun 06, 2009 8:10 am     Reply with quote

Is there a way to RELIABLY manage MORE than an int8 time keeping variable - with an interrupt based timer?

I have happy been using a timer0 -interrupt based timer that updates a SINGLE byte quantity at a 10 mSec rate - the high level 'user' functions must poll often enough to know how many "ticks' have elapsed.
BUT
I can't think of a way to SAFELY use an int32 counter for the same purpose ,
due to the certainty that timer0 interrupts will occur DURING the high level function calls, trying to READ the multi byte format -and change the bytes of the long integer - as they are being read .

This sort of thing was EZ to solve in the 808x environment I was used to in a former life - is the same sort of code needed here ?

ie disabling the timer0 int - copying my timer int32 counter to a temp var - and then re enabling the timer ints ( what I did in PC assembler)

Is there an elegant - simple solution I should know about ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Jun 06, 2009 9:07 am     Reply with quote

There is a pretty easy means, that is generally used in all similar cases, where consistency of data structures across interrupt calls is an issue: Disabling interrupts temporarily, either globally or the respective conflicting one.
Ttelmah
Guest







PostPosted: Sat Jun 06, 2009 10:10 am     Reply with quote

Yes. the 'normal' method, is to have a variable used only in the interrupt handler, and a 'copy', used by the external routines.
Code:


disable_interrupts(global);
local_tick=timer_tick;
enable_interrupts(global);
//work using 'local_tick' here.


I also, if using a 'fast' tick, will still only update an 8bit value in the interrupt, then instead of the above code, use:
Code:

disable_interrupts(global);
if (local_tick > timer_tick)
   ++local_msb;
local_tick=timer_tick;
enable_interrupts(global);


This way there is still only an 8bit counter in the timer, while the main code has a 'tick', and an extended counter. Often I'll create a union, so that I have (say), an 8bit 'tick', and a 16bit extended counter, stored in a 32bit value, to give 24bits useable, without using 32bit arithmetic.

Best Wishes
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