In SX Microcontrollers, SX/B Compiler and SX-Key Tool, bean wrote: Okay I'm missing something vital here... I thought that if a task took longer than 1 tick the interrupt would keep track of that and adjust the next task. Why won't something like this work ? I don't see what all the "context switching" is doing... [code] DEVICE SX28, OSC4MHZ, TURBO, OPTIONX, STACKX FREQ 4_000_000 LED1 PIN RC.0 OUTPUT LED2 PIN RC.1 OUTPUT LED3 PIN RC.2 OUTPUT LED4 PIN RC.3 OUTPUT cnt VAR Byte task_ID VAR BYTE (4) task_Interval VAR BYTE (4) task_Count VAR BYTE (4) INTERRUPT 100 GOTO HandleInt TASK1 SUB 0 TASK2 SUB 0 TASK3 SUB 0 TASK4 SUB 0 HandleInt: FOR cnt = 0 TO 3 DEC task_Count(cnt) IF task_Count(cnt) = 0 THEN ON cnt GOSUB TASK1, TASK2, TASK3, TASK4 task_Count(cnt) = task_Interval(cnt) ENDIF NEXT RETURNINT PROGRAM Start Start: PUT TASK_ID, 0, 1, 2, 3 PUT TASK_INTERVAL, 10, 50, 75, 100 PUT TASK_COUNT, 1, 1, 1, 1 ' Main code here, do whatever... END Task1: LED1 = ~LED1 RETURN Task2: LED2 = ~LED2 RETURN Task3: LED3 = ~LED3 RETURN Task4: LED4 = ~LED4 RETURN [/code] Bean ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=2&m=157842#m176163 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)