Now Reading
Automating Every thing in a USB Cable Tester PCB Design

Automating Every thing in a USB Cable Tester PCB Design

2023-05-25 14:25:37

TL;DR

I’m Cayden, {an electrical} engineer and transhumanist hacker. On this article, I discover the frustrations of repetitive handbook duties in PCB design and the advantages of automation. I exhibit the automation of duties equivalent to connecting pins, producing take a look at factors and indicator LEDs, programmatically inserting elements, and autorouting.

Introduction

If I’m writing a program, I’ll write a perform one time, then use that perform each time afterwards. Normally, if issues come up again and again, we clear up them as soon as very well, then we don’t clear up them once more.

But as {an electrical} engineer designing circuit boards, I usually burn quite a lot of time on repetitive duties. These duties can get annoying – they’re one thing I’d reasonably automate.

For instance, to design a easy USB-C cable testing board I must:

• Calculate and supply a special present limiting resistor to get the specified brightness for each colour of LED.

• Sort out, dimension, and place a customized textual content label that tells me what web every take a look at level belongs to.

• Redraw supporting circuitry from scratch each time I reuse a part in a brand new design.

• Recheck datasheets many occasions as I join varied GPIOs and peripherals.

It’s annoying to repeat duties like this, and every bit of handbook work carries a bit danger of creating a mistake. For my first design with JITX, I wished to see what number of of those pains I may automate away, and I wished to know what design would really feel like after I did. Electrical design shouldn’t be loss of life by 1,000 paper cuts. Let’s automate the only board doable and see what that does for our expertise as designers.

You’ll be able to see the complete code and design recordsdata for this venture within the JITX Cookbook: https://github.com/JITx-Inc/jitx-cookbook

The Undertaking

A USB-C cable tester board exams each wire in a USB cable. It has two ports which hook up with both finish of the identical cable. The board sends a voltage by way of every impartial wire within the cable, by way of an indicator LED, and to floor. If the LED lights up – there’s a connection. If it doesn’t mild up – no connection.

Indicator LED Schematic

Dangerous USB cables trigger complications when doing board bring-up – I’ve personally spent hours debugging the UART on an embedded system solely to search out that the USB cable had a foul information connection. A USB cable tester can point out the sort and well being of a USB cable, saving us from this ache.

I’ve purposefully chosen a easy, simple design as I wish to discover PCB design automation, and this can assist me give attention to making an attempt to automate frequent, repetitive duties.

Automation TODO

What can one automate right here? I’ll attempt:

1. Connection of nets to the USB connectors.

2. Calculation of 18 LED ballast resistors given a desired colour and brightness.

3. Naming all 18 take a look at pads.

4. Placement

Let’s do it.

How?

JITX EDA Software in VS Code

I’m going to make use of JITX to automate these duties. JITX is a software program outlined electronics CAD instrument. It’s just like KiCad, Altium, and the opposite EDA packages, however as a substitute of drawing PCBs, we outline PCBs in code. That offers one the power to show handbook duties into code.

Pin It To Win It – Connecting Pins

Let’s create two USB connectors and an influence web:


web POWER (energy)
...
public inst in-usb : elements/USB-C-1054500101/part
public inst out-usb : elements/USB-C-1054500101/part

One aspect of the USB must be absolutely related to our optimistic voltage rail. As an alternative of drawing a wire from each pin, let’s simply join them suddenly:


; join all pins of in-usb to energy
web (POWER pins(in-usb))

Take a look at Factors, Take a look at Factors All over the place

I’m going to create an indicator LED for each connection within the USB cable, so I’ll begin with a textual content label and take a look at level for every web. Within the conventional EDA course of, these are made and positioned manually. I’ll automate it with a perform that identifies the related web and generates a silk display screen label for the take a look at level. It is a basic helper perform which I’ll write as soon as now and count on to make use of again and again in future designs.

Under, I outline a perform which makes a take a look at level and locations a silk display screen label with customized textual content:


; place a testpad
defn my-testpoint-strap (tp:JITXObject, tp-name:String, diameter:Double) -> JITXObject:
  inside pcb-module :
    public inst tp-pad : gen-testpad(diameter)
    web (tp-pad.p tp)
    ; title the take a look at level
    value-label(tp-pad) = Textual content(tp-name, 1.0, W, loc(1.2, 0.0))
    inst my-label : ocdb/paintings/board-text/textual content(tp-name, 1.0, 0.0)
    place(my-label) at loc(1.2, -0.4, 0.0) on High (relative-to tp-pad)
    tp-pad

I can name this perform within the above loop that generated the LEDs. I’ve now generated testpoints with customized silk display screen labels.


; add a testpoint for this pin
val test-pad = my-testpoint-strap(IN, net-name, 2.0)

Subsequent Technology LED Technology

To check all of the USB connections, the opposite USB connector have to be cut up into separate nets. I’ll arrange these nets:


; make nets for all the pins on the usb C that we wish to take a look at
for p in pins(out-usb) do : ; for every pin of the USB, we make a web
    make-net-from-pin-name(p)

Every of those nets ought to then hook up with an indicator LED. However first, to assist with routing, I can order the nets primarily based on their bodily location.


; get all pins of the USB, and get them organized primarily based on how they bodily seem
val ordered-pins = get-pins-physically-ordered(out-usb)
; convert from ordered record of pins to ordered record of nets
val ordered-nets = map(get-named-net{self, _}, ordered-pins)

Routes are made so as of pads’ bodily location.

See Also

Routes are made so as of pads’ bodily location.

Now to generate an indicator LED for each USB pin. It’s a standard situation for various LEDs on the identical board to have vastly completely different brightnesses, like this:

Uneven LED Brightness (Credit score: SparkFun)

To automate this frequent job and to verify I don’t hit the frequent uneven LED brightness “gotcha”, I outline a perform referred to as generate-test-led which takes in a colour and an enter voltage and makes use of these values to choose an LED and an acceptable ballast resistor to realize a nominal brightness.


; take a Tuple of pins we wish to add standing LEDs to, and the GND pin. Add standing LEDs and take a look at pins to every of the enter pins.
defn generate-test-leds-array (in-pins:Tuple, gnd-pin:JITXObject, voltage:Toleranced) :
  inside pcb-module :
    val colours:Seq = generate-rainbow(size(in-pins))
    for (in-pin in in-pins, colour in colours, place in 0 to false) do :
      ; create take a look at LED and join it
      inst test-led : generate-test-led(voltage, to-string(ref(in-pin)), colour)
      web (in-pin test-led.in)
      web (gnd-pin test-led.out)

    ...
    
; generate an array of take a look at LEDs for every web we simply made
generate-test-leds-array(ordered-nets, GND, property(battery.energy.vdd.voltage))

Laziness Redefined – Programmatic Placement

I now have 18 LEDs, 18 take a look at factors, and 18 ballast resistors. If I had been to export now and open it in a legacy CAD instrument, it’s only a large pile of elements:

Normally, the technique now’s to seize each part and manually drag them wherever we wish. Or, one would possibly use some fundamental alignment automation in current CAD instruments, however this nonetheless requires handbook time and effort.

Let’s do it higher with automation. I can programmatically place elements or submodules in code, which occurs sooner and works higher than handbook placement. Within the for loop the place I created the testpoints and LED modules, I can programmatically place something I would like on the board, with a little bit of iterative arithmetic every time by way of the loop:


val colours:Seq = generate-rainbow(size(in-pins))
for (in-pin in in-pins, colour in colours, place in 0 to false) do :
  ; create take a look at LED and join it
  inst test-led : generate-test-led(voltage, to-string(ref(in-pin)), colour)
  web (in-pin test-led.in)
  web (gnd-pin test-led.out)

  ; place elements right here
  ...

Now the whole lot is mechanically positioned. Higher but, if I modify the LED sort, take a look at level dimension, board dimension, and many others., it doesn’t matter, this can rerun to mechanically yield the structure I would like. Cheers to laziness!

Routing in Your Sleep

JITX has a in-built autorouter, which automates a big quantity of the routing course of. I can route most of this board in 30 seconds with a few clicks:

Discover these autorouted traces look completely different than the traces on the bodily board. Within the first move of this design, I manually routed the whole lot in an exterior CAD instrument. Afterwards, JITX launched an autorouter, so I redid the routing with the autorouter, which is what you see above.

Conclusion

That is some quite simple automation, however it does really feel a bit magical to have the take a look at factors mechanically created and correctly named. The handbook course of of making silk display screen textual content and sliding it round in EDA board instruments is all the time annoying, so I’m glad to have it automated away now and sooner or later. The LED technology module most likely didn’t save me time but, as I needed to write it from scratch, which takes time, however now it exists perpetually, and I’m trying ahead to reusing it many occasions sooner or later.

It’s not all excellent although – one would possibly discover that the LEDs on this board are vibrant. Whereas all the LEDs had been the identical brightness – they had been all brighter than I’d need. I manually selected 50 mcd because the depth, and this was manner too excessive. An automation enchancment can be to simply accept an enum of lighting choices (e.g. nightime, indoor, outside) that would mechanically select the proper depth for the appliance.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top