Search This Blog

Tuesday, August 7, 2018

Portable 103 - PCB

Projects / F103 Pod  Original post date:07/18/2018

Maybe this is the one?  I'll procrastinate a little longer and hope to find some fault or better routing than this.


When the lead time is 4+ weeks, a few extra days of thinking over is better than rushing things only to respin again.  I rarely have a board that need a few simple mods to get running.

Here is the top stop mask showing that the buttons pads are indeed free of resist.


Silicon Labs: AN0046.pdf


I won't be able to match impedance due to the lack of space for wide tracks needed. 17cm is a lot of leeway.


I have done skew matching because of skew introduced by routing swap that was needed to match the connector pin orientation.  It was within the limit, but was easy enough to fix.



  • Fixed up the stereo connector - a bit shorter with slightly different footprint.
  • Fixed up footprint of SPDT switch at the 4 corners.
  • Modify 3D model for stereo connector
  • Mod footprints to keep silkscreen away from pads.  Don't rely board houses to clean them up.
  • Move & resize/thicken Reference Designators away from pads and vias.
  • Move text away from vias
  • Check for component clearances and buttons in 3D models

This is what it looks like.  I don't have the 3D models of MicroSD connector and special Mini-USB socket.

Board is on order.  Too late to change anything.  :P

I have done enough procrastinations, so at some point I need to send the board out.  I did find a small list of issues that could have caused me a board spin had I rush the layout a few days ago.

The Chinese MP3 player uses 0.6mm PCB. I really don't have much of a choice on the dense PCB, but to go with OSH Park 0.8mm 2oz.   They have 10 mil via for the higher density I need and ENIG (soft gold) for the buttons pads.

It would normally take 2-3 weeks for the 0.8mm PCB to be made and added anywhere between 2-3 weeks for the shipping.  You get the picture.  Lots of waiting again.  Probably not going to see the PCB until after the closing date of this round of the contest.

Here is the order link (untested PCB)

Order from OSH Park  - do not order this version.
I made a couple of mistakes so far due to stereo connector footprint issues.




It's getting into the tracking hell hole as UPS doesn't list the Canada Post tracking number.


It took about a week for the 0.8mm PCB and another 2 weeks for shipping.

Portable 103 - 10 pins Mini-USB connector

Projects / F103 Pod  Original post date:02/02/2018

SWD is one of the things I would like to have available without having to open up the case all the time. One way to do that is to fool around with the ID pin and share pins with USB.

I am tempted to use those 10 pin Mini-USB connectors which are used in some cameras for composite video and audio.  They are backwards compatible with regular 5-pin USB plugs.

I have ordered 10 receptacle and 10 plugs from here. I found a datasheet for something that matches the receptacle here. Unfortunately that means pushing back this project for quite a bit as I want to confirm the footprints before committing to a final PCB design.  I guess I could work a bit on the firmware for the time being.

Aliexpress called receptacle a Type-B while the datasheet call it Philips style.


Looks like the receptacle could be a Mini-AB which could accommodate the Mini-B plug which is the only style still used.



The connectors arrived a while back, but I have been procrastinating.  The space of the connector pins are such that you don't want to solder it free hand.  So I layout a PCB for it, but some of the mechanical dimensions are not easily measurable until you made one.  And of course you don't expect to find the mechanical drawings for something on Aliexpress that easily.

So forward to today, I finally made the double sided PCB using toner transfer while doing a batch for a flashlight mod.  I used the drill holes for aligning the paper for the second pass of the toner transfer and etching process.


Here is the back side.  I have to bend the pins slightly so that it straddles the PCB.  (need a thinner PCB).  There is a gap between the connector and the PCB to accommodate a plastic bit in the housing.  I even file the curvy outline to match the housing.

I stagger the breakout to 0.05" spacing to make it easier to solder.  The spacing is such that it would line up with a ribbon cable broken into two rows.


This is how it looks fitting into the the other half of the housing.


Still have no clue how what I need to do on the PCB outline to get boards fabbed.  It is small and violates a few of the DRC for copper to outline spacing and a few manufacturing rules.  I managed to make on with very primitive hand tools.  I guess I'll procrastinate a bit more.

BTW this breakout connector is only need for SWD debugger.  A regular Mini-USB can be used for normal operation.

I messed up.  I should have made a new footprint for the male side of the connector, but instead I used the female pin ordering.  It is a mirror image so the left/right ordering are flipped.  I am going to patch this PCB as is.  As for the SWD side, I'll fix the layout for the main PCB.

I have spent too much time thinking about round cables vs ribbon cables.  I have both types and even the right size, but settled on ribbon cables.

General warning:

Ribbon cables are designed for IDC (Insulation Displacement Connector) and not meant to be soldered.  Solder wicks up inside the cable and where flexible part meets non-flexible can create stress points for failures.  The staggering helps the front row, but not the back.  There isn't much space left, so can't extend the PCB.  :(

I separate the wires and work on the short ones first. When that's done, solder down the row of long ones.  The cables I have aren't very solderable even with a very aggressive flux and extra flux applied.

There are 2 pairs of 4 conductor ribbon cables.  I could have folded a set of 8, but these came from my  scrap pile already broken out.


This is how they fit into the housing.  The opening is just wide enough.  There are two slots on the connector housing meant for a metal strain relief to hold the cable in place.  They don't come with one.


I could have cut a tin can or some transformer cores, but settled for 3/8" heat shrink tubing instead.  I carefully roll up the heat shrink like a pair of socks with a pair of needle nose pliers.  It is not easy, but the tubing is soft so you'll eventually get it.  I use low heat (100C) on my hot air tool to shrink the tubing.  The fold is slightly wider than the opening, so it would help to retain it.  The tubing protect the cable against the sharp corner at the opening and the extra stiffness of the heatshrink helps to spread the flexing point more evenly.


The two halves of the housing snapped together almost seamlessly.  I had to pied open this one earlier with a knife which leave some scars.


Once again there are different options for terminating the USB connections.  I bought some DIY USB type A plugs, some Micro USB breakout PCB.  I settle for the micro USB as they sell cables at the "dollar" store.


I have seen plastic housing for those PCB exactly once and not since.  BTW those two holes are for the pegs in the housing, but they sort of work for cable ties and nylon screws too.  This is a q&d way of strain relief for the solder joints. Too lazy to add tubing for the exiting cable.

I folded the cable and apply 3/4" heat shrink tubing over the whole thing to prevent shorts from random conductive object in my desk.

Good quality polyolefin tubing get soft sticky and can be weld together by applying pressure while cooling down.  All I have is cheap Chinese one here, so I use cheap Chinese super glue to seal the wide opening.


I'll leave the SWD side of the cable unterminated until the pin outs are finalized.


I have seen 4, 5 and 6 pins on the extra I/O, so this is a good thing that the plug physically would not go into other types of mini-USB sockets.

Portable 103 - Teardown


Projects / F103 Pod
Original post date:12/15/2017

One MP3 player arrived today. The LCD doesn't have the ugly yellow/blue filter from the description.

The plastic case is held together with 4 tabs near each of the corners and 2 on each end. I broke all of 4 corners tabs when I pried it opened with a knife. I think I'll have better luck with the 2nd batch from a different supplier as they are supposed to have screws and come with belt clip.

The PCB thickness is 0.026" (0.6mm). The stereo connector (0.2") and the LCD (0.086") are the tallest components on each side of the PCB.

The battery is a LiPo pack without any protection circuits nor a proper charger chips.  There is a silicon diode (CD1) in series from the VUSB as the charge circuit.

VUSB has a loose tolerance of 4.4V to 5.25V while a silicon diode drop is around 0.7V, so you might be charging the LiPO with up to 4.55V!  There are no current limiting other than the internal resistance of the USB cable, LiPO and power source. What can possibly go wrong?  (Cue Mission Impossible OP).

The battery ( 0.831" x 0.860" x 0.113") is held above the Micro SD connector with a piece of double sided tape. I estimate the battery capacity to be around 100mAHr based on size.


The LCD and the dome buttons are on the back side of the PCB.  The Red/Blue wires are the LCD backlight.  I measured 2.85V.  It is driven directly from pin 16 of the chip without a series resistor.


he back side of the LCD diffuser is taped to the PCB with a piece of double sided tape.  There are two sets of footprints to accommodate modules with different cable lengths.


PCB high resolution scans

I made a couple of high resolution (2400DPI) scans of the bare PCB with my flatbed scanner.  I am going to be using the scans for the measurements. I'll have to wait for the second batch from the different supplier.

Component side (Click for full resolution)
Top side (Click for full resolution)

  • The standoff keepout areas are marked with a Sharpie. They are in different location than the silkscreen.
  • Two of the pins covered by silk screen are not connected.  They are probably using I2C mode to access the MicroSD.  
  • One of the Mini-USB non-plated through holes encroaches into the "Next" button pad.  I'll resize the hole to try to minimize the effects and also might have to play around with the DRC to reduce the void.

I imported the bitmap into Eagle CAD and overlay it on top on the layout template from github and there seems to be a lot of discrepancies on the placements.

As I have learnt many times before, most of the freebies from someone else ended up costing me a lot.  I will be doing my own from scratch.


This is what the layout should look like.  The scanned image has the right X/Y scaling and aligns with the placement holes.


This is what I have done:

  • measure the PCB with a caliper
  • (previously done) rotate the scan to align with X/Y axis
  • reduce colour depth to 4. This make things goes faster while retaining details.
  • import into Eagle PCB as .BMP and 2400DPI
  • overlay measured board outline and main components

I found another discrepancy of the the SJ-2523 stereo connector footprint used.  According to the datasheet, the spacing between pin 1 and 2 should be 11.4 -1.7 = 9.7mm (0.382")


Well...  It is 0.275" for the part I pulled from the MP3 player.


I guess I should have checked the component side of the layout myself and not give any blind trust to someone else's.  The rest of the components seems to be fine.



I imported the scan into Visio and to draw some rectangles over them as a quick and dirty way of measuring the distances.  I measured the distances of the pads to the alignment holes to figure out the X offsets.  The X, Y scaling factor are computed from the component outline vs actual measurements from my calipers.  The offsets are rounded to 1/10 of a mm for the footprint.


The footprint were a bit off to start out with, so this isn't going to be as good as one made directly from the manufacturer's CAD drawing.  It is close enough.

Teardown of 2nd MP3 player

The 2nd batch of MP3 players arrived via Kyrgyzstan.  Canada Post have decided to raise the postage fee from China Post starting from 2018, so I would expect to see a lot more creative logistic shipping routes in the future.  Canada Post service has deteriorated over the past few years.


This MP3 player is a lot easier to disassemble.  There are two self tapping screws holding down the plastic panel in the right side.


Two pegs from the panel latches down the button wheel. The button wheel can then be popped out from the front.


The PCB assembly slides out from the right hand side.


It uses the same PCB design as before.  The LiPo pack is about half the size ~50mAHr.  The overall build quality is slightly better.


Some of the cheaper PCB house only have silkscreen on the top layer which is on the back side of the PCB.  The LCD position no longer lines up with the silkscreen as it is shifted lower to accommodate the curvature of the case.


Portable STM32F103

Most of the projects I have in mind involve a microcontroller, LCD, some buttons, a power source, some I/O and optional mass storage or USB. These $2 MP3 player comes with most of these features, I'll need to replace the PCB with my own design.

While shopping for parts for my next project, I came across these $2 MP3 players from China. They are about 2AA batteries in size. It has all the I/O I'll ever need in a project.  It even comes in an inconspicuous injection molded case making easy to hide your gadget/key/bitcoin keeper in plain sight.

There is already a project: China cheap MP3 player hack which uses my favorite STM32F030. It is missing some of the features that I am looking for.  I initially started off with the board outline and I/O placements from that project, but quickly realized that they are not aligned correctly with my high resolution scan of the MP3 player PCB.  This is why I have decided to start my project from scratch and try to document my design process so that others may improve upon.

I am using a far more capable STM32F103 with native USB interface, dual ADC, dual SPI and a lot more memory.  It is used in Blue Pill breakout board and can be found for around $2 from China with some minor differences.  It is a popular platform and there are a lot of open source projects for the F103. In case you are wondering, the F103 sadly does not have enough processing power to decode MP3.

Features

  • STM32F103 64kB FLASH, 20kB RAM, up to 72MHz.
  • Mini-USB: USB 1.1 Full Speed (12Mbps) device, charging, SWD debug using special cable.
  • 128x64 LCD
  • Micro SD slot for SD/SDHC.
  • 3.5mm Stereo - multiple I/O functions are available 
  • e.g. 3.3V TTL serial, ADC, PWM, I2C and serial bootstrap.
  • 5 push buttons, On/Off switch
  • ~100mA Hr LiPO battery,  LTC4054 charger.

Design

Power design
The device is powered from internal Li-ion battery.  LTC4054 is used for charging the battery from USB. LDO is used to power the main circuits.


The RTC and backup RAM location are backup from the battery. A pair of silicon diodes is used to drop the battery voltage down as a single diode drops might not be enough at uA range.

From Elm-Chan web site (English): How to Use MMC/SDC


MicroSD can draw a lot of current and introduce a droop during hot-insertion.  This can reset the microcontroller or affect results of ADC.  Previously I have used a switch mode supply with a fast transient response and have seen much less droop.

The XC6206P332MR and other ultra low quiescent current LDO make compromises for low bandwidth/transient response. It has a slow recovery time for a sudden load.  While you can pile lot of passives to undo the manufacturer's design decision on $0.04 parts, it is cheaper and takes much less space to simply use 2 separate supplies for the microcontroller and the MicroSD.

I wired 2 GPIO in parallel (saving one MOSFET) to control the power to the LCD backlight (probably around 20mA).

I/O
A few of the I/O peripherals are wired together in parallel to provide different functions.  


Here are the mappings to the peripherals:


The I/O can be programmed in the following modes.


When they are programmed as Analog, the input buffers are turned off and output disconnected.  This allows the other 2 digital GPIOs to be disconnected while ADC is being used.


I/O Protection


With the 330R series resistors, the input can handle 5V CMOS level signal just fine without additional protections.  Injection current: (5V - (3.3V + 0.3V))/330R = 4.2mA

The short circuit current is limited by the resistors: 3.3V/330R = 10mA (or less - driver internal resistance)


Diode clamps are used for additional input protection.  Two series resistors are used as current limit and the signals are clamped a diode drop above the zener voltage.  The zener is pre-biased by R4 to reduce the load on the inputs below the threshold.  C2 reduce the AC impedance.

The protection circuit can be altered for clamping to 3.3V rail by depopulating (or replacing with 3.9V) D3 and relacing R4 with 0R.  There are some trade-offs in each of these option

Clamping to Zener diode:

  • Tolerance and zener voltages are harder to control.  The ideal voltage is a 3.6V zener diode pre-biased to 3.0V nominal.  3.0V + 0.3V from Schottky starts clipping around 3.2V or so and clamp at 3.9V (depending on overload voltages.)  Dropping Zener voltage helps with protection, but will clip sooner and require higher bias current.  The clamping might affect ADC accuracy above 3V.
  • I have tried an active clamp with a transistor circuit  previously in a project when I didn't have the right Zeners.  I don't have the space for it here.
  • Zener pre-biasing  raises power consumption.  One sample I tested with R4 = 330R  for Zener voltage at 2.93V and consumes about 1mA. 
  • Power is dissipated at Zener and only a small amount flows back to circuits.  It works even when circuits are off.

Clamping to power rail:

  • No tolerances, clamping or power consumption issues.  Works fine with ADC.
  • It requires the excessive current to be dissipated by circuits and may be affected by power management.
  • The LDO has a parasitic diode that could allow current to flow back to unprotected LiPO if overvoltage is sufficiently high.  A 3.9V Zener could be used to dissipate some of the current.
Bootstrap mode
The Play/Pause button is wired differently as it is also connected to the Boot0 pin.


When the button is held down during power on, the F103 jumps to the System Memory which is preprogrammed at the factory for a serial bootloader.  The serial port is wired to the stereo jack.


It is a poor man's way of loading precompiled code.  Clone STLinks are ~$2 US from China which is not much more than a serial dongle and offers much more.


Project logs

PCB v6 - made some mistakes, wait for rel 1.1
PCB rel 1 - hardware testing in progress
LCD - reverse engineered init commands.
Misc items - 32kHz oscillator startup issue/fix, battery capacity estimate.
ADC - Calibrating ADC, scaling and formatting using integer math. 
Power source detection - Detecting power source, USB connection for optimizing battery life.

Libraries that can be ported
Hardware random number generator for key generation (Poorman's Quite Random Number Generator (PQRNG) by Hardware)
Nemuisan - STM32 GPS tracker which contains STM32F103 low level driver and FatFS (Elm ChaN's FatFs Module) for reading/writing to Micro SD card
LCD driver, keypad driver, USB driver (libopencm3 or STM32CubeF1 library)
CHIP-8 emulator: Chip8 STM32F103

Reference bookmarks
HaD project: China cheap MP3 player hack  - PCB problems, components are off, wrong footprint. Not worth using.
Github: libopencm3 - open source library/driver
Website: https://github.com/avislab/STM32F103 code examples

Open source password/bitcoin keeper
Github: mooltipass

Oscilloscope based on the STM32F103 

Random number generator

I was going to use Avalanche noise generator using the charge pump on the LCD as a high voltage source, but ran out of board space.

Misc