Skip to main content

Script Tip Friday - Determining an Optimal Location for Components on a PCB | 09.30.2022

What is the optimal location to place a component on a Printed Circuit Board (PCB), in terms of its reliability under shock, vibration, and other environmental conditions? And how do the mount point configurations affect the relative performance of the PCB?

For many Ansys Sherlock users, this involves repeating the steps of editing the part location using the Part Editor, updating the mount point configuration in the layer viewer, running an analysis, and viewing the results.

However, this can become cumbersome and time consuming if a user wants to test out many different locations and mount point configurations. Do you know you can automate this by using Sherlock APIs? Sherlock APIs are written using Google’s gRPC framework and there are Sherlock APIs that would let you easily set a component’s location properties, the mount point configurations, and run an analysis.

In this article, we will show you how you can set a component’s location properties and edit the mount point configurations for a PCB. In a future article, we will show you how to automate running of an analysis. For information on how to setup your computer to run Sherlock’s APIs, please refer to the Sherlock User Guide.

At the start of your Python script, import the generated gRPC client and server interfaces.

import SherlockPartsService_pb2
import SherlockPartsService_pb2_grpc
import SherlockLayerService_pb2
import SherlockLayerService_pb2_grpc 

Create a gRPC channel to communicate with the server.

channel = grpc.insecure_channel('localhost:9090')

The below code sets the location properties for a component using the setPartLocation() API. As you can see, it uses variables for the x and y locations for the API, so they can be dynamically updated during the script runtime by either looping through a list of values or provided as inputs when the script is executed.

# Initialize the variables for the input parameter
project_name = “Tutorial Project”
cca = “Main Board”
my_component = “U6”
x = -0.25
y = 0.45

# Create a stub for the SherlockPartsService
stub = SherlockPartsService_pb2_grpc.SherlockPartsServiceStub(channel)

# Sets up the input parameters
message = SherlockPartsService_pb2.SetPartLocationRequest()
message.project = project_name
message.ccaName = cca
message.refDes = my_component
message.x = str(x)
message.y = str(y)
message.rotation = "0"
message.locationUnits = "IN"

# Executes the API
response = stub.setPartLocation(message)

In the below code, it first deletes all the mount points on the PCB using the deleteAllMountPoints() API, then it adds a list of mount points using the updateMountPoints() API by importing a CSV file that contains all the mount points and their configurations.

# Create a stub for the SherlockLayerService
stub = SherlockLayerService_pb2_grpc.SherlockLayerServiceStub(channel)

# Deletes all mount points from the CCA
message = SherlockLayerService_pb2.DeleteAllMountPointsRequest()
message.project = project_name
message.ccaName = cca
response = stub.deleteAllMountPoints(message)

# Add Mount Points from file (filename can be dynamically generated to use different configurations)
num_mount_points = 6
mount_point_directory = "C:\\Temp\\”
filename = “mount_points_” + str(int(num_mount_points)) + “.csv”

message = SherlockLayerService_pb2.UpdateMountPointsRequest()
message.project = project_name
message.ccaName = cca
message.filePath = mount_point_directory + filename

# Please note that starting in 23.1 this API will be renamed to updateMountPointsByFile()
response = stub.updateMountPoints(message)

The Sherlock Layer Viewer below shows the board layout after executing the above snippets:

You can see the table of reliability results in Sherlock:

The above script example can be easily integrated with Ansys optiSLang to perform a sensitivity study. If you are interested in learning more about this, please register and attend Ansys Level Up 3.0 on October 25, 2022. The presentation “Enhancing Electronics Reliability Studies with APIs and Ansys optiSLang” will showcase how to couple optiSLang with Sherlock APIs to optimize designs in less time, perform more robust reliability studies and reduce overall turnaround time.

To learn more register for Level Up 3.0 and attend the "Enhancing Reliability Studies with APIs and Ansys OptiSLang" under the Electronics Reliability Track.