mohan-bee/modern-controller

A two-board 2.4 GHz wireless control system using CH32X035 MCUs, SX1280 radios, USB‑C transmitter with RFX2401C PA/filter, and a battery-powered receiver with U.FL antennas, RGB status LEDs, regulators, and PWM output headers.

Version
0.0.6
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone mohan-bee/modern-controller  # download the package files into ./modern-controller
tsci add mohan-bee/modern-controller    # add it to your project as @tsci/mohan-bee.modern-controller

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

design/RadioBoard.tsx

import { CH32X035F8U6 as MCU } from "./imports/CH32X035F8U6"
import { E6C0606RGBC3UDA as StatusLED } from "./imports/E6C0606RGBC3UDA"
import statusLedBody from "./imports/E6C0606RGBC3UDA-body.json"
import { GJM1555C1HR50WB01D as RFMatchCap } from "./imports/GJM1555C1HR50WB01D"
import { SX1280IMLTRT as Radio } from "./imports/SX1280IMLTRT"
import { XC21M4_52_000_F10NNHPL as Crystal } from "./imports/XC21M4_52_000_F10NNHPL"
import { U_FL_R_SMT_1_80_ as UFL } from "./imports/U_FL_R_SMT_1_80_"
import { TYPE_C_31_M_12 as Receptacle } from "./imports/TYPE_C_31_M_12"
import { XC6206P332MR as LDO } from "./imports/XC6206P332MR"

import { RFX2401C as FrontEnd } from "./imports/RFX2401C"
import { AP2112K_3_3TRG1 as TxSupply } from "./imports/AP2112K_3_3TRG1"
import { A_2450LP14B0100001T as OutputFilter } from "./imports/A_2450LP14B0100001T"

const at = (pcbX:number, pcbY:number, schX:number, schY:number, schSectionName:string, pcbRotation=0) =>
  ({pcbX, pcbY, schX, schY, schSectionName, pcbRotation, layer:"top" as const})
const jlc = (part:string) => ({jlcpcb:[part]})
const port = (pin:string) => "."+pin.replace("."," > .")
const net = (name:string) => "net."+name
const links = (pins:Record<string,string>) =>
  Object.fromEntries(Object.entries(pins).map(([pin,name])=>[pin,net(name)]))

type Part = [name:string, value:string, code:string, from:string, to:string, location:ReturnType<typeof at>]

export function RadioBoard({tx}:{tx:boolean}) {
  // Translate the matched RF section together to preserve its pad spacing.
  const rfAt: typeof at = (x,y,...rest) =>
    at(x+(tx ? 6.5 : 1.6), y-(tx ? 2 : 0.8), ...rest)
  // The receptacle opens toward the center of the lower board edge.
  const txOutline = [
    {x:-16,y:-17.1}, {x:16,y:-17.1}, {x:16,y:6.9}, {x:-16,y:6.9},
  ]
  const capacitors:Part[] = [
    ["C1","1uF","C52923","VIN","GND",at(tx ? -14 : -9.8,tx ? -8 : -3.05,-22,-4,"Power")],
    ["C2","1uF","C52923","V33","GND",at(tx ? -6 : -3.5,tx ? -7 : -3.45,-20,-9,"Decoupling")],
    ["C3","100nF","C1525","V33","GND",at(tx ? 4.1 : 4.4,-6.6,-18.6,-9,"Decoupling")],
    ["C4","10nF","C15195","VPA","GND",rfAt(-2.45,0.4,0,-5,"Radio")],
    ["C5","10nF","C15195","VREG","GND",rfAt(-0.7,0,4,-5,"Radio",90)],
    ["C6","470nF","C47339","VREG","GND",rfAt(4.9,6,5.4,-5,"Radio")],
    ["C7","100nF","C1525","V33","GND",rfAt(4.4,3.8,-17.2,-9,"Decoupling",90)],
    ["C8","100nF","C1525","V33","GND",rfAt(tx ? 2.3 : 1.15,7.5,-15.8,-9,"Decoupling")],
    ["C9","0.8pF","C326068","RF_RAW","GND",rfAt(-2.15,2.2,19,-2,"Match",-90)],
    ["C10","1.2pF","C76955","RF_M1","GND",rfAt(-4.75,2.2,24,-2,"Match",-90)],
    ["C11","1.2pF","C76955","RF_M2","GND",rfAt(-7.25,2.2,29,-2,"Match",-90)],
    ["C12","0.5pF","C76912","RF_M1","RF_M2",rfAt(-6,5.25,25,5,"Match",180)],
    ["C13","100pF","C1546","RF_M2",tx ? "RF_DRIVE" : "ANT",rfAt(tx ? -7.9 : -8.4,3.75,32,2,"Match",180)],
  ]
  const inductors:Part[] = [
    ["L1","3nH","C269824","RF_RAW","RF_M1",rfAt(-3.5,3.75,21,2,"Match",180)],
    ["L2","2.5nH","C237342","RF_M1","RF_M2",rfAt(-6,3.75,26,2,"Match",180)],
  ]
  const frontEndCaps: Part[] = [
    ["C14","0.3pF","C76909","RF_PA","GND",rfAt(-15.1,1.95,44,7,"PA",-90)],
    ["C15","220pF","C1530","V33","GND",rfAt(-12.6,0.2,-14.4,-9,"Decoupling")],
    ["C16","1uF","C52923","V33","GND",rfAt(-14.95,-0.7,-13,-9,"Decoupling",180)],
    ["C17","4.7uF","C19666","V33","GND",rfAt(-17.75,-0.5,-11.6,-9,"Decoupling")],
  ]
  const frontEndControls: Part[] = [
    ["R2","1k","C11702","FEM_TX_GPIO","FEM_TX_EN",rfAt(-10.55,0,42,-5,"PA")],
    ["R3","1k","C11702","FEM_RX_GPIO","FEM_RX_EN",rfAt(-10.55,-1.65,47,-5,"PA")],
    ["R4","5.1k","C25905","FEM_TX_EN","GND",rfAt(-8.35,0,42,-8,"PA")],
    ["R5","5.1k","C25905","FEM_RX_EN","GND",rfAt(-8.35,-1.65,47,-8,"PA")],
  ]
  const debugX = tx ? 13 : -5.4
  const debugY = tx ? -8.5 : 7.6
  return <board {...(tx ? {outline:txOutline} : {width:24,height:19})} thickness={1} layers={2} material="fr4"
      minViaHoleEdgeToViaHoleEdgeClearance={tx ? 0.2 : undefined} minTraceWidth={0.15} minTraceToPadEdgeClearance={0.15} minPadEdgeToPadEdgeClearance={0.15}
      autorouterVersion="beta_pipeline9" autorouter={{traceClearance:0.17}}  title={tx ? "USB-C transmitter" : "2.4 GHz receiver"}>
    <schematicsection name="Power" displayName="Power and USB" />
    <schematicsection name="Decoupling" displayName="3.3 V bypass capacitors" />
    <schematicsection name="Control" displayName="Microcontroller" />
    <schematicsection name="Status" displayName="RGB status indicator" />
    <schematicsection name="Radio" displayName="2.4 GHz transceiver" />
    <schematicsection name="Match" displayName="RF matching" />
    {tx && <schematicsection name="PA" displayName="RF power amplifier and output filter" />}
    <schematicsection name="Pads" displayName="Programming and I/O" />
    <net name="GND" isGroundNet />
    <net name="VIN" isPowerNet />
    <net name="V33" isPowerNet />
    <copperpour name="Reference ground" layer="bottom" connectsTo="net.GND" unbroken={false} useThermalReliefs={false} />
    {tx && <>
      <Receptacle allowOffBoard name="J1" {...at(0,-13,-34,4,"Power")} connections={links({
        EH1:"GND",EH2:"GND",EH3:"GND",EH4:"GND",A1B12:"GND",B1A12:"GND",
        A4B9:"VIN",B4A9:"VIN",A5:"CC1",B5:"CC2",A6:"DP",B6:"DP",A7:"DM",B7:"DM",
      })} />
      <resistor name="R1" resistance="5.1k" footprint="0402" supplierPartNumbers={jlc("C25905")}
        {...at(-7,-11.5,-28,5,"Power")} schRotation={-90} connections={links({pin1:"CC1",pin2:"GND"})} />
      <resistor name="R6" resistance="5.1k" footprint="0402" supplierPartNumbers={jlc("C25905")}
        {...at(7,-11.5,-25,5,"Power")} schRotation={-90} connections={links({pin1:"CC2",pin2:"GND"})} />
    </>}
    {tx
      ? <TxSupply name="U3" {...at(-10,-8,-19,2,"Power",90)}
          connections={links({VIN:"VIN",EN:"VIN",VOUT:"V33",GND:"GND"})} />
      : <LDO name="U3" {...at(-6.6,-3.3,-19,2,"Power")}
          connections={links({INPUT:"VIN",OUTPUT:"V33",GND:"GND"})} />}
    <MCU groundPadDrill name="U1" {...at(0.375,tx ? -7.4 : -6.3,-8,2,"Control",180)} connections={links({
      pin1:"V33",pin21:"GND",pin6:"CS",pin7:"SCK",pin8:"MISO",pin9:"MOSI",
      pin10:"BUSY",pin11:"IRQ",pin12:"RF_RESET",pin14:"DIO",pin16:"DCK",
      pin19:"LED_B",
      ...(tx ? {pin17:"DM",pin18:"DP",pin2:"FEM_TX_GPIO",pin3:"FEM_RX_GPIO",pin4:"LED_R",pin5:"LED_G"} : {pin4:"OUT1",pin5:"OUT2",pin2:"LED_R",pin3:"LED_G"}),
    })} />
    <StatusLED name="D1" cadModel={{ jscad: statusLedBody }} {...at(tx ? 9 : 9.65,tx ? -14.7 : 7.2,2,-20,"Status")}
      connections={links({pin2:"V33",pin1:"BLUE_K",pin3:"GREEN_K",pin4:"RED_K"})} />
    {[["R7","LED_R","RED_K"],["R8","LED_G","GREEN_K"],["R9","LED_B","BLUE_K"]].map(([name,gpio,cathode],i) =>
      <resistor key={name} name={name} resistance="1k" footprint="0402" supplierPartNumbers={jlc("C11702")}
        {...at(tx ? 6.5 : 6.5,(tx ? -15.9 : -4.6)+i*1.1,-2,-18-i*2,"Status")}
        connections={links({pin1:gpio,pin2:cathode})} />)}
    <Radio name="U2" {...rfAt(1,4,4,2,"Radio")} connections={links({
      pin1:"VPA",pin2:"VREG",pin3:"RF_RESET",pin4:"XT_A",pin6:"XT_B",
      pin5:"GND",pin7:"BUSY",pin8:"IRQ",pin11:"V33",pin12:"VREG",
      pin13:"GND",pin15:"V33",pin16:"MISO",pin17:"MOSI",pin18:"SCK",pin19:"CS",
      pin20:"GND",pin21:"GND",pin22:"RF_RAW",pin23:"GND",pin24:"GND",pin25:"GND",
    })} />
    <Crystal loadCapacitance="10pF" name="X1" {...rfAt(1.85,-0.45,10,8,"Radio",90)} connections={links({pin3:"XT_A",pin1:"XT_B",pin2:"GND",pin4:"GND"})} />
    <UFL name="J2" {...rfAt(tx ? -19.6 : -10.93,tx ? 3.25 : 3.75,tx ? 60 : 36,2,tx ? "PA" : "Match",90)}
      connections={links({pin1:"ANT",pin2:"GND",pin3:"GND"})} />
    {tx && <>
      <FrontEnd name="U4" {...rfAt(-12.2,3,43,2,"PA",90)} connections={links({
        pin1:"GND",pin2:"GND",pin3:"GND",pin4:"RF_DRIVE",pin5:"FEM_TX_EN",pin6:"FEM_RX_EN",
        pin7:"GND",pin8:"GND",pin9:"GND",pin10:"RF_PA",pin11:"GND",pin12:"GND",
        pin14:"V33",pin15:"GND",pin16:"V33",pin17:"GND",
      })} />
      <OutputFilter name="FL1" {...rfAt(-17.05,3.25,53,2,"PA",-90)} connections={links({
        pin1:"GND",pin2:"RF_PA",pin3:"GND",pin4:"GND",pin5:"ANT",pin6:"GND",
      })} />
      {frontEndControls.map(([name,value,code,a,b,location]) =>
        <resistor key={name} name={name} resistance={value} footprint="0402"
          supplierPartNumbers={jlc(code)} {...location} schRotation={b === "GND" ? -90 : 0}
          connections={links({pin1:a,pin2:b})} />)}
    </>}
    {(tx ? [...capacitors,...frontEndCaps] : capacitors).map(([name,value,code,a,b,location]) =>
      name === "C12" ? <RFMatchCap key={name} name={name} footprint="0402" {...location}
        connections={links({pin1:a,pin2:b})} /> :
      <capacitor key={name} name={name} capacitance={value} footprint={name === "C17" ? "0603" : "0402"} supplierPartNumbers={jlc(code)}
        {...location} schRotation={b === "GND" ? -90 : 0} connections={links({pin1:a,pin2:b})} />)}
    {inductors.map(([name,value,code,a,b,location]) =>
      <inductor key={name} name={name} inductance={value} footprint="0402" supplierPartNumbers={jlc(code)}
        {...location} connections={links({pin1:a,pin2:b})} />)}
    <pinheader name="J3" pinCount={4} pitch={2.54} gender="male" holeDiameter={1} platedDiameter={1.7}
      manufacturerPartNumber="B-2100S04P-A110" supplierPartNumbers={jlc("C124378")}
      {...at(debugX,debugY,-20,-14,"Pads",tx ? 90 : 0)} connections={links({pin1:"GND",pin2:"V33",pin3:"DIO",pin4:"DCK"})} />
    {["G","3V3","DIO","DCK"].map((label,index) =>
      <silkscreentext key={label} text={label} pcbX={tx ? debugX-2.2 : debugX+(index-1.5)*2.54} pcbY={tx ? debugY+(index-1.5)*2.54 : debugY-2} fontSize={tx ? 0.64 : 1} />)}
    {!tx && <>
      <pinheader name="J4" pinCount={2} pitch={2.54} gender="male" holeDiameter={1} platedDiameter={1.7}
        manufacturerPartNumber="B-2100S02P-A110" supplierPartNumbers={jlc("C124375")}
        {...at(-7.3,-7.2,-9,-14,"Pads")} connections={links({pin1:"VIN",pin2:"GND"})} />
      <pinheader name="J5" pinCount={4} pitch={2.54} gender="male" holeDiameter={1} platedDiameter={1.7}
        manufacturerPartNumber="B-2100S04P-A110" supplierPartNumbers={jlc("C124378")}
        {...at(9.7,-1.16,0,-14,"Pads",90)} connections={links({pin1:"OUT1",pin2:"OUT2",pin3:"GND",pin4:"VIN"})} />
      <silkscreentext text="B+" pcbX={-8.57} pcbY={-8.9} fontSize={1} />
      <silkscreentext text="B-" pcbX={-6.03} pcbY={-8.9} fontSize={1} />
      <silkscreentext text="G" pcbX={7.65} pcbY={0.11} fontSize={0.8} />
      <silkscreentext text="VIN" pcbX={7.65} pcbY={2.65} fontSize={0.7} />
      <silkscreentext text="O1" pcbX={7.65} pcbY={-4.97} fontSize={1} />
      <silkscreentext text="O2" pcbX={7.65} pcbY={-2.43} fontSize={1} />
    </>}
    <trace from=".U2 > .pin4" to=".X1 > .pin3" pcbPath={[".U2 > .pin4",{x:0.25,y:-2.75},".X1 > .pin3"]} thickness={0.15} />
    <trace from=".U2 > .pin6" to=".X1 > .pin1" pcbPath={[".U2 > .pin6",{x:1.25,y:-2.76},{x:2.36,y:-2.76},{x:2.42,y:-2.9},{x:2.42,y:-4.61},{x:1.88,y:-5.15},".X1 > .pin1"]} thickness={0.15} />
    {<>
      <trace name="Supply bypass ground" from=".C2 > .pin2" to=".U1 > .pin21"
        pcbPath={[".C2 > .pin2", {x:1.1,y:0}, {x:1.1,y:0,via:true,toLayer:"bottom"}, {x:1.1,y:0}, ".U1 > .pin21"]} thickness={0.2} />
      <trace name="MCU bypass ground" from=".C3 > .pin2" to=".U1 > .pin21"
        pcbPath={[".C3 > .pin2", {x:1.1,y:0}, {x:1.1,y:0,via:true,toLayer:"bottom"}, {x:1.1,y:0}, ".U1 > .pin21"]} thickness={0.2} />
    </>}
    {tx && <trace name="PA exposed pad to ground plane" from=".U4 > .pin17" to=".U4 > .pin12"
      pcbPath={[
        ".U4 > .pin17",
        {x:1.62,y:1.62}, {x:1.62,y:1.62,via:true,toLayer:"bottom"}, {x:1.62,y:1.62},
        {x:-1.62,y:1.62}, {x:-1.62,y:1.62,via:true,toLayer:"top"}, {x:-1.62,y:1.62},
        ".U4 > .pin12",
      ]} thickness={0.32} />}
    {tx && <trace name="PA harmonic shunt" from=".FL1 > .pin2" to=".C14 > .pin1"
      pcbPath={[".FL1 > .pin2",{x:0,y:1.95},".C14 > .pin1"]} thickness={0.22} />}
    {/* Short top-layer RF interconnect. The antenna feed impedance depends on the fabrication stackup. */}
    {[
      ["U2.pin22","L1.pin1"],["L1.pin1","C9.pin1"],
      ["L1.pin2","L2.pin1"],["C10.pin1","L1.pin2"],["L2.pin1","C12.pin1"],
      ["L2.pin2","C13.pin1"],["L2.pin2","C12.pin2"],["C11.pin1","L2.pin2"],
      ...(tx ? [
        ["C13.pin2","U4.pin4"],["U4.pin10","FL1.pin2"],["FL1.pin5","J2.pin1"],
      ] : [["C13.pin2","J2.pin1"]]),
    ].map(([a,b]) => <trace key={a+b} from={port(a)} to={port(b)} pcbPath={[port(a),port(b)]} thickness={0.22} />)}
    <silkscreentext text={tx ? "USB RF TX" : "2.4G RX"} pcbX={tx ? -8 : 6} pcbY={tx ? 4.9 : 8.4} fontSize={1.15} />
  </board>
}