In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Peter Van der Zee wrote: Hi Chris; I thought your requirements to be an excellent example of how to use a simple (non-preemptive) RTOS, so I coded up your program for you so others could see the benfit of using such a time-structured approach. But because I am somewat SX/B illiterate and for efficiency, I wrote it in my favourite......assembler. Please do understand this is just one particular implementation; there are MANY ways to skin this cat....only one example is given. And not necessarily the best or fastest or shortest, just something with LOTS of comments so many people can more easily follow it. The main thing to understand is the scheduler. The interrupt sets a flag every 5 uSec, and the main loop simply waits for that to occur. Then all heck breaks loose. I have somewhat arbitrarily chosen the scheduler to have 100 uSec, 1mSec, 10 mSec, 100 mSec and 1 Sec time ticks to run the various tasks that are required in THIS rendition. Actually some of those ticks are not directly used, so they might be combinable with other time ticks. However, their inclusion does not hurt, and for generality it demonstrates the RTOS better. Each of those ticks is triggered by counting off the decade of faster ticks above it. They need not necessarily be what I chose, but, hey, I like nice numbers. So, every 1 millisecond I call the RAMPER that controls how fast the duty cycle changes from minimum to maximum; I call the CYCLERUNCHECK to see if the input conditions (rb.2) asks that the duty cycling should operate at all; and I call the CYCLER which actually calculates and puts out the relay duty cycle on rc.0. Then every 10 milliseconds the RAMPADJUST is called to accept push button input (rb.0 and rb.1) to adjust the ramping speed slower or faster. These have limit sets from 5 units to 75 units. Every 100 milliseconds the CYCLETRIGGER is called to initiate yet another complete duty cycle, and it is this trigger of course that sets the 10 Hz cadence. So for fun, you could relocate the 1 second LED flasher (rc.1) to the 100 millisecond tick level and see what happens. The beauty of this scheme is that all these tasks are (apparently) simultaneous and independent, and one need not concern (much) about timings of one event affecting another event. That said, though NO task may hog all the processor time and lock up the system. Delay loops are an ABSOLUTE NO-NO!!!!! After all, that is why we use an RTOS! Run it through Guenther's simulator, and single step it in "debug" it with your SX-Key until you really get the hang of it. Holler if you have questions. Cheers, Peter (pjv) ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=104114#m104165 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)