Write a check

In this tutorial we will write a check that checks the automotive qualification of a passive component. We will over:

  • Writing a check
  • Adding a check to a pcb-module
  • Running checks
  • Inspecting a design to add checks programatically.

The design

Example code for this tutorial is here.

Let's start with a simple design that contains one resistor, with that has a property aec-rating set to "Q200".

pcb-module checked-design :
  inst r : chip-resistor(1.0)
  property(r.aec-rating) = "Q200"

set-current-design("test-checks")
make-default-board(checked-design, 4, Rectangle(25.0, 25.0))

; Show the Schematic and PCB for the design
view-board()
view-schematic()

The pcb-check

Next we want to define a new check that makes sure that a property named aec-rating exists, and its value is "Q200".

pcb-check aec-q200 (component:JITXObject):

    #CHECK(
    name =                 "Automotive rating"
    description =          "Check that a passive component is AEC Q200 rated"
    condition =            has-property?(component.aec-rating),
    category =             "Component Data"
    subcheck-description = "Check that %_ has a defined aec-rating" % [ref(component)],
    pass-message =         "%_ has a property for aec-rating of %_" % [ref(component) property(component.aec-rating)],
    info-message =         "%_ does not have an aec-rating property attached" % [ref(component)],
    locators =             [instance-definition(component)]
    )

    #CHECK(
    name =                 "Automotive rating"
    description =          "Check that a passive component is AEC Q200 rated"
    condition =            property(component.aec-rating) == "Q200",
    category =             "Component Checks"
    subcheck-description = "Check that %_ is AEC Q200 rated." % [ref(component)],
    pass-message =         "%_ is AEC Q200 rated" % [ref(component)],
    fail-message =         "%_ is not AEC Q200 rated. Instead has rating %_." % [ref(component) property(component.aec-rating)],
    locators =             [instance-definition(component)]
    )

This check takes a JITXObject as an argument. We pass in a component and the #CHECK macros:

  • first make sure that the aec-rating property exists on the component (adding a prompt to add it if it is missing)
  • and second make sure that the value of aec-rating is "Q200".

The syntax of the #CHECK macro is documented here.

In our design, we can check the instance r for an AEC rating with check aec-q200(r):

pcb-module checked-design :
  inst r : chip-resistor(1.0)
  property(r.aec-rating) = "Q200"

  check aec-q200(r)

set-current-design("test-checks")
make-default-board(checked-design, 4, Rectangle(25.0, 25.0))

; Show the Schematic and PCB for the design
view-board()
view-schematic()
run-checks("check-report.txt")

Note that we also add run-checks to run the check we added to our design.

Adding checks with introspection

Let's say that we want to check the AEC rating of any resistor or capacitor in our design. We can write a function that inspects all the components to see if it is a resistor or capacitor, and than applies the check if so. Here's the introspection function and how it gets used in a design with more components:

defn check-aec (module:JITXObject) :
  inside pcb-module:
    for c in component-instances(self) do :
      if has-property?(c.resistance)  or reference-prefix?(c) == "R" or
         has-property?(c.capacitance) or reference-prefix?(c) == "C" :
        check aec-q200(c)

pcb-module checked-design :
  inst r : chip-resistor(1.0)[10]
  inst c : ceramic-cap(10.0e-6)[8]

  for i in [0 1 3 4 5 7] do :
    property(r[i].aec-rating) = "Q200"
    property(c[i].aec-rating) = "Q200"

  property(r[2].aec-rating) = "Q101"

  ; check aec-q200(r[0])
  check-aec(self)