Here is a very brief manual for Queued Task Manager, aka qTask (C) Copyright 2009, michael bradley, mbradley@mculabs.com This code is written for the CCS C compiler for the PIC line of micro controllers First thing first, in your source, we need to define a few items before we include the qtask.c source. we define some task ID numbers, do not use 0, 0 is reserved for the idle task! you can have up to 15 (16 actually, but 0 is idle task) if you want more, #define TASKS_MAX 32 will give you 32 #define TASKID_LEDBLINK 1 #define TASKID_COUNT 2 Next we need to define a TOCK, I am using TOCK to represent an interrupt period. And this number is how many ticks of the timer resolution. ie: timer res = .1us, then TOCK 500 would be 50 uSeconds bottom line, we want to know how many ticks of the timer before we overflow it and cause an interrupt. #define QTASK_TOCK 500 now we just include the qtask.c source. #include "qtask.c" Now, somewhere in our source code, we need to initialize the qtask system preferably in main() or in your boot up code qTaskInitialize(); After you have initialized the qtask system, you need to define some parameters for each task id, such as interval, enabled, and priority. First, the timer interval, this number is how many interrupt periods This number is how many TOCKS Set the interrupt period: mqTaskSetTmr(TASKID_LEDBLINK, 1000000); Set a priority: (QTPRI_NORMAL is default) (QTPRI_HIGHEST, QTPRI_HIGH, QTPRI_NORMAL, QTPRI_LOW, QTPRI_LOWEST) mqTaskSetPri(TASKID_LEDBLINK, QTPRI_HIGHEST); Enable the task: mqTaskEnable(TASKID_LEDBLINK); If you need to disable a task in your program, simply: mqTaskDisable(TASKID_LEDBLINK); Now that your program has setup each task, we need to manage them somewhere, that is, start processing the queue. In your code, preferable in an endless loop, add the following: Note: task_blink_led() is a function you defined to handle this task while(1) { // some main loop code here (but not needed, all can be done in tasks) mqTaskManager() { // tell it what function to execute per task id mqTaskFunction(TASKID_LEDBLINK, task_blink_led()); mqTaskFunction(TASKID_COUNT, task_count()); } } Now the fun part, should you find that any of your tasks are taking much to long to execute because of their size, and queued tasks do not execute in a timely manner, you can break up long tasks with a state machine, but I like to call it slices. Think of a task as a pie, and you slice it up, and we execute each slice one at a time as the task manager calls it. To do this, first we need to define a pie, you can break any number of tasks into pies if you wish. Before you include the qtask.c file, define your pies: // define a pie (basically name of a state machine) qDefinePie pieBlinkLed; // this is actually just an int8, so its a variable In your source, in main() or in your boot up, after you set some info for each task, you need to initialize each pie: // initialize the blink led pie (state machine) mqPieIni(pieBlinkLed); Now just define task_blink_led() function, that calls each slice. Each slice is nearly a function you have defined to perform a sliced up task: void task_blink_led(void) { // manage slices of the pie mqSliceManager(pieBlinkLed) { // define the order of the slices, (constant, function) mqOrderSlice(1,slice_ledOn()); mqOrderSlice(2,slice_ledOff()); } // we need to define what the last slice was (this resets slice counter) mqLastSlice(pieBlinkLed,2); } slice_ledOn() and slice_ledOff() are functions that you have defined in your source that get called by the slice manager. the function: mqLastSlice(pieBlinkLed,2); tells the slice manager when to reset the slice counter, so we can start over. Thats it. If you follow the example code, you will see all the above in use. --mike