I suppose "straightforward and easy to write and understand" is in the=20 eye of the beholder. I do find myself occasionally needing to jump forward to step 14, or=20 backwards to step3, usually due to a detected mechanical malfunction. =20 The equivalent of the dreaded goto, I guess. Convenient, if not=20 actually necessary. I also sometimes find the same steps in a loop, and I might have: case 3: case 12: lift_cylinder_up(); // other things extend_step++; break; // back to main Kerry Isaac Marino Bavaresco wrote: > I took some time to study your example S.M. and I think this code is an > accurate representation: > > > int extend_loop( void ) > { > TaskStart(); > > while( 1 ) > { > while( !( tray_at_nest && index_command )) > Yield();// Perhaps could be a Sleep to save a lot of CPU time= ; > > set_conv_speed( 256 ); > tray_feed_pusher( out ); > Sleep( 200 ); > > do > { > tray_feed_pusher( in ); > Yield(); > } > while( !forward_slowdown ); > > clamp_on(); > conv_stop(); > tray_at_ready =3D 1; // tell other tasks we are done > } > > TaskEnd(); > } > > > Adding the two 'Yield' plus the 'Sleep', my code has three exit points > while your has four, besides during the sleep the function is not called > at all, making the system faster. > Besides, my representation is much more straightforward and easy to > write and understand. > > > Best regards, > > Isaac > > > > Em 16/02/2014 20:20, Kerry Wentworth escreveu: > =20 >> Maybe my projects are "simple and small ". but what I do is set up each= =20 >> loop to do 1 simple task at each entry and return. >> >> main() >> { >> for(;;) >> >> { >> extend_loop(); >> serial_loop(); >> etcetera_loop(); >> } >> } >> extend_loop() >> { >> switch(extend_step) >> { >> case 0: >> if(tray_at_nest && index_command) >> { >> set_conv_speed(256); >> tray_feed_pusher(out); >> extend_timer =3D timesince(0); >> extend_step++; >> } >> break; // Go back to main() >> case 1: >> if(timesince(extend_timer) > 200) extend_step++; // 200mS delay,=20 >> with no waiting >> break; // Go back to main() >> case 2: >> tray_feed_pusher(in); >> if(forward_slowdown) extend_step++; >> // In real life, there would be a timeout here >> break; // Go back to main() >> case N: >> clamp_on(); >> conv_stop(); >> tray_at_ready=3D1; // tell other tasks we are done >> extend_step=3D0; // ready for next tray >> break; // Go back to main() >> } >> >> Each loop runs for a couple of microseconds and returns. Any task can=20 >> be broken down inro a series of small steps. >> =20 > --=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 .