Embedded Software

Embedded Software

Topics related to SCADE Suite, SCADE Display, SCADE One and more.

Understanding causality errors when using `pre` and `last` in a Scade program.

    • fdtsaid
      Subscriber
      In Scade language referece, these is a code sample illustrate the causality error for variable y:
      type T = enum {a, b, c};
      node WhenBlkSample(x: T) returns (y: T last = b)
      let
        activate when y match
        | a: y = a -> pre(y);
        | b: y = x;
        | c: -- empty
        returns ..;
      tel

      The output of the scade compiler (kcg) is as the following

      *** Causality Error (ERR_400): Causality error
        at file ..., line 5, character 7
        at path whenBlkSample/_:a:y=
       the definition of shared flow y depends on flow y via the control context ;
        at file ..., line 2, character 34
        at path whenBlkSample/y/
       the definition of flow y depends on shared flow y via a control block ;

      I still have trouble to understand it. Could anyone give some insight?
    • Benjamin Descorps
      Ansys Employee

      Hello,

      Actually, in your model, the activate block compute the output y. But activation of the activate block also depends on the variable y. This leads to a causality error.

      If you want to resolve this error, you should add a delay. Example:

      type T = enum {a, b, c};
      node WhenBlkSample(x: T) returns (y: T last = b)
      let
        activate when last 'y match
        | a: y = a -> pre(y);
        | b: y = x;
        | c: -- empty
        returns ..;
      tel
    • fdtsaid
      Subscriber

      Hi Benjamn, thank you for your clear illustration!

Viewing 2 reply threads
  • You must be logged in to reply to this topic.