G'day Peter, On My system I have a 5mS timer int setup. All that this does is increment a counter, and provide a wakeup if required. Most of the fast routines are not critical when they occure but must be executed. Eg a RTC keeping time.
In my general service routines I then perform the timer function counter times. As a general rule I keep all my interrupt functions really short and service them in my main loop via an "event" This allows for longer routines to be performed without, missing the faster timer event. Here are my functions so that you can get the general Idea. :) /**************************************************************************/ /* Name :Timer_A_i */ /* Parameters :void */ /* Returns :void */ /* Scope : interrupt[TIMERA0_VECTOR] */ /* Function : Will increment the timer tick. */ /* */ /* NOTE : THE INT WILL EXIT THE CURRENT LPM MODE */ /*------------------------------------------------------------------------*/ interrupt(TIMERA0_VECTOR) wakeup Timer_A_i(void) { TACTL &= ~TAIFG; /* reset the flag */ TACCTL0 &= ~CCIFG; /* reset the ccr0_i_flag */ CCR0 += TIMER_TICK; /* Set the new time interval */ timer_tick++; /* increment timer ticks */ } /*------------------------------------------------------------------------*/ /* End of Function: Timer_A_i */ /**************************************************************************/ Called from The main loop after wakeup /**************************************************************************/ /* Name :100ms_event */ /* Parameters :void */ /* Returns :void */ /* Scope : Timer Interrupt will set the timer tick counter */ /* Function : To process ALL the 100mS_timer for EACH TIMER TICK */ /*------------------------------------------------------------------------*/ void ms100_event(void) { unsigned int tmr_cnt; /*----- counter increments in Int(f) -------------------------------------*/ if( timer_tick > 0 ) { while( timer_tick > 0 ) /* Done for all timer counts */ { timer_tick--; /*------------------------------------------------------------------------*/ tmr_cnt = 0; while ( tmr_cnt < MAX_100MS_TIMER ) { if ( ms100_timer[tmr_cnt].timer_ID > FREE_TIMER ) { if (--ms100_timer[tmr_cnt].timer == 0 ) /* timer just expired */ { ms100_timer[tmr_cnt].time_out_fp(); /* Timer calls f() direct */ // set_event( ms100_timer[tmr_cnt].timer_ID, ms100_timer[tmr_cnt].time_out_fp ); /* Place f() onto event_que */ ms100_timer[tmr_cnt].timer_ID = FREE_TIMER; } } tmr_cnt++; } } } } /*------------------------------------------------------------------------*/ /* End of Function: 100ms_event */ /**************************************************************************/ /*- main Loop -------------------------------------------------------------*/ while(1) { ms100_event(); /* Service timers */ do_events(); /* Process all events on the Q */ LPM3; /* Low power mode 3 */ _NOP(); /* Required only for C-spy */ } Hope this is of help to you. Regards Mike Kroon -----Original Message----- From: Bill Knight [mailto:bi...@rosw.com] Sent: Wednesday, 26 November 2003 7:54 AM To: mspgcc-users@lists.sourceforge.net Subject: Re: [Mspgcc-users] multitasking On Tue, 25 Nov 2003 21:05:24 +0100, Peter Mueller wrote: Hi all, I have the problem that I need two background tasks. The first task has a cycle time of 10 ms, the second one of 1000ms. In the second task I want to execute a complex algorithm taking much longer than 10ms. Therefore it is not possible to run both in a while(1) loop. One way to solve to problem would be to break the algorithm up into short chunks to be able execute the faster task in time, which I would not like to do (if possible). Is there a good way to solve this problem without an OS? Is there a simple scheduler available? Peter uC/OS-II is available for the MSP430. There are others but I am not familiar with their capabilities. uC/OS-II is a preemptive RT kernel, but the last time I looked it did not support cyclic timers. To work around that problem you could create 3 tasks; a timer task, a 10 ms task, and a 100 ms task with priorities descending in that order. The timer task (highest priority) would (re)schedule itself to run every 10 ms. It would wake up the 10 ms task each time it ran and would wake up the 100 ms task every tenth time it ran. The reason to use a seperate timer task is to keep it short so the 10 ms period accuracy is maintained. I realize this explanation is awkward but hopefully close enough to follow. I'm also sure others with have a number of reasonable suggestions. Regards -Bill Knight R O SoftWare ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Mspgcc-users mailing list Mspgcc-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mspgcc-users