Skip to content
Snippets Groups Projects
Forked from Per Lindgren / e7020e_2021_hw
21 commits behind the upstream repository.
Henrik Alsér's avatar
Henrik Alsér authored
a685fae0
History
Name Last commit Last update
.vscode
README.md

General lab info

In this course you will use Git extensively. To master Git and/or similar content management system with version control is absolutely essential engineering skill. If you have not used Git or similar, here is your chance to learn.

If you are under Linux, you likely have Git installed by default (else use your Linux package manager to install it). If you are under Windows, then look at https://git-scm.com/downloads. If you get stuck, use the Telegram group to ask questions and help each other out.

In general, to pass lab assignments you will:

  • Create a user on https://gitlab.henriktjader.com/
  • Fork the lab repository
  • Clone your repository to your local machine
  • Solve the lab assignment(s)
  • Commit your repository
  • Submit link to your repo as a Canvas assignment (you will then be assigned two repos to review)
  • Make review as Gitlab Issue(s)
  • Submit links to the repos you have reviewed as a Canvas assignment.
  • Attend the reviews/issues you have received
  • Submit link to you final repo as a Canvas assignment.

Pay strict attention to the deadlines (the course depends on everyone being on time, to give and get reviews etc.). If you get sick and due to that cannot complete an assignment in time, give us a heads up in Telegram, and we will try to find a solution.

Remember to commit often, this allows you to rollback to previous states. Name your commits so that it reflects the recent changes, then your git log will make much more sense, and will be easier to navigate.


Lab 1 (Schematics)

The main topic of this lab is to give you a good understanding on how to use the information in Datasheets to draw components and connect them in the schematic view. This lab should be done individually.

Task 1

Read the whole lab instruction before you start.

Design and connect all necessary components to the microcontroller (MCU). Some of the components can’t be found in the standard libraries so you have to draw some of them by yourself and extract the necessary information through datasheets. The work flow of KiCad:

  • Add components and draw the schematic of your design
  • Assign a footprint to your schematic components
  • Generate a net-file
  • Layout (Lab2)

1) Adding the microcontroller

Start ”KiCad” and follow the instructions:

  • Make a new project.
  • Open the schematic. (double-click on the *.sch-file)
  • Click on Preferences/Manage symbols libraries.
  • Check the library MCU_ST_STM32F4 is active in your project.
  • Click on the ”Place symbol”-button to the right and then click on the sheet where you want the component to be placed.
  • Find your microcontroller (STM32F411RETx) in the stm32-library.
  • You have now added the microcontroller to your project. It needs additional components to make it run, e.g. a crystal (for stable USB clocking), decoupling capacitors, power and a SWD (Serial Wire Debug) connector to program it.

2) Decoupling Capacitors

To stabilize the voltage at the pins to the MCU, decoupling capacitors are used. When assigning decoupling capacitors for a microcontroller running at 50-100MHz, 100nF ceramic capacitors are usually suitable for each power-pin.

However, this microcontroller needs additional decoupling capacitors for its internal voltage regulator and analog peripherals, you can find the datasheet by searching on internet (Hint: ”STM32F411 datasheet”).

  • Open the datasheet and look at the figure in section 6.1.6.
  • Add capacitors to the power pins as the figure shows.
    (Place component-button, click on sheet, device/C)
  • Hoover over the capacitor, press ”V” and give the capacitor its value e.g.,100n.
  • Connect them to the microcontroller using the ”wire” button. (W key)

You should have at least 8 capacitors connected to the microcontroller.

3) Adding supply symbols

VDD should be connected to +3.3V and VSS should be connected to ground. These nets are often used in a schematic, so to avoid drawing nets across the whole schematic you can add power ports. All power ports are global in your design, which means that all power ports of the same kind is connected to each other.

  • Click on the Place power port button.
  • Select ”+3.3V”.
  • Add power ports on appropriate places and connect them to the pins and capacitors that should have 3.3 volt.
  • Do the same thing with GND.
  • Note that the VCAP1 pin should NOT be connected to +3.3V.

4) NRST Reset pin

The NRST pin is an active low (0) input used to reset the MCU. There is an internal pull-up resistor keeping the pin high (allowing the MCU to run). For more info on what a pull-up resistor is, search the internet for ”Pull-up resistor”.

Later we will add a Reset Button, so that you can force reset even when the MCU is powered and running.

5) Pull-down resistor to BOOT0 (boot mode)

