Overview

This tutorial will guide you through copying a reference circuit into tscircuit.

There are many great reasons to copy a reference circuit:

  • You are learning tscircuit and want to focus on learning the tscircuit tools rather than designing a circuit
  • You are migrating a project from another EDA tool
  • You are planning on making a modified version of an existing circuit

In this guide we’ll walk through the four major steps of copying a reference circuit:

  1. Understanding your reference circuit
  2. Importing or creating each subcomponent
  3. Connecting your subcomponents together

If you’re feeling confused or overwhelmed, take a look at the Motor Controller reference circuit, most of the files are generated or use reference circuits as a starting point!

0. Prerequisites

  1. You’ve initialized a directory with tsci init
  2. You can successfully see the default circuit using tsci dev
  3. You have a typescript IDE like VS Code installed

1. Understanding your reference circuit

Most reference circuits are composed of one or more of the following elements:

  1. Pictures of the manufactured board
  2. A PDF of the schematic
  3. A Bill of Materials or description containing the major parts

Use these resources to find part numbers for each component in your schematic. You’ll need this because you’ll need to create a typescript component for each part you’re using (except for passives like resistors and capacitors)

Most components have a little bit of white text on the top of them that you can google to find the part, but it’s usually easiest to find the part number on the schematic itself.

2. Importing or creating each subcomponent

You should create a file in the lib directory for each subcomponent in your design. There are generally 3 ways you can create components.

2.1 Super Easy Mode: Find it on JLCPCB

The easiest way to create a component is to google “jlcpcb <part name>” and find the part on JLCPCB. You then can copy the JLCPCB Part Number and generate a component using easyeda-converter.

# This will create a component file for you!
npx easyeda convert -i C88224 -o lib/C88224.tsx

2.2 Create from Scratch with Standard Footprint

If you can’t find the part on JLCPCB, you can create a component from scratch.

There are two parts to creating a component:

  1. Find all the pin labels
  2. Find out what the footprint looks like
  3. Fill in the template

This is what the template for a component looks like:

import { createUseComponent } from "tscircuit"
import type { CommonLayoutProps } from "@tscircuit/props"

const pinLabels = {
  "1": "PWR",
  "2": "DO",
  "3": "GND1",
  "4": "GND2",
  "5": "AO2",
  "6": "AO2",
  "7": "BO2",
  "8": "BO2",
} as const
const pinNames = Object.values(pinLabels)

interface Props extends CommonLayoutProps {
  name: string
}

export const PartName = (props: Props) => {
  return (
    <bug
      {...props}
      footprint="tssop16" // <-- This is the footprint specifier! Find it in the datasheet!
      pinLabels={pinLabels}
      schPinSpacing={0.75}
      schPortArrangement={{
        leftSize: 4,
        rightSize: 4
      }}
    />
  )
}

export const usePartName= createUseComponent(PartName, pinNames)

2.2.1 Finding the correct footprint

A datasheet will normally include in it’s description somewhere details about the footprint or “landing pattern”. You can paste any package details into text-to-footprint to figure out exactly what footprint string you should use.

3. Connect your components

Now that you have all the subcomponents, you can connect them together. By importing them into the main MyCircuit.tsx file.

Start by just importing a single component like this:

import { useC88224 } from "gen/C88224"

export const MyCircuit = () => {
  const U1 = useC88224("U1")

  return (
    <group>
      <U1 />
    </group>
  )
}

Now start to connect components together…

import { useC88224 } from "gen/C88224"
import { useCapacitor } from "tscircuit"

export const MyCircuit = () => {
  const U1 = useC88224("U1")
  const C1 = useCapacitor("C1", {
    capacitance: "1uF",
    footprint: "0603",
  })

  return (
    <group>
      <U1 />
    </group>
  )
}

Finally when you’re ready, put it all together by adding every component:

import { layout, useResistor, useCapacitor, useBug } from "tscircuit"
import { TB6612, useTB6612 } from "./TB6612"
import { C88224 } from "gen/C88224"

export const MyCircuit = () => {
  const R1 = useResistor("R1", {
    resistance: "10k", // TODO
    footprint: "res0402",
    schX: -5,
    schY: 0,
  })
  const U1 = useTB6612("U1")
  const C2 = useCapacitor("C2", {
    capacitance: "1uF", // TODO
    footprint: "cap0603",
    schX: -4,
    schY: 1,
  })
  const C3 = useCapacitor("C3", {
    capacitance: "1uF", // TODO
    footprint: "cap0603",
    schX: -6,
    schY: -2,
  })


  return (
    <group>
      <U1
        VM1="net.VMOTOR"
        VM2="net.VMOTOR"
        VM3="net.VMOTOR"
        GND="net.GND"
        AIN1="net.AIN1"
        AIN2="net.AIN2"
        PWMA="net.PWMA"
        AOUT2_1={JP3.MA2}
        AOUT2_2={U1.AOUT2_1}
      />
      <R1 schRotation="90deg" right={U1.VCC} left={U1.STBY} />
      <C2 schRotation="-90deg" left={U1.VCC} right="net.GND" />
      <C3 schRotation="-90deg" left="net.VMOTOR" right="net.GND" />
      <C88224 name="U2" schX={-2} schY={-2} />
    </group>
  )
}