- KickAss HAL Programming -

  

 

 

 

 

First Kick - Casting off the blinders of conventional programming experience.

 

Procedural vs. Event-Driven Programs

Many programmers, even professional and highly skilled programmers do not fully understand the distinction between these very different paradigms. Most people are familiar with procedural programs. Procedural programs are those where program steps execute in sequential order, branching as necessary decisions are made, but always looping back to a beginning point and repeating themselves.

This snippet of code is an example of a procedural program.

if (the user did this) {

do this

}

else if (the user did this) {

do this }

...

else {

do this

}

Procedural programs may be a simple list of actions that progress from program entry to exit. Such programs typically process some specific data and end in short order. More complex programs may use a giant loop, soliciting input, processing that input, delivering output, and then repeating forever or until commanded to stop.

Such a loop is sometimes called an "executive loop" and when waiting for input, the system will loop many thousands of times per second. All this looping and waiting ties up machine resources that may be needed elsewhere.

An event-driven program on the other hand does not loop when idle, and does not use resources or execute actions until it receives a trigger. In HAL programs there can be multiple triggers, and there can be conditions that are tested, but once triggered the actions are executed. Until a trigger arrives, the “program” does nothing.

In the purest implementation of an event driven program, the processor is actually halted, and only started when a trigger event arrives. This is usually only the case with small embedded systems that use a PIC or similar micro-controller for a processor.

In the PC world, this isn’t the case as operating system and other processes may need processor cycles even when no triggers are present. Windows GUI style programs are like this. Individual programs, from Word to Explorer are generally event driven, but Windows itself runs continuously, looping and checking for mouse movements, etc.

It's unfortunate that HAL Rules use the traditional IF/THEN programming nomenclature. They are not conventional IF/THEN statements, although they do bear a superficial resemblance.

Think of HAL programming in terms of Trigger Events, Secondary Conditions and Actions, not IF/THEN and conventional programming constructs, and you will find developing HAL logic much simpler.

 

 

 

 

 

 

 

 

 

 

Event driven programs of the sort HAL uses are sometimes also referred to as Ladder Logic. HomeToys carried an excellent article on ladder logic as applied to the Ocelot back in April 2000. Much of the wisdom of this article applies to HAL as well. Recommended.

Navigation

Introduction

Cast Off your Blinders

Triggers, Conditions and Actions

More Macros

Scenes and Modes

Main Menu