The microcontroller can boot in different modes, similar to how you can enter the BIOS when booting your PC by pressing the F2-key (or other F-key). This can save you in tricky situations, for example if you are playing with the main clock or with sleep modes and it crashes, making you unable to upload (flash) a new binary to the microcontroller. You can boot in "safe mode" by pulling this pin high (so it does not run you code on startup) allowing you to upload a new binary even if your code would otherwise brick your MCU.

  • Add a 10k pull-down resistor to the BOOT0 pin.
  • Add a "jumper" between BOOT0 and +3.3v, so that you can easily boot into "safe mode" by shorting these two terminals. You could make this a 3-pin header and "no-connect" the third terminal in order to provide a place to store the jumper when not in use.

6) Crystal

The crystal will resonate at a specified frequency. Its waveform will be used as an input to the PLL (Phase Locked Loop) that will multiply the crystal’s frequency. This is the crystal that will be used: https://www.elfa.se/en/quartz-surface-mount-12mhz-iqd-lfxtal003210/p/17452154

  • Click on the Place component button.
  • Find the device/Crystal.
  • Place it close to PH0 and PH1, pin 5 and 6 (RCC_OS_CIN and RCC_OSC_OUT).
  • Connect the component with wires to the mentioned pins. Value 12MHz.
  • Connect one 22pF capacitor to each pin on the crystal and connect the other end of the capacitors to GND.

7) Serial Wire Debug (SWD) connector

To program and debug the MCU we will use a SWD connector (6 pin header). Sometimes it can be tricky to find all the information in the datasheet and user manual for the microcontroller, all the information you need is there, it will just take time to find it. However, it can then be useful to follow proven examples like your Nucleo board. This is the type of connector that will be used: https://www.elfa.se/en/straight-male-pcb-header-through-hole-rows-contacts-54mm-pitch-rnd-connect-rnd-205-00627/p/30093647

  • Add one conn/CONN01X06 (male).
  • Search for the Nucleo boards datasheet.
  • In this datasheet search for the table that explains the connector CN4 pinout. You can also investigate how they have connected the target MCU to these pins in the schematic below in the datasheet.
  • You can connect pins without wires going everywhere. Use ”net labels” (button to the right) to name one wire. It will connect all wires with the same name in the local sheet.
  • VDDTARGET→+3.3V. GND→GND. NRST→NRST. SWCLK→SWCLK (PA14). SWDIO→SWDIO (PA13). SWO→SWO (PB3)

8) Power from USB

One easy way to get power to your project is through USB. It can deliver up to 100mA without any negotiations.

  • Add a ”USBOTG” connector to your schematic. Already here you can think about how you should connect your mouse and use a suitable connector (mini, micro or even usb-c).
  • Find the USB pinout for your connector.

9) 3.3v Power Supply

The MCU wants to be powered from a 3.3V rail. To this end we will use a fixed LDO (low dropout) linear regulator, to convert a 5V input (from the USB connector) to a 3.3V output. We will use the AP2125N-3.3TRG1 for this.

Look in the datasheet for a typical application circuit. Later we will design the power supply for the PWM3389 sensor, which is a bit trickier.

10) PWM3389DM-T3QU Schematic Symbol

Download the general datasheet, and look at section 3. There you will find a reference schematic.

For some components (like the PMW3389DM-T3QU) there might not exist a pre-made library, so you will now learn how to draw your own component.

  • Click on Tools/ Symbol Library Editor.
  • Create a new library for your project and click on Create New symbol inthe new library).
  • Component name ”PMW3389”. OK.
  • Add pins and name them according to the datasheet. Remember to assign the correct pin number as well.
  • Make sure to set the ”Electrical type” on each pin according to usage (signal in/out, power in/out etc.) X marks a non connected pin. In our setting we don't use GPO so you can set it X.
  • Save by clicking on the ”Save current component to new library”-button (found at the top). This is only done for the first component, you can add several components to the same lib later.
  • Add the newly created component to your schematic.

Hint. Never, never ever, change the grid settings when placing the pins in the symbol.

11) 1.9v Power Supply

As you can see in the PWM3389DM-T3QU datasheet and reference schematics, the sensor requires a 1.9v power supply. This is much less common voltage for a fixed output LDO (try finding one from Elfa or rs-online and you will likely fail).

To that end, you can use an adjustable voltage regulator, such as MIC5235YM5-TR, which will let you set your desired output voltage using external resistors.

