Example to use Separate Task to Execute a Command

Here you can share completed projects or parts of projects that may be useful to others. You may post files relevant to ZBasic - source code, schematics, etc.
Post Reply
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Example to use Separate Task to Execute a Command

Post by mikep »

Here is a simple example of how to use a separate task to perform some operation; in this case flip a I/O port bit to sound a buzzer (zero turns on the buzzer). If the buzzer is already on then no action is taken. The example shows how to wake up a sleeping task so that it can start the action right away and then control is passed back to the caller. At a later time the task asynchronously ends the action.

Here is some of the example output:

Code: Select all

0.1 Sleeping
2.1 Sleeping
4.1 Wakeup
4.1 Buzz
8.1 Already awake
9.1 Sleeping
11.1 Sleeping
12.1 Wakeup
12.1 Buzz
16.1 Already awake
17.1 Sleeping
19.1 Sleeping
20.1 Wakeup
20.1 Buzz
The corresponding annotated timing diagram is shown below. Note that the various sleep periods in this example have been chosen to show how the program works rather than what might be used in reality. For example the buzzer may only be turned on for 250ms rather than 5 seconds. The task sleep time can be set to a very large value because it is woken up when needed by the SoundBuzzerNoWait() routine.
Attachments
TaskExample.zip
Example Code
(25.04 KiB) Downloaded 4259 times
Example Timing Diagram
Example Timing Diagram
timing_diagram.jpg (25.67 KiB) Viewed 11316 times
Mike Perks
Post Reply