shownb / shownb.github.com

shownb.github.io
shownb.github.io
5 stars 1 forks source link

键盘pcb指导 #58

Open shownb opened 4 years ago

shownb commented 4 years ago

来自 https://github.com/ruiqimao/keyboard-pcb-guide

按照kicad 5.1.5来翻译。

想为一个键盘设计pcb,你来对地方了。

软件安装

我们用kicad,还有一些组件库 要用到的是Hasu's keyboard_partsfootprint library. 最好还有 switch footprint library.

原理图

新建一个项目 起个名字,然后用力双击.sch就得到一个空白原理图了。 添加组件库(新版kicad叫symbol库了。) 找到 首选项->管理符号库 添加你下载回来的lib文件,然后就可以开始了 一下快捷键,非常有用,配合鼠标

m: 鼠标选择组件,然后按m可以移动防止元件
g: 也是移动组件,但是线会跟着移动
c: 复制组件
e: 编辑组件
r: 转组件方向
y: 镜像组件
del: 删除组件
esc: 对当前命令中断

试一下 放置->符号 你的光标会变成一支二逼铅笔. 随便往原理图上点一下. 在淡出的对话框里面的keyboard_parts库里选择ATMEGA32U4:

点OK, 然后在我们图上选择放置的地方. 可以右键点元件的属性改变名字为u1

The next part we'll want to place is the crystal, which is the part that tells the controller how fast to run. Look for the XTAL_GND component and place it next to the controller. Change the reference to X1.

Next, we're going to want to add 2 decoupling 电容 (C_SMALL). These capacitors will basically help prevent the signal to the controller from accumulating too much noise. There's a formula for determining the capacitance you need for these capacitors, but for now, we'll use a crystal with 18pF load capacitance, so these decoupling capacitors will be 22pF. Name them C1 and C2, and change their values to 22p. Also add a GND symbol to represent ground, and connect everything using the wire tool (在右边的绿色线) like so:

crystal

Next, we'll add decoupling capacitors for VCC, our power source. We will generally want one 0.1uF capacitor for each VCC/AVCC on the controller and one 4.7uF capacitor for UVcc. In our case, we want 4 0.1uF capacitors and 1 4.7uF capacitor, like so:

capacitors

Let's hook up a reset switch. For this, you'll want a switch (SW_PUSH) named SW1 and a 10k 电阻 (R) named R1. If you want to know why we want a pullup resistor and what a pullup resistor even means, here is a good explanation from Sparkfun. But for now, here's how it should be hooked up:

reset

Now let's put a 10k resistor named R2 on HWB/PE2 pin and connect it to ground. We want a resistor here because it tells the microcontroller that when we press the reset button, we want to go into the bootloader so that we can flash a new layout onto it!

hwb

下面,添加一个usb接口. 从组件库选择USB_mini_micro_B并命名为J1. 连接 VUSB 到 VCC 和 Uvcc, 在连接D-和D+的中间放连个 22 欧的电阻R3和R4. 接地.放置电容等,像图片下面一样:

usb

Let's connect all the VCC connections together and all the GND connections together. Normally, you would place a capacitor between AVCC and VCC if you were using the built-in ADC (analog to digital converter), but we don't care about that for a keyboard, so just directly connect them. Here's what everything look like at this point:

overview

我们搞键轴的矩阵把. 我们搞简单点,搞2*2的矩阵。我们用 KEYSWD 组件(代表键轴和二极管) 就好像你飞线一样连接。不忘记给他们命名。

matrix

把他练到mcu上面去. 我们用标签来做这个事情 (右侧下方带有绿线的A). For our example board, we'll use PF0 for row0, PF1 for row1, PF4 for col0, and PF5 for col1:

matrix controller

最后,给没有连线的都打个没连接的标签. 用这个工具(蓝色X右侧工具栏) 最后我们的原理图是这样的 final schematic

元件封装

靠,很复杂,要自己加载完元件封装库,然后再选择对应元件。 我们需要告诉 KiCad 每个组件是什么意思. 点击个图标 CvPcb:

cvpcb icon

如果是第一个运行,我们添加元件封装库. Click 首选 > 管理封装库 选 "keebs.pretty" 和 "keyboard_parts.pretty" 的文件夹

footprint libraries

然后自己关联每个东西。

associations

保存退出。

生成网表

没什么好说的,看图 netlist button

PCB

到pcb了,保存一下你的原理图,然后回到项目,打开.kicad_pcb,进入pcb的编辑器:

blank pcb editor

查看 “原件封装” 的库还在不在,不在就导入

设置网格 图示 > 网格设置, and set Units to Inches and Size X and Size Y both to 0.09375, like so:

dimensions

告诉 PCB 编辑器用用户自己定义的网格 "User Grid".

加载网表:

read netlist

现在你应该看到所有封装都在屏幕中间了。:

stack of footprints

Before we separate them, let's hide the 飞线, which is essentially the lines that detail the electrical connections in the board. Go to the "Render" tab on the right and uncheck "Ratsnest", like so:

hide ratsnest

Here are some useful commands for the PCB editor:

m: 移动封装
g: 拖封装并保持连线
e: 编辑封装
r: 旋转封装
f: 反转封装
del: 删除封装
esc: 取消当前操作

将键轴封装保持在正面,其余封装在另外一面,用flip功能吧,我估计是:

separated footprints

元件放置

把键轴的封装放好之后. 双击封装然后在 "移动并放置" 的选项里面 "锁定封装" 防止我们不小心乱动了:

move and place

Let's put our 二极管 under our switches first (THIS PLACEMENT WILL ONLY WORK FOR SMD DIODES). Make sure each diode corresponds to its switch:

diodes

Let's move our microcontroller next to the switches, like so:

microcontroller next to switches

Now the most important part of PCB design: the crystal. We need to make sure the traces to the crystal are as short as possible and that they are roughly the same length. An easy way to tell what pads are supposed to connect to what pads is to use the "highlight net" tool on the right. You use the tool and simply click on a pad, and it and the pads it connects to are highlighted. For this example, I put the crystal above the microcontroller and rotated it by 45 degrees:

crystal placement

Then place the 2 decoupling capacitors next to their respective pads:

crystal capacitors

You don't need to worry about connecting ground to any other grounds, since we will be putting a ground plane under all the components. More on that later.

Next, we want to place the decoupling capacitors for VCC. Place a 0.1uF capacitor next to each VCC and AVCC and the 4.7uF capacitor next to UVCC. At this point, I discovered that the microcontroller was a little too close to the switches, so I move it out a little bit:

capacitors

Let's put our last capacitor on, which will fit nicely between C5 and C7:

last capacitor

Now let's place our mini USB connector and our reset switch. Here's where I put mine:

usb and reset

And our last components, the resistors. Place them in a way such that routing traces later will be easier. Here's how I did mine:

resistors

Note that at this point, my grid sizes are at 0.0234375" in each dimension to allow for finer positioning.

Edge Cuts

Now let's draw out the outline for our board! Go to the "Layer" tab on the right and click next to "Edge.Cuts" to move the blue arrow down to it, effectively selecting it as the layer we're going to draw on:

edge.cuts

Use the drawing tools on the right to draw an outline for the PCB:

drawing tools

Here's how I cut mine:

cuts

Ground Plane

We want to put a ground plane in the PCB. Essentially, a ground plane is just one big chunk of copper that's connected to ground on both sides of the PCB. It's useful when we have a lot of components that are connected to ground, like in our PCB. To do this, we want to use the zone tool:

zone tool

Make sure the blue arrow is back on F.Cu in the Layers tab. Then, select the zone tool and click on one of the corners of the edge cuts. A dialog will pop up asking you which net the zone should be associated with. Select GND and hit "OK":

gnd

Now, draw a border where you put the edge cuts. When you get back to the starting point, double click. You will see a red hatch pattern around your PCB. Now right click on the edge of the zone and select Zones > Duplicate Zone onto Layer. The same dialog will pop up, but this time, select B.Cu on the left and hit "OK". Now your PCB will have both a red and green hatch pattern around it:

hatches

Now right click and select each zone, and for each zone, select Zone > Fill Zone. Make sure the option to show filled zones is selected on the left:

zone options

And your PCB should now look something like this:

filledzones

Now choose the option to hide filled zones. We don't want them while routing.

Routing

Now we want to do some routing. To route, we want to use the "add tracks and vias" tool:

tool

I would also recommend setting your grid size to 0.25mm for this part.

Let's get some terminology out of the way first:

While routing, you can press v to switch layers and create a via.

Now that we've gotten that out of the way, let's set some ground rules. Well, one ground rule. Namely, no vias between the crystal and the controller. Vias can potentially lead to a small amount of capacitance that can actually affect our crystal operation, so that's a big no no.

Now let's start routing. The first thing you want to route is always the crystal and the decoupling capacitors next to it. Luckily for us, this is pretty simple. To get started, make sure you have the B.Cu layer selected, since that's where most of our components are. Here's how I did mine:

crystal

Next, let's route the VCC lines. Make sure you route the decoupling capacitors to their appropriate VCC pins on the microcontroller. And don't forget to route to the USB port!

vcc

Now let's route the UCap capacitor and the rest of the resistors. Keep in mind that a well designed PCB will also look aesthetically pleasing. Here's how I routed the remaining capacitor and the resistors:

resistors

Note that I changed the routing of the switch to accommodate for the traces for the USB data resistors. You can also turn on the ratsnest in the Render tab on the right to check for any connections you have missed or any ground connections you may have accidentally broken while tracing routes. Ignore the traces that lead to the diodes and switches. We'll route those next. It turns out, I forgot to route all of the VCC pads together and broke a few ground connections. This is what my PCB looked like after fixing all the missed connections:

fixed

And now we'll route the diodes and switches. First, route the diodes and switches together before touching the controller:

diodes and switches

And finally, we'll route the controller to the rows and columns:

done

Turn on your zones, fill in any missing ground planes, press b to update the zones, and voila:

voila

Double check that all connections have been made using the DRC (design rule check) tool:

drc

Click "Start DRC" and make sure there are no problems. Then click "List Unconnected" and check for unconnected nets. If both sections are blank, then...

Your PCB is finished!

Go to View > 3D View and turn on Preference > Realistic Mode. Turn up all the settings you want, set your background color, and you'll have a nice render of your PCB! You can even select the Text tool and the B.SilkS layer to put your name on your PCB:

render

Mounting Holes

Now, with a normal PCB, you would want to add some mounting holes. The way you would add those would be by creating custom footprints with NPTH (non-plated through hole) pads and adding them to your PCB. This is out of scope for this guide, but this is something that is very simple to Google!

Production

Now that you've finished designing your PCB, you want to get it made, right? Let's get you started on that.

Gerber Files

First thing is to generate our "gerbers", which are essentially files that tell the PCB manufactuer what is on each layer. Click on the "plot" icon:

plot

Specify a directory to put your gerber files into and make sure the F.Cu, B.Cu, B.Paste, F.Paste, B.SilkS, F.SilkS, B.Mask, F.Mask, and Edge.Cuts layers are selected. Check the "Use Protel filename extensions" option, and make sure the format is "4.6 (unit mm)":

settings

Click on "Plot" to generate your files.

Then, click on "Generate Drill File". Set the output directory to be the same as before, set your drill units to "Inches", and your Drill Map File Format to "PostScript". Make sure "Mirror y axis" is unchecked, and then click "Drill File":

drill files

Now close the dialogs.

Put all the files you just generated into a zip file:

zip file

Upload your files onto http://www.gerber-viewer.com/ and make sure all the layers look good. If so, you're ready to send your PCB off to the manufacturer!

Manufacturer

Now, there are a lot of options here. I've personally used PCBWay (referral link) to great success, but there are plenty of other cheap PCB prototyping services, such as EasyEDA, OSH Park and DirtyPCBs.

All of these services simply involve choosing some options for how your PCBs will be manufactuered (default settings are fine for all of them), then uploading the zip file you just created. If you want to change the color of your PCB, then the option you will want to look for is "solder mask color". The color of the text on your PCB will be "silkscreen color".

Once you receive your PCBs, you can simply use some solder paste and a hot air rework station to put everything together! If you're unsure of how to do this, there are plenty of resources online that can teach you the basics of SMD soldering.

Components