PDA

View Full Version : How to run more logic in a PAC


Darren
02 Dec 05, 02:23 PM
The PAC is designed to run small amounts of logic. Unfortunately, at the moment "small" is hard to define.

It is possible to write code that will physically fit in the PAC, but takes too long to run. In this case, the PAC will reset itself. Currently, the only way to know for sure whether a particular set of code will run is to try it and see (the status LED will show if the logic engine is resetting). This will be improved in the future.

If you find that you have too much code for the PAC to run, one solution is to make different bits of code run on different loops to reduce the total time taken on any one loop. The downside of this is that it introduces delays, so it is only suitable for non-time-critical code.

The easiest way is to put delays between chunks of code in a module :


{ chunk of code }
delay(1);
{ chunk of code }
delay(1)'
{chunk of code }
delay(1);


An alternative way which will run a little faster is as follows :


{ variables section }
LoopCount : integer;

{ initialisation section }
LoopCount := 1;

{ Module code }
case LoopCount of
1 : { chunk of code };
2 : { chunk of code };
3 : { chunk of code };
4 : { chunk of code };
end;
LoopCount := LoopCount + 1;
if LoopCount = 5 then
LoopCount := 1;

Josh
02 Dec 05, 05:10 PM
Does the PAC support local variables?

Lookin at the above code, you would have to define a global variable for each module that has chunk of code. If a local variable is defined (or allowed in PAC) it might be a bit easier to maintain. Just my opinion.

Darren
05 Dec 05, 10:44 AM
Does the PAC support local variables?
No it doesn't. There are certainly benefits for adding local variables, but it is unlikely to happen soon.