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 on Windows virtual machine, in which the peripherals can be set up.  (The last version supported on Windows XP is 4.0 (Release Date 10/06/2016).) Once the hardware configuration is generated, 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.

Tuesday, December 17, 2019

AN8008 Current Measurement Error

The most annoying problem with ANENG AN8008 multimeter is the poor accuracy of high current measurements.  Significant error is seen for the measurements above 1A.  The error drifts high quickly at higher current.

It is apparent looking that the circuit board the current sense circuitry is laid out incorrectly.  The voltage measurement across the current sensing shunt includes a section of PCB trace.     The copper trace width is about 150mil, and the length is about 700mil; so the copper trace could be as much as 2-3 mOhms.  The shunt wire is labelled 0.01 Ohm.  Assume the shunt wire is Manganin with temp co 1.5e-5 /C  (vs Copper 3.9e-3 /C).  The size is about 14 AWG, so the resistance is about 2 mOhms/cm; the length appears to be 4-5cm, so 8-10 mOhms is reasonable.  We could bypass this section, but the meter may be calibrated this way. (The EEPROM may be updated for new calibration.)


The section of the PCB is already different from the earlier version based on other teardown pictures online.  The copper trace is exposed and vias are added; the trace is coated with solder.  It appears that attempts are made to improve thermal dissipation.

When I actually measured the voltage drop across the shunt wire and the copper trace, I did not see the drift that I expected.  The shunt wire has about 8 mOhms, and the trace less than 1.5 mOhms.  When 7A is applied to the meter, the area near the fuse gets pretty hot.

The burden on the current measurement is also high because of the fuse and traces.  I measured as much as 180 mOhms at the terminals.

Wednesday, December 11, 2019

$20 Multimeter (ANENG AN8008)

I wrote about $4 multimeter (also see here), which is fine for crude measurements.  For $20, we can have a meter with the following enhancements: 10Meg-Ohm input impedance, auto range, auto power off,  higher resolution (9999 vs 1999 counts or 4 digits vs 3.5 digits), capacitance measurement, true RMS for AC voltage and current, frequency and duty measurement, continuity beep.  Those are the features of ANENG AN8008, which has received favorable reviews online.  There are even modifications (adding capacitors to the reference and supply) to improve its performance.  The meter also comes with an extra set of probes with changeable tips.

The voltage measurements are generally very good.  The current measurements are poor at high current range.  The measurement drifts a lot.  For example, at 7A current input, the initial measurement is 7.03A (well within spec), but very quickly it drifts 7.15A and keeps climbing.  For current 1A or below, the measurements seem stable.  (It appears that the poor layout of the current sensing shunt resistor contributes to the poor performance.)  The $4 meter actual does better: measuring 7.05A and steady.  The shunt resistance in the uA range is 100 Ohms.  The resistance measurement excitation voltage appears to be 1V.  The diode voltage measurement goes up to 3V; the open circuit voltage is 3.3V .  It has a square wave output (+/-1.37V) at selected frequencies, which I don't know a good use for.  The current draw in the voltage mode is about 1.5mA from two AAA batteries; that gives about 600 hrs operating time.

The specifications are fairly conservative and easily met except for the high current measurements.

Is it worth $20?  Maybe.  It is not for professional use.  The poor high current measurement accuracy is a disappointment.  There is no 10mA and 100mA current range.  The input protection is pretty minimal: 10A/250V and 200mA/250V fuses for current protection, a bidirectional TVS diode and a 1.5K-Ohm PTC thermistor.  The 600V CAT III and 1000V CAT II ratings should not be relied on.

The Fluke 107 has comparable features and specs (the only enhanced feature is 40M-Ohm range); the cost is $80.   The extra cost buys guaranteed spec and verified 600V CAT III rating.

Saturday, November 16, 2019

TS100 mini soldering iron

The TS100 soldering iron is an open source hardware by Miniware, which releases the schematics and software.  It has a decent construction; it comes with one tip but no power adapter.  The input voltage range is 12 to 24V, for power of 17W to 65W.  The interesting feature is that custom software can be loaded.  Ralim/ts100 on Github is an alternate firmware with more features.

The processor is STM32F103T8U6, 72MHz M3 core with 64K Flash and 20K SRAM, 2 12-b ADC.  It includes a 3-axis digital accelerometer for motion and orientation detection, 96x16 OLED display, a temperature sensor, TMP36 and two push buttons.  It has a barrel connector (5.5mm x 2.5mm) for power and a micro USB connector for firmware update.  The tip contains a thermocouple (reported to be type K); TMP36 provides the cold junction compensation.  The circuit design seems decent; it does not aim for the lowest cost possible.  For the price of about $50, it should not need to skimp on the circuitry.  I would estimate the bill of material costs do not exceed $20.  With 12V input, it takes about 30s to heat up to 300C; with 19V input (40W) from a laptop power adapter, it takes about 12s.

With the right firmware, it does make a nice soldering station.  The tip temperature is settable up to 450C.  The iron goes to sleep on a timer and wakes up on motion.   It can be made portable with a LiPo pack; the cutoff voltage is settable based on number of cells.  Because of the small size, a stand can be made out of a paper clip.


Monday, October 14, 2019

Habor Freight $4 Multimeter

I was generally pleased with Cen Tech multimeter from Habor Freight.  Similar looking multimeters (Item 63604) sold at Habor Freight now do not carry Cen Tech brand name; it can still be purchased for $3.99.  Upon close look the spec has changed a little bit,  The highest voltage only goes up to 250V DC or AC (vs 1000V), and the max current 5A (vs 10A).   It appears that the meter simply changed 1000V DC and 750V AC range to 250V range probably because of the fear of liability.  Opening it up, I can see the effort in cost reduction.  The Chip-on-Board I/C may be the same, but there are fewer discrete components and the PCB is smaller.   It does not have the trimmer. The fuse is soldered on; previously there was a fuse holder.  The probe is still decent; the spec says 18 gauge.  Even the critics now concede that the cheapest multimeters can be reasonably accurate; their main complaint is protections.   The CAT II rating cannot be taken serious; the CAT II marking on the probes are now removed.  One-mega-Ohm input impedance is also too much loading for some measurements.
The official spec is
  • 0-200mA: 1.2%+/-2d
  • 5A: 3%+/-5d
  • 200mV: 0.5%+/-1d
  • 2000mV-200V: 1%+/-2d
  • 250V: 1%+/-2d
  • AC 200/250V (45-450Hz): 1.2%+/-2d
  • No accuracy given for resistance
No spec for resistance measurements.

We'll check the accuracy against a Fluke 87 (spec voltage 0.05%, current 0.2%, resistance 0.2-0.6%).  The accuracy seems to have degraded somewhat, more so with the resistance measurements.  If you accept 1% error; it is OK for casual use.

Voltage
8.88.80.00%
48.949.10.41%
98.598.80.30%
149149.50.34%
198.5198.50.00%
4994990.00%
9999990.00%
19991992-0.35%
2.99930.03%
3.9994.010.28%
55.010.20%
99.020.22%
1212.020.17%
1515.020.13%
2019.97-0.15%
2525.20.80%
29.9930.20.70%
4040.30.75%
5050.40.80%
Current
17.817.7-0.56%
5454.10.19%
99.7100.10.40%
154154.50.32%
198.5198.90.20%
147014800.68%
195019690.97%
5.075.06-0.20%
10.2110.19-0.20%
15.3415.29-0.33%
19.619.52-0.41%
50500.00%
99.799.70.00%
150.8150.90.07%
197.3197.2-0.05%
0.50.50.00%
10.99-1.00%
21.99-0.50%
2.9992.99-0.30%
3.9993.99-0.23%
54.99-0.20%
660.00%
770.00%
* I took the current up to 7A; it is still working. I wonder if the lower spec is just to be on the conservative side.
 
Resistance
10.911.11.83%
50.750.70.00%
100.5100.3-0.20%
150.3149.6-0.47%
190.2189-0.63%
499494-1.00%
998987-1.10%
14961479-1.14%
18971872-1.32%
4.984.95-0.60%
9.999.92-0.70%
14.9814.85-0.87%
18.9818.79-1.00%
49.849.7-0.20%
99.299.1-0.10%
149148.7-0.20%
189188-0.53%
498493-1.00%
997989-0.80%
14941480-0.94%
18951872-1.21%