[C.CC USERS] Occam-Pi programing question

Fred Barnes F.R.M.Barnes at kent.ac.uk
Mon Sep 3 22:02:15 BST 2012


Hi Bryant,

> Here is what I got so far. The problem is, all the pumps turn on at the
> same time, run for the proper amount of time, then wait for the maximum
> wait time. For example, the pump on pin 12 is governing the off time. After
> 4s all the pumps kick on, 13 is on for 1s, 12 for 2s and 11 for .7s, once
> 12 is done it waits 4s then everything starts at the same time.
>
> Can somebody help me out?
>
>
> #INCLUDE "plumbing.module"
> PROC do (VAL INT pin, VAL INT timeOn, VAL INT timeOff)
>   SEQ
>     digital.mode (pin, OUTPUT)
>     digital.write (pin, HIGH)
>     delay(timeOn)
>     digital.mode (pin, OUTPUT)
>     digital.write(pin, LOW)
>     delay(timeOff)
> :
>
> PROC main ()
>   WHILE TRUE
>     PAR
>       do(13, 1000, 2000)
>       do(12, 2000, 4000)
>       do(11, 700, 1500)
> :

If I understand correctly, you just need to move the logic around a bit.
What happens with the PAR is that all the sub-processes do their own
thing, but then wait for each other to finish (as per PAR semantics),
at which point the WHILE loop flies around and everything starts all
over again.

It sounds like you want these things to be entirely independent, so
(fairly simply) move the WHILE loop inside the process, e.g.:

PROC do (VAL INT pin, timeOn, timeOff)
  WHILE TRUE
    SEQ
      ... do stuff
:

PROC main ()
  PAR
    do(13, 1000, 2000)
    do(12, 2000, 4000)
    do(11, 700, 1500)
:


Alternatively, and equivalent to the above [but not your original code],
you could just mangle PROC main() to swap the WHILE and PAR around:

PROC main ()
  PAR
    WHILE TRUE
      do(13, 1000, 2000)
    WHILE TRUE
      do(12, 2000, 4000)
    WHILE TRUE
      do(11, 700, 1500)
:


However, having the WHILE loop inside the 'do' process is cleaner and a
little more obvious -- unless there are situations where you don't want this
behaviour.


Hope that helps,

-- Fred
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: not available
URL: <http://lists.concurrency.cc/pipermail/users/attachments/20120903/c9fc67bd/attachment.pgp>


More information about the users mailing list