Wednesday, December 30, 2020

AC Termination

In the case of the RS422 circuit, the differential line impedance is around 100$\Omega$ and "Standard RS-422 drivers are guaranteed to source and sink a minimum 20 mA across a 100Ω load."  (The receiver sensitivity is 200mV.)  That's 40mW dissipated on the termination resistor, and it could be 100mW dissipation at the driver if powered from a 5V supply.  Since this power dissipation is constant regardless the data pattern, the AC termination should be considered.  The AC termination draws power only at the data transition.  How effective is the AC termination?  The AC termination is a resistor and a capacitor in series.  The resistor value matches the transmission line impedance, so about 100$\Omega$.   People seem to use a capacitor value from several hundreds picofarads to a few nanofarads.  How do you select the capacitor value?  If we look at the transmission ratio (the voltage at the termination vs the input voltage), it is $$2\frac{1+j\omega R C}{1+2j\omega RC}.$$If $\omega >> 1/RC$, the ratio is 1.  If we take $R=100$ and $C=1$nF, the frequency must be much greater than 1.6MHz.  This is much more than the usual baud rate we use.  

But the steady state analysis is not the right way to go.  The step response that we are interested in is a transient.  Consider a 1V step applied to the transmission line.  Initially, a 10mA current flows into the termination resistor and capacitor.  The voltage across the capacitor rises as it is charged; and the voltage starts overshoot and reflects back to source.  It can be shown that the reflected voltage is half of the voltage across the capacitor.   The overshoot rises as 2RC time constant and reaches the peak when the reflected voltage makes the round trip.   So the overshoot is depended on the length of the transmission line.  If the transmission line delay is 10ns (~6ft), there is about 10% overshoot with 100$\Omega$ and 1nF termination.

If the transmission line delay is 100ns, the overshoot is $1-\exp(-2\cdot100n/(2\cdot 100 \cdot 1n)) = 63\%$.

TI's AN-903 erroneously stated, ; then the overshoot would be 39% or larger.

But one thing that we have not considered is the source impedance.  The driver could have 10-20$\Omega$ output impedance or series resistors may be included.   When the source impedance is greater or equal to the termination resistance, there is no overshoot, instead there is just a step followed by exponential rise.  For this case, a small capacitor gives fast edges (necessary for high speed transmission).

Friday, December 25, 2020

Christmas LED Lights

I have a string of 60 LED Christmas lights with 6 distinct colors.  I measured the RMS current with a multimeter, and found to be 27mA, so it worked out to be about 3.2W or about 54mW each, which seems reasonable if each LED takes about 20mA.  The string appears to have 3 parallel segments, with 3 lights having 3 wire connections.  That means each LED string consumes 9mA, so the 54mW number seems high for each LED.  Four of LEDs (all blue color why?) are not working, but the rest of the string works, so the connection is maintained.  I was curious to take one off; that segment was out.  So it is the LED that provides the electrical connection.  I took it apart and measured the resistance an found it to be 90 Ohms both ways.  Is there a built-in parallel resistor for fault tolerance?   Each of these resistors would take about 10mW.  The LEDs are running directly off AC, so the current is measured as true RMS, but the voltage RMS is not known.  

Thursday, December 10, 2020

Anti Sulfur Chip Resistors

 Many automotive grade chip film resistors have the  anti sulfur feature.  Bourns has a white paper, "Advantages of Sulfur-Resistant Film Resistors".  It describes in good detail the construction.   In short, sulfur based gasses (such as caused pollution) can react with Ag/AgPd resistor terminal that leads to crack the package.  A Palladium (Pd) protection layer is added to the Ag terminal to eliminate the formation of Silver Sulphide and hence increases the reliability.

Thursday, August 27, 2020

Computer Software Notes

Windows

Change network setting with commands
netsh interface ip set address "Local Area Connection" static IP NetMask Gateway
netsh interface ip set dns "Local Area Connection" static DNS primary
netsh interface ip add dns "Local Area Connection" DNS index=2

Add Emacs to the right-click menu.  Add to the registry
[HKEY_CLASSES_ROOT\*\shell\Emacs\command]
@="\"C:\\Program Files\\emacs-22.3\\bin\\runemacs.exe\" \"%1\""

Emacs for windows needs the diff program to run ediff.  If cygwin is installed, in .emacs (setq exec-path (list "c:/cygwin/bin")) to use cygwin's diff.  Also set environment variable CYGWIN=nodosfilewarning.

Emacs over VNC sometimes could not use the Alt key, add the following to .emacs
;; Map Alt key to Meta
(setq x-alt-keysym 'meta)
For computer with with multiple networks, eg hardwire ethernet and WIFI.  To set the network order
Control Panel -> Network and Sharing Center -> Change adapter settings -> The hit Alt to get the menu and choose Advanced -> Advanced Settings.

Screen saver timeout may have to be changed in the registry
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Control Panel\Desktop]
"ScreenSaverIsSecure"="0"
"ScreenSaveTimeOut"="900"

Microsoft mouse software Intellipoint messes up the left handed setting.  Uninstalled it.

Microsoft robocopy is a useful tool for backups. The command  "rmdir /s/q folder" is a much quicker way to delete a large folder than through Windows interface.  [Others have pointed out a combination of "del /f/s/q foldername > nul" and "rmdir /s/q foldername" is even faster.]

Xilinx USB cable does not install incorrectly with ISE 11.1.  Manually running the following solves the problem,
cd C:\Xilinx\11.1\common\bin\nt
wdreg -inf windrvr6.inf install

Xilinx Platform Studio 7.1 cannot coexist with ISE 11.1. The PATH environment variable should contain either 7.1 or 11.1.

Foxit Reader is a better PDF reader than Adobe Acrobat Reader.

Matlab "Failure to find requested data acquisition device: nidaqmx."  Run Matlab as Administrator.

The driver for Proflic PL2303 based USB to serial adapter uses much more interrupt time than others.

Windows 7 jump lists are in %AppData%\Microsoft\Windows\Recent\AutomaticDestinations, deleting the large files helps restoring the lists.

Windows 7 does not include hyperterminal; copy the following files from Windows XP.  Hyperterminal does run on Windows 7.
c:\Program Files\Windows NT\Hypertrm.exe
c:\Windows\System32\hypertrm.dll

Hyperterminal can send ascii code by pressing and holding down ALT and entering numbers from the numeric keypad (with Num Lock on) then releasing the ALT key.  The code is sent upon the release of the ALT key.

xfig on cygwin complains about missing fonts.
cp /usr/share/ghostscript/fonts/*l.pfb /usr/share/fonts/Type1
cat /usr/share/ghostscript/fonts/fonts.scale >> Type1/fonts.scale
Change the first line to the number of fonts listed.
Update the font database:
mkfontdir

com0com creates a pair of virtual com port.

Laptop PC generates excessive fan noise even when there is little user activity.  The solution is to create a power plan that uses passive cooling, which reduces CPU speed first before increasing fan speed.  Furthermore limits the maximum processor state to 75%; that reduces the CPU frequency.  Power Options -> Create a power plan -> Change plan settings -> Change advanced power settings -> Processor power management -> Maximum processor state .

Linux

To clone a linux system to a large disk.
cp -ax /olddisk/. /newdisk
sed 's/`vol_id --uuid /dev/olddisk`/`vol_id --uuid /dev/newdisk`/g' /boot/grub/grub.cfg > /newdisk/boot/grub/grub.cfg
grub-install --boot-directory=/newdisk/boot /dev/newdisk
sed 's/`vol_id --uuid /dev/olddisk`/`vol_id --uuid /dev/newdisk`/g' /etc/fstab > /newdisk/etc/fstab


To keep the xterm open after executing a command with -e option,
xterm -hold -e 'command' 

To set up a remote git repository from a local repository
#Remote machine: Create the bare repository
mkdir proj.git
cd proj.git
git --bare init

#Local machine:
git remote add origin ssh://remote-machine///repository/proj.git
git push origin master
git checkout origin/master
#Create the local "master" branch that is tracking the "origin/master" branch
git branch -f master origin/master
git checkout master


To make an existing branch tracking a remote branch
git branch --set-upstream master origin/master

To fix a problem with acroread menu on Ubuntu,
"export UBUNTU_MENUPROXY="acroread":$UBUNTU_MENUPROXY
or disable global appmenu altogether
sudo sh -c "echo export UBUNTU_MENUPROXY=0 > /etc/X11/Xsession.d/81ubuntumenuproxy"

When partition a USB drive for Linux and Windows, place the Windows partition first.   Windows can only read the first partition from a USB drive.  The Linux can boot from the second partition.

To map the mouse buttons in X Windows
xinput list
xinput set-button-map 12 1 2 3

To create a pair of virtual serial ports 
socat -d -d pty,raw,echo=0 pty,raw,echo=0

The password length and complexity are controlled by
/etc/pam.d/common-password

The hardware clock setting is in /etc/default/rcS
UTC=yes
to set to UTC time.

Environment variables for Desktop, .pam_environment, the following may be needed to prevent undesirable scaling
QT_AUTO_SCREEN_SCALE_FACTOR=0

Monday, August 3, 2020

Tile Tracker

Powers off 3V CR2032 lithium coin battery
One piezo buzzer
Toshiba's TC35678FSG BLE 4.2 Cortex-M0 (13 or 26MHz) 384KB ROM, 192KB RAM, 256KB Flash.
Diodes PAM8904 12-pin U-QFN3030-12 18VPP output piezo sounder driver, charge pump
Could not identify the two other ICs


  


Monday, July 20, 2020

FPGA Design on Linux

I'm dusting off an old Digilent Nexys 2 board with a Xilinx Spartan 3E FPGA.  The older FPGA devices are not supported by Xilinx Vivado, and the last version of ISE is 14.7 (2013).  The free webpack license is sufficient.  The Linux install file is about 6.5GB; the installation would take 18GB.   It installs fine except for the cable drivers.  It appears that when trying to build windrvr6.ko kernel module, there is an error "fatal error: linux/config.h: No such file or directory" because Linux does not have config.h.  Because we plan to use Digilent's Adept interface, it is not crucial that we have the Xilinx cable driver.  Instead we install Digilent's adept utility and runtime.

After sourcing Xilinx setup script, we can run ise to start ISE Project Navigator.  Then the graphic interface guides us to create the project and run the implementation and generate the bit file.  Then we use the adept utility djtgcfg to program the FPGA.

Subsequently, it might be easier to run the command line interface.  We can turn the command log into a batch script.

The design can be simulated with ISim Simulator.  Now we have a Xilinx FPGA development environment on Linux.

The Linux version of Microsemi's Libero SoC is also available.  We install Libero SoC v11.9 for the ProASIC3 devices.  But we run into a problem with the license.  We request a free sliver license and install Linux Licensing Daemon.  We run lmgrd to start the license server, but license checkout for synplifypro_actel is unsuccessful: The license key and data for the feature do not match. It turns out that I forget to set the environment variables. That gets the synthesis going. Compile does not work and gives an error message of
"Unable to open a working copy of adb file: checksum error detected. The specified file may not be an Actel design file or may be corrupted."
and another message of
"Wind/U Error (248): Failed to connect to the registry on server Cannot register service: RPC: Unable to receive; errno = Connection refused" .
I tried the suggested solution of allowing TCP connections to Xserver. But it does not work.

Monday, June 1, 2020

Router

I finally retired a ten year old router which can no longer support the speed from the cable modem.  It has been running DD-WRT firmware; now it is time to really hack it.   A router is an embedded computer.  Let's first take a look at the components.  The RF circuitry is in the shielded metal can; we won't get into for now and will look at a later time.  The main SoC is AR9130, Wireless Network Processing Unit (802.11n MAC/Baseband, Fast Ethernet MACs, 2x MIMO, 300Mbps PHY/link rate), 400MHz MIPS32 24K CPU (64KB I-cache, 32KB D-cache), supported by 32MB (16Mx16) 200MHz@CL3 DDR400 SDRAM and 4MB (64x512Kb) 50MHz SPI Flash memory (which does not support QSPI).  AR8216 is a 6-port 10/100 Fast Ethernet switch.  The input power is 5V; there are footprints for input filtering, but are bypassed with zero-Ohm resistors.   The first voltage regulator is a 3.3V synchronous buck at 200KHz with external MOSFETs and a relatively beefy inductor.  There are two LDOs, 2.5V/1.5A and 1.8V/0.6A from 3.3V respectively.  There is another switching regulator that generates 1.2V/1A from 3.3V.  There is one UART serial port through-hole header footprint.  There is also an un-populated USB 2.0 port which is supported by AR9130.   A USB 2 port opens up a lot of possibilities, such as disks, webcam, printer, etc.

OpenWrt is a version Linux for routers.  We'll build a version for this router.  A lot of good information can be found here.  One of the limitations of this router is the 4MB Flash, which we'll upgrade; 16MB version costs only about $2.  It is possible to upgrade SDRAM to 64MB, which is about $4 or possibly to get from old PC DIMM.


We use OpenWrt V17.01.7, which still has direct support in the config for this router.  It uses the buildsystem for LEDE.  It downloads all the sources, patches them and builds both host tools and target systems.  It took over two hours and almost 8GB to build.  It builds some of the common UNIX tools, which seems wasteful but maybe it is the easy way to enforce compatibility.  The toolchain is binutils and GCC as usual.  musl libc is used as the standard C library; it is supposedly lightweight and fast.  It is relatively new, compared to uClibc and newlib.  The host tools and the toolchain do not need to build if the configuration changes; the subsequent rebuild takes about 20 minutes.

By holding the reset button while powering up, it enters the factory firmware upgrade mode.  I tried to load the firmware through browsers without success.  The command line worked,
curl -v --form files=@lede-ar71xx-generic-dir-615-c1-squashfs-factory.bin 192.168.0.1/cgi/index
I could ssh into it.  The version that I built did not have a web interface, which probably is not included by default.  After including uhttpd, luci-mod-admin-full, etc also removing a few packages, such as ppp, ip6tables, etc to keep the image small, we have the web GUI.  We can easily configure the router to bridge the main router.  And firmware upgrade can be done through the web GUI using lede-ar71xx-generic-dir-615-c1-squashfs-sysupgrade.bin .   Note that accessing web interface is not secure; luci-ssl has to be enabled to use https.  The Flash is very close to full; the file system is 2432K and the compressed kernel is 1292K for total about 3724K out of 3776K allocated for the OS.

Wednesday, April 29, 2020

Reading Computer Architecture

Hennessy and Patterson's Computer Architecture book was first published in 1990 and the sixth edition came out in 2017.  That is a span of almost three decades.  I read a few editions over years since each edition has substantial new materials.  I have gathered every edition.  We will read them again to see how computer architecture has evolved as described by this influential book over 30 years from the 1e 1990, 2e 1996, 3e 2002, 4e 2006, 5e 2011, to 6e 2017 (about 5 years/edition).

The 1st edition published in 1990 has over 750 pages with appendices.  The 2nd edition published in 1996 has 1000 pages including the appendices.  The 6th edition has 1500 pages with appendices. 

It would be a mistake not to read the 1st edition (especially for beginner).  It lays the foundation for the subsequent editions to follow.  It describes the technology up to 1989.  It describes a hypothetical RISC processor DLX (similar to MIPS).  It emphasizes the importance of making quantitative measurements.  The quantitative principles are actually fairly simple, just some elementary school mathematics.  This seems to make it just an empirical science.  Does the lack of mathematical sophistication mean that the computer architecture discipline is still in its infancy?   The main technical discussions center on pipelining and memory hierarchy.  The vector processor and I/O are also covered.  The DEC VAX and IBM 360 are used as main examples.  In the pre-VLSI days, computer designers seemed to worry a lot about the speed of light being the limiting factor and totally missed the miniaturization brought about by the nanotechnology and the ultimate limitation actually being the power dissipation. 

In the 2e, the graph of microprocessor performance growth shows the top performer DEC Alpha in 1995; the microprocessor performance grows at 1.58x per year (vs 1.35x per year performance growth in technology).  The graph appears to show a SPECint92 rating of 330.  It matches the data from netlib.org: DEC Alpha 21164 266MHz in AlphaStation 600 5/266 of 1995 has a SPECint92 rating of 329.0 and SPECint95 of 6.30.   Intel Pentium 133MHz available at that time has SPECint92 rating of 190.9 and SPECint95 of 3.96.  (A lot of historical CPU performance data can be found at  http://cpudb.stanford.edu/ .)   In the 3e, the top performer is Intel Pentium III of 2000, same growth rate.  Pentium III 1GHz of 2000 has SPECint95 rating of 46.8.  In the 4e, the top performer is Intel Xeon 3.6GHz; the growth rate is revised to show 25%/year before 1986, 52%/year 1986-2002 and 20% 2002-2005.  In the 5e, the top performer is Intel Xeon 6 cores 3.3 GHz; the growth rate after 2003 is 22%/year.  In the 6e, the top microprocessor is Intel Core i7 4 cores 4.2GHz; the growth rate after 2003 is refined: 23%/year 2003-2011, 12%/year 2011-2015, 3.5%/year 2015-2017.

Also notable is the scaling of clock rate:  the first 15 years (1987-2003), the clock rate goes from 16MHz to 3.2GHz (40%/year increase), and the recent 15 years (2003-2017) the clock rate goes from 3.2GHz to 4.2GHz (2%/year).  Between 2003 and 2010, there was almost no improvement in clock rate.  FinFET technology production (22nm) started around 2011, which possibly boosted clock rate slightly.  The power limitation is first mentioned in the 3e as power consumption reaches over 100W.  (Xeon 9282 launched in 2019Q2 reaches TDP of 400W.) 

The 2e emphasis is mostly on the RISC principle; one entire chapter is devoted to describe the RISC instruction set, which DLX is introduced as a textbook example.  The DLX instruction set is simple by using load-store, fixed encoding, and large register set.  The question about CISC vs RISC is settled decisively by comparing CPI (cycles per instruction) and number of instructions executed using the quantitative principles. RISC's CPI advantage more than compensating for the more instructions per program and RISC is much simpler to build.  Rarely used complex instructions just do not pay off.  ILP (instruction-level parallelism) is the main focus from basic pipelining, dynamic scheduling, branch prediction, superscalar, speculation to compiler technology.  The fundamental ideas remain unchanged through editions.  The modern superscalar speculative dynamic processor has gotten very complex.  It is hinted that multiprocessor may be the way to go as it is possible to put two processors on a single die around the end of the 20th century.

TLP (thread-level parallelism) first appears in 3e.  Basic pipelining is relegated to the appendix.

From 4e, instruction set principles are relegated to the appendix.

DLP (data-level parallelism) is first introduced in 5e.  GPU is first described as DLP.  Vector processor is brought into the DLP section; it is included in the appendix of the previous editions.  RLP (request-level parallelism) is also introduced.  WSC (warehouse-scale computers) is coined; WSC is made of hundred thousands of networked servers.  

DSA (domain-specific architecture) is first discussed in 6e; the AI neural chips are presented as the examples. 


Tuesday, April 7, 2020

$3 USB Li+ Battery Charger

The $3 Li+ battery charger is very simple in construction.  It has a single layer PCB.  I could not identify the IC, which linearly regulates the voltage and the current from the USB 5V input.   It also controls two LEDs, so it may be designed for this application.  One 2K resistor is possibly for programming the current. It draws about 5mA when idle and 500mA when charging.  It cuts off at the right voltage of 4.2V.  But the open circuit voltage is 4.38V.  The negative battery terminal tab is spring loaded to accommodate different battery sizes.




Sunday, March 29, 2020

LoRa on RPi

LoRa is a low-power and long distance wireless technology.  I have a set of Semetch SX1272 boards.  We'll try to use them to communicate between two Raspberry Pi boards (Pi3 and Pi4).

Wire the 4 SPI signals to the header, and add a GPIO for reset.  I also wire up an LED.  First checkout the connection by reading the "RegVersion" register at address 0x42 and expect a value of 0x22.  The chip operates in Mode 0 (CPOL=0, CPHA=0).
import spidev
spi=spidev.SpiDev(0,0)
spi.max_speed_hz=1000000
spi.xfer([0x42,0]) 
It returns [0, 34].  Note that the SPI max speed depends on the wiring.

There are a few Python modules that support SX1272.  We'll try to make use of Adafruit's Python package for RFM9x, which is said to use SX1272 (although the IC has its own marking).  The first attempt to use adafruit_rfm9x was unsuccessful; it could not find the device.  It appears that RFM9x uses an older version of the chip and there is some additional circuitry on the module Furthermore, the CircuitPython implementation of the SPI device interface for RPi seems a little convoluted.  It fails at the very beginning trying to read the version register.

We move on to use raspi-lora for RFM9x.  It requires only RPi.GPIO and spidev.  One GPIO input is needed as interrupt for receiving.  The code is simple.  It worked on the first try; messages sent from RPi3 were received by RPi4.

Another Python package python-sx127x also works.

Monday, February 17, 2020

PSoC Development on Linux

PSoC from Cypress is a unique microcontroller for the flexibility of its peripherals.  The low-cost PSoC 5LP prototyping kit CY8CKIT-059 is particularly attractive with $10 price and built-in programmer and debugger KitProg.  The PSoC5 series has an ARM Cortex-M3 core, which is supported by the GNU compiler.  However, the develop environment Cypress PSoC Creator only runs on Windows.  My attempt to run PSoC Creator with wine was unsuccessful.  I can run PSoC Creator Windows virtual machine, in which the peripherals can be set up.  (The last version supported on Windows XP is 4.0.) Once the hardware is set up, the software development can be done in Linux.

One way to update the application software on Linux is to use a bootloader.  Cypress supplies a bootloader component, that can communicate over UART, I2C, and USB HID.

First we have to flash the bootloader itself; we can use OpenOCD, which has support for KitProg.   The Linux kernel detect KitProg (ID 04b4:f139) as a USB HID device and a serial port.
[ 1995.852252] usb 1-1.2.2: new full-speed USB device number 11 using ehci-pci
[ 1995.968208] usb 1-1.2.2: New USB device found, idVendor=04b4, idProduct=f139, bcdDevice= 2.11
[ 1995.968217] usb 1-1.2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=128
[ 1995.968222] usb 1-1.2.2: Product: Cypress KitProg
[ 1995.968227] usb 1-1.2.2: Manufacturer: Cypress Semiconductor
[ 1995.968231] usb 1-1.2.2: SerialNumber: 1016163201324400
[ 1995.970949] hid-generic 0003:04B4:F139.0003: hiddev0,hidraw1: USB HID v1.11 Device [Cypress Semiconductor Cypress KitProg] on usb-0000:00:1a.0-1.2.2/input0
[ 1996.015524] cdc_acm 1-1.2.2:1.2: ttyACM0: USB ACM device
[ 1996.017170] usbcore: registered new interface driver cdc_acm
[ 1996.017172] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
After building openocd from the source, openocd detects KitProg,
./src/openocd -s ./tcl/ -c "interface kitprog" -f target/psoc5lp.cfg -c "targets"
Open On-Chip Debugger 0.10.0+dev-g9a363c9 (2020-02-09-14:02)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
cortex_m reset_config sysresetreq
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* psoc5lp.cpu        cortex_m   little psoc5lp.cpu        unknown
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : KitProg v2.17
Info : Hardware version: 17
Info : VTARG = 4.755 V
Info : This adapter doesn't support configurable speed
Info : SWD DPIDR 0x2ba01477
Info : psoc5lp.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : accepting 'telnet' connection on tcp/4444
To program the bootloader, 
../Cypress-OpenOCD/src/openocd -s ../Cypress-OpenOCD/tcl/ -c "interface kitprog; kitprog_init_acquire_psoc" -f target/psoc5lp.cfg -c "init; halt; program output/debug/Bootloader_USBUART.elf  verify reset exit"
Open On-Chip Debugger 0.10.0+dev-g9a363c9 (2020-02-09-14:02)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
cortex_m reset_config sysresetreq
Info : KitProg v2.17
Info : Hardware version: 17
Info : VTARG = 4.758 V
Info : This adapter doesn't support configurable speed
Info : SWD DPIDR 0x2ba01477
Info : psoc5lp.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : psoc5lp.cpu: external reset detected
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x41000000 pc: 0x000004b8 msp: 0x20007fc8
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000010 msp: 0x20008000
** Programming Started **
auto erase enabled
Info : Padding image section 0 at 0x00001869 with 3 bytes
Info : Flash write discontinued at 0x00001de0, next section at 0x0003ffc0
Warn : Adding extra erase range, 0x0003c000 .. 0x0003ffbf
Error: Writes must be row-aligned, got offset 0x0003ffc0
Error: error writing to flash at address 0x00000000 at offset 0x0003ffc0
** Programming Failed **
shutdown command invoked
Error: Sequence 2 not supported.
If the hex file is used, the error message is different,
** Programming Started **
auto erase enabled
Warn : no flash bank found for address 0x80000000
Warn : There is no erase operation for NV Latches
Error: failed erasing sectors 0 to 0
** Programming Failed **
shutdown command invoked
Error: Sequence 2 not supported.
 Despite of the error message, the programming of the bootloader seems to have succeeded.

The UART bootloader works with a Linux version of bootloader_host, cyhostboot, built around the source for Bootloader Host Tool provided by Cypress, available on Github.
../cypress_linux_tools/cyhostboot/cyhostboot -f output/debug/PSoC5ino.cyacd
Programing file output/debug/PSoC5ino.cyacd
Start programing on serial /dev/ttyACM0, baudrate 115200
no parity
Got silicon id 0x2e161069, rev 0x00
Progress: array_id 0, row_num 30
Progress: array_id 0, row_num 31
... 
Progress: array_id 0, row_num 149
Progress: array_id 3, row_num 255
programing OK !

It takes about 2 minutes to program about 30KB.



Monday, January 20, 2020

EBL 18650 Lithium Ion "3000mAh" Battery

The battery can be purchased for less than $2 a piece.   But it is a little skeptical that the capacity is actually 3000mAh.  The weight is about 44g, which seems reasonable, perhaps 3-4g short of other comparable cells.  The EBL battery seems to be Ultrafire repackaged: the labeling is similar down to the misspelling of "Sheef-life".  One "official specification" found on another online review site is
  • Genuine Ultrafire 3000mAh 18650
  • Real capacity: 2900mAh (-100mAh / + 100mAh)
  • Internal PCB protection prevents under-voltage at 2.5V and over-voltage at 4.25V. UNIQUE INTERNAL PCB!
  • Diameter 18.6+/-0.2 mm (Note: Diameter may not fit all flashlights)
  • Height 66.5+/- 0.2mm
  • Weight (Typical) Approx. 46 g
  • Nominal Voltage: Average 3.7V
  • Cut-off Voltage: 2.5V
  • Internal Impedance: less or equal to 180 milli-ohm (with PTC)
  • Cycle Performance: 90% of initial capacity at 400 cycles
  • Cycle life: > 500 cycles
  • Charge: Current = 0.5C mA Voltage = 4.2 V End Current = 0.01 mA
  • Discharge: Current = 0.5C mA End Voltage = 3.0V
The first discharge test with constant resistive load of 5 Ohms; the battery drains to 3V in about 3hrs.  Integrating the discharge current shows about 2300mAh.  The voltage falls off quickly at around 3.3V.  Discharging with 35-Ohm resistive load yields about 2400mAh.  The integration of charging current back to full capacity also shows about 2300-2400mAh.  So it only has 80% of the stated capacity.  It is in general agreement with measurement by other people.

Friday, January 10, 2020

18650 Battery Shield V3

"18650 Battery Shield V3" charges a 18650 lithium ion battery and outputs 5V and 3.3V.  It claims 4A on 5V and 1A on 3.3V.  It can be purchased for less than $3.


The charge input voltage is from a micro USB connector, going through a diode, to the 1A linear lithium ion battery charger IC, TC4056A by China Fu Man Electronics Group.  The charging current is about 0.6A (the current programming resistor at Pin 2 is 2000Ω, I = 1V/2000Ω*1200).   Taiwan Fortune Semiconductor's DW01-G battery protection IC and China Hottech Semiconductor's 8205A dual n-channel MOSFETs (drain pins tied) provide over-voltage (4.25V), over-discharge (2.4V) and over-current protection, which is set to about 3A (with Rdson of the two FETs 50 milli-Ohms total).  We can get an estimate of the charge current by measuring GND and the negative battery terminal; the gain is 20A/V.

A step-up regulator FP6298 by Feeling Technology generates 5V.  Given that the battery discharge limit to 3A, the 5V output cannot reach the specified 4A.  The actual measured current limit is about 2.6A and 5V output tops out at about 1.5A.

The 3.3V output is generated by 3 parallel Torex XC6206P linear regulators with input from the battery.  The 3.3V output does not seem stable; it is noticed that there is no output capacitor.  Each regulator has rated maximum output current of 200mA.  The current limit is 450mA before foldback.  The dropout voltage is 500mV at 200mA.  The outputs of the 3 regulators are tied together directly.  If the outputs are not exactly the same, the regulator with the highest output voltage will dominate and causes the other two to shutoff.  So the output current is sourced from only one regulator until it starts current limiting.  Surprisingly, the actual measurements show that the output current can reach 1A.  The dropout from the battery voltage is likely to be limiting factor for the output voltage to be in regulation.

A slide switch switches power to the USB A connector, but it does not turn off the regulators.  The idle current is 0.3mA.

The battery holder is backwards, reversed from the polarity marking as a result of layout footprint error.  The marking on the PCB is correct.