The circuit and equation for calculating the resistor values needed to acheive the desired the output voltage (1.9V) can be found in the datasheet for the regulator. Here you will also find information about input- and output capacitor values needed for proper operation.

Once you have added the 1.9v power supply you can add a new power net, and connect that to your PMW3389 component.

12) Reset button

Now add a reset button. Suitable value for capacitor is found in the MCU data sheet.

13) Power LEDs and test points

In order to see that your system is correctly powered, it is common to add test points for easy probing. It is also recommended you add LEDs to your power rails so you can see they're powered up correctly. You can use an LED such as , together with a suitable current limiting resistor. Aim for a forward current of about 2mA. You can use this LED calculator to calculate suitable resistor values for your LEDs. Use resistor values from the E12 series.

14) SPI

SPI (Serial Peripheral Interface) is a common way to interconnect components synchronized with a clock signal. In our case the STM32F401/F411 will be the Master and the PMW3389 will be the slave (so all communication is driven by the MCU).

In order to allocate pins to peripherals there is a nice tool STM32CubeMX. Install STM32CubeMX (either using the link, or your package manager), select the target (smt32f401, e.g.) and find suitable (unused pins for) SPI communication. E.g., using SPI2 you can assign.

// Configure SPI
// spi2
// sck    - pb10,
// miso   - pc2,
// mosi   - pc3,
// ncs    - pb4,

Decide on which pins you want to use, and connect the PMW3389 to your MCU. You can connect the Motion signal to a free GPIO (its used to generate an interrupt when the sensor detects a motion event, for allowing wake from sleep mode). Likely you don't need this but you can add it in any case.

15) USB Data

Until now you have used the USB only to power the system, but you will need to add data lines +D/-D as well for communication. Check the data sheet for specifics.

You may also want to protect your system from ESD (Electrostatic discharge). To that end you may optionally add ESD protection circuitry.

16) Assign Footprint

It is very important that the pin numbering on your component is correct to the footprint in the library! Always double check with the datasheet. You will now associate each component to a footprint.

  • Annotate all the components, this will give your components a name.

  • Click on the ”Assign PCB footprints to schematic symbols” to associate components and footprints”-button at the top.

  • Click on the View selected footprint button at the top, it will display the footprint in question.

  • We recommend you to use 0805-size capacitors and resistors. Associate all the res. and ceramic caps. to 0805 respectively, Handsoldering. (Capacitors SMD and Resistors SMD)

  • Read in the datasheet or on the link for the voltage regulator and select the correct footprint. Make sure that all components are in stock for immediate delivery.

  • Repeat for the crystal and SWD connector.

  • MCU = HousingsQFP:LQFP-6410x10mmPitch0.5mm.

  • USBOTG = Connect:USBMini-B (or to your liking)

  • Don’t forget to save!

    Hint: Check that the numbering of the pins are correct! Hint 2: When you are working with your project later, you will probably not find all footprints in the standard library. There are good tutorials on youtube on how to draw your ownfootprints.

17) Electric Rule Check (ERC)

ERC is a check that detects if you have any ”lose ends”, meaning that it will give you a warning if you have a net with only one connection. It will also give you a warning if you have drawn a net to a component but the net and the component haven’t connected. To get the ERC to work as intended, you have to mark all the unused pins with a Not-connected flag, found to the right.

    1. ”Perform electrical rules check” button (Ladybug button).
    1. Do a ERC.
    1. Fix errors.4.
    1. Repeat point 1 until errors == 0 && warnings == 3. The GND net is not connected to a Power output, the 5 voltage neither and the capacitor connected to VCAP1 is not connected to a power output.

First Submission

In Canvas look for Lab1-First Submission, and submit a link to your repo there before the deadline.

Review

You will be assigned two repositories to review. Clone the repositories and compare to your solution.

Check each that each of the 17 steps has been correctly conducted and that the calculated values for generating 1.9v makes sense, and that the LED selection/current limitation is within specs.

Make an issue in each repository that you review with detailed comments to the author/repo owner. Later follow up on those comments and close them when your issues have been addressed to your satisfaction.

In Canvas look for Lab1-Review, and submit links to the repositories you have reviewed before the corresponding deadline.

Final

Address the raised issues, and commit your fixes. This is an iterative process, where you help each other coming up with a working solution by leading questions, hints etc. (Just giving the answer directly is not particularly fruitful, its a learning process right.)

Once you have addressed all issues, look in Canvas for Lab1-Final, and submit a link to your repository.