Designing a chip antenna keepout zone in python with Kicad

keepout

Antenna design has a lot of information for one to take in, especially if it is your first time doing it. In the process of developing networks and protocols for interconnected devices(IOT), there is an urge to miniaturise devices usually held by the notion “Smaller is better”.

A large part of creating devices involves the physical nature of a device and this includes its mechanical characteristics and its electrical characteristics. This is largely ignored usually and usually forms the barrier between creating a single device and moving on to mass production and manifests itself in engineering cost.

A part of this which is usually a dark art is Radio frequency design  and in product development it is usually in the statement “We need to make this design smaller” and antenna size plays a huge role in this depending on the area of application of a device. The steps taken to design an antenna involve the following:

1. Determining the application area of the device

I usually define areas of physical application in three broad categories:

  • Indoor
  • Semi-outdoor/indoor
  • Outdoor

Any of the above can also belong into other categories involving the actual use of device:

  • Human to machine(H2M).
  • Machine to machine(M2M).

The most difficult to design is Outdoor due to the weather elements and Human to machine due to the various use-cases the device may be used for and the need to pre-plan and manage user expectation.

2. Determining the factors affecting and constraints on antenna.

From the above high level classification, one then has to determine the effect of the immediate environment including:

  • Physical space constraints of the region the device will be present.
  • Effects of the immediate materials surrounding the device. An example of this are walls causing signal absorption, metals causing a change to the antenna field distribution and so on.
  • Movement of the device: This usually shows up as the Doppler effect and does affect satellite communication and high velocity communications.

The application use-case usually affects how the user perceives and interacts with the device especially in H2M applications. This is usually a design perspective that will directly affect the antenna design.

3. Choosing the antenna

This will be affected by expected cost, performance and look. There are two broad categories of antennas:

  • Internal antennas.
  • External antennas.

External antennas

External antennas are used for Industrial applications or non H2M applications where the shape and size doesn’t affect the user of the product. A famous type of external antenna in IOT applications is the whip antenna.Image result for whip antenna

Figure: A 3G/4G whip antenna.

A whip antenna is usually good where the device shape/size doesn’t matter and performance is a no compromise.

Internal antennas

These are usually in two types:

  • PCB antennas.
  • Chip antennas.

PCB antenna also called Trace antennas use the copper of the PCB board as the radiating element and the air and board underside as the dielectric. They are susceptible to detuning depending on the presence of metals, plastics and other PCB components nearby.

PCB antennas

https://i0.wp.com/dangerousprototypes.com/blog/wp-content/media/2013/02/2013-02-22_2311-600x409.png

Figure: PCB Antenna selection guide from Texas Instruments(TI) for the Industrial Scientific and Medical(ISM) band

The advantage of PCB antennas is zero cost but the disadvantage is that it involves lots of testing and simulation. They also may have poor efficiency if incorrectly used.

Chip antennas

https://www.proto-pic.co.uk/user/products/large/00691-03-L__62893__82521.jpg

Spark-fun NRF24L01+ transceiver with blue chip antenna.

Chip antennas are simply quarter-wave monopole antennas that require a ground plane in order to transform it to a half-wave dipole antenna. This is usually an example of an image antenna .

The Chip antenna usually contains its own ground plane and thus the PCB board it is to be mounted on needs to be clear of all copper. The removal of copper from the PCB forms what is called a keep out zone abbreviated as KOZ.

Kicad

Image result for kicad logo

Kicad is a great and free PCB design tool and I have been using it for approximately six months now after I switched over from EAGLE CAD. I can always pay the monthly eagle fee but I love community driven initiatives. Kicad being an open source project it usually leans on contributors like you and me apart from the official project contributor which is CERN(European Organization for Nuclear Research) in Europe.

Image may contain: 22 people, people smiling

Past image of my visit to CERN at the port hackathon, with Nobel Prize laureate in physics Jack Steinberger. Attribution to The Port association.

Kicad nuance

This lead me to my issue: Kicad lacks a means to precisely create keepout zones. One can always create a KOZ by moving the mouse on a grid and snapping on the coordinate plane but for antenna design, this does not suffice! Measurements need to be spot on and a mistake of a few millimeters can easily detune an antenna thus one needs to go berserk on the design and thoroughly inspect it. DO NOT TRUST THE DESIGN SO EASILY!…RECHECK

Image result for meme foaming at the mouth

 

Python to the rescue

Image result for python logo

Kicad includes a python interpreter that provides an interface to the compiled C++ codebase. This is done using SWIG http://www.swig.org/ that converts the C++ kicad code to python.

pyshell

Python usually has a dedicated folder for its python scripts and on my nix box, this is at:

$/usr/share/kicad/scripting/plugins/

The design

The specific chip antenna being designed for is the Ethertronics M620720:

M620720 Ethertronics Inc. | 939-1066-1-ND DigiKey Electronics

For design this antenna requires the following free-space tested land pattern:

land_pattern

 

Due to the effects of antenna detuning, it is recommended to leave a space for a PI(Shunt-series-shunt) matching circuit that one can use to correct the impedance matching after production. A PI circuit has a high Q level, and is suited for instantaneous narrow-band signals due to the high Q. More details of PI matching circuits can be found at Wikipedia .

PI_cct

At design time, it is best to use a 0 ohm resistor or solder bridge as the series element and do not populate(DNP) the shunt elements. The individual elements for a match can be calculated from a vector network analyser(VNA) measurement after production by plotting on a smith chart.

Creating the keepout zone

Kicad is built on the Wx C++ framework and thus kicad reuses alot of the components from Wx framework. In python this is Wxpython. The keep-out zone is a simple rectangular shape with the corner points as the elements. The coordinates should be known before hand with reference to the origin of the layout design. The coordinates in python is as Wxpoint with method attributes Wxpoint.x and Wxpoint.y .

Kicad uses a coordinate space of 1E6 units to form a milimeter thus in order to convert from millimeter from to kicad coordinate space one must multiply by 1000000. This is implemented in the method pcbnew.FromMM() .

We then form a python script file is antzone.py:


import pcbnew

def create_point(x,y):
    return pcbnew.wxPoint(pcbnew.FromMM(x),pcbnew.FromMM(y))

def insert_antenna_keepout(left_bottom_pt, left_top_pt, right_top_pt, right_bottom_pt):
    board = pcbnew.GetBoard()
    layers=[board.GetLayerName(0),board.GetLayerName(1),board.GetLayerName(2),board.GetLayerName(31)]
    for layer in layers:
        _insert_keepout(left_bottom_pt, left_top_pt, right_top_pt, right_bottom_pt, layer)
    #Refresh
    board = pcbnew.GetBoard()

def _insert_keepout(left_bottom_pt, left_top_pt, right_top_pt, right_bottom_pt, layer):
    board = pcbnew.GetBoard()
    hatch_type = pcbnew.CPolyLine.DIAGONAL_EDGE #Hatched outline
    area = board.InsertArea(-1, 0xffff, board.GetLayerID(layer), left_bottom_pt.x, left_bottom_pt.y, hatch_type)
    #coordinate of first corner (a zone cant have empty outline)
    area.SetIsKeepout(True) #Set area as KOZ
    area.SetDoNotAllowTracks(False) #Allow tracks in KOZ
    area.SetDoNotAllowVias(False) #Allow vias in KOZ
    area.SetDoNotAllowCopperPour(True) #Do not allow Copper pours in KOZ

    outline = area.Outline()

    outline.Append(left_top_pt.x, left_top_pt.y)
    outline.Append(right_top_pt.x, right_top_pt.y)
    outline.Append(right_bottom_pt.x, right_bottom_pt.y)

    area.Hatch()

To simplify the input process, we form a second script file that takes in the user coordinates:


import antzone

left_bot=antzone.create_point(160.28,78.537)
left_top=antzone.create_point(160.28,67.7)
right_top=antzone.create_point(171.78,67.7)
right_bot=antzone.create_point(171.78,78.537)

antzone.insert_antenna_keepout(left_bot,left_top,right_top,right_bot)

 

References