For tweaking the amount of code executed in each state machine, it can=20 be useful to use a D/A converter, or a few (3) bits driving an R2R=20 ladder. Say you have 5 tasks in your main loop: int main() { // initialize stuff... while(1) { one_machine(); two_machine(); ... five_machine(); } You can assign each machine an int value, and start each machine's=20 routine with an assignment of it's value to the D/A or R2R port. You can=20 watch the D/A or R2R with a scope, and learn how the work is being=20 distributed among the machines, and adjust code based on that. #define ONE_VALUE 1 one_machine() { r2r_port =3D ONE_VALUE; // work... } I don't recall where I first heard of it, but I've used it and it was=20 useful. If focusing on a single machine, you can use the same technique=20 for each state in the machine. Joe W On 4/19/2013 3:23 AM, Veronica Merryfield wrote: > I have used a state machine based co-operative multitasking approach in m= any systems. The main code is a loop calling each task state machine, which= is a large switch statement, usually. Finding the right size of block and = unrolling loops can get tedious and it can look messy but it does work well= .. I have had such systems deal with timers and comms, the interrupt handles= just raise flags and the code in the state machines handles things. > > On 2013-04-18, at 11:20 PM, veegee wrote: > >> On 2013-04-18 10:59 AM, Joe Wronski wrote: >>> Having never worked with any RTOS due to ROM and RAM limitations, I fin= d >>> Protothreads fascinating. Where my cow-orkers and I had hand crafted >>> state machines which closely resembled the Protothreads expanded macros= , >>> using PT would have made the code more readable and maintainable. I ha= d >>> never considered using the __LINE__ macro for anything other than >>> compiler error and warning info. And I never realized that you could >>> put the case : argument of a switch within a while loop (Duff's Device)= .. >> Yup, C switches behave somewhat like labels. The cases are valid >> anywhere within the switch. >> >> --=20 >> http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >> View/change your membership options at >> http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .