Thursday, April 11, 2019

Fixing Power Adapter

I have an old AC power adapter that outputs 5V and 12V at 1A each with combined total output of 15W.  It stopped working.  I opened up and found the 2.5A input fuse was blown.   The primary side was shorted.   This offline power switcher seemed really simple.  There did not appear to have a controller IC; it was made entirely with discrete parts.  It did not take long to locate the faulty component, the primary side MOSFET switch, 2SK1535, a 900V 3A power MOSFET with 4-Ohm Rdson; all three pins were shorted.  It is a flyback switcher with two secondary outputs and an optocoupler off the 5V.





The first question is how it generates PWM signals.  Besides the main FET switch, the primary side has only one additional transistor. But the primary side has one auxiliary coil, which provides the positive feedback for oscillation.  The secondary side does not seem to even have a voltage reference, so how does it regulate?  There are only a transistor and a POT that feed the optocoupler.

After replacing the faulty MOSFET and the blown fuse, the switcher works again.  But one problem with the circuit is the lack of short-circuit protection.  The primary side switch can turn on hard and destroy itself before even the fuse blown. 


Monday, March 25, 2019

Alkaline Batteries

My Bluetooth mouse runs on two AA cells.  As the each battery drops below 1.2V, the mouse complains about low battery.  The alkaline battery does not completely drain until about 0.9V.  According to Energizer, its AA alkaline battery is about 3000mAh if discharged at 25mA (to 0.8V).   One of its diagrams shows that the battery has as much as 750mAh left at 1.2V, that is about 25%.

So how do we maximize the battery life?  The mouse draws relatively low current.  If we mix a fresh battery with a partially drained battery, that should have the voltage high enough.  A fresh alkaline battery has an internal resistance about 0.1 Ohm at the room temperature (rise to 0.4 Ohm at -20C) from the chart provided by Energizer.

I measured an alkaline battery with OCV 1.09V, when loaded with 10 Ohms, the voltage drops to 0.84V.  So the internal resistance about 2 Ohms at 84mA load.   For low current draw, it should still be able provide power.  With a fresh battery at 1.535V and a drained one at 0.992V, the mouse still works without any complaint.  The two batteries together are measured 2.47-2.51V when the mouse is on.  When the mouse finally start to complain about low battery, one battery has drained to about 0.83V and the other 1.47V.  We got about extra 4 weeks of battery life.



Tuesday, February 19, 2019

LCR-T4 Oscillator Upgrade

We will replace the 8MHz crystal with a 16MHz one on LCR-T4 transistor tester.  ATMega328p can run up to 20MHz.  The old firmware still seems to run with the 16MHz, but some measurements are off.  Maybe it can be fixed with calibration, but we'll just update the firmware.

The OP_MHZ parameter in the makefile defines the operating frequency of the CPU.  We change it to 16 from 8.  Now we can also enable crystal and ceramic resonator test by defining WITH_XTAL. Only 16MHz and 20MHz are supported for crystal test at this time.   F_CPU, F_CPU_HZ and MHZ_CPU are in turn defined by OP_MHZ. 

After compilation, the program size is shown to be 95.1% full, grown 2290 bytes.  The I2C display version no longer fit in the flash, exceeded by 216 bytes.
Program:   32984 bytes (100.7% Full)(.text + .data + .bootloader)
Data:        210 bytes (10.3% Full)(.data + .bss + .noinit)
EEPROM:      912 bytes (89.1% Full)(.eeprom)
So we disable the crystal test for now, and it is 93.5% full.   After programming the flash, it runs fine.

Now we'll try to trim the code a little so we can enable the crystal test.  Before doing any size optimization, we'll try to remove some features.  Looking the memory map, removing select_color() function would yield enough saving.  We change the compile option undef LCD_CHANGE_COLOR, which saves 586 bytes.  Now we have 370 bytes to spare.
Program:   32398 bytes (98.9% Full)
(.text + .data + .bootloader)
Data:        206 bytes (10.1% Full)
(.data + .bss + .noinit)
EEPROM:      887 bytes (86.6% Full)
(.eeprom)
We can test the XTAL function.  The crystal that we replaced is measured 8000.00KHz, not bad!  A 10MHz series resonance crystal is measured 9999.77kHz series and 10.0018MHz parallel.  But it seems that it cannot measure beyond 10MHz.

We further replace the crystal with a 20MHz one.  Now when we measure the 16MHz crystal, we get 15.9948MHz series, 15.9979MHz parallel.  However, other lower frequency crystals are measured incorrectly.  We'll look into it.


Tuesday, February 12, 2019

Garmin LIDAR Lite

We'll interface Garmin LIDAR Lite with esp32-pico-kit.  esp32-pico-kit interfaces the LIDAR using I2C.   We'll make use of the wireless connectivity.  First we'll transmit the data through Bluetooth.  And we'll the esp32-pico a webserver that'll display the data through WiFi.

The LIDAR runs on 5V, but itself I2C signal is 3.3V, which matches esp32.

We'll use Garmin's LIDARLite_Arduino_Library .  First, we'll try out the library example GetDistanceI2C.  It compiles and is uploaded without a problem.  After hooking up the I2C and 5V, the serial monitor spits out numbers.  For this, the Arduino serial plotter is a great tool to view the output.

Next we'll try to run esp32-pico-kit as a Bluetooth serial device.  We run the SerialToSerialBT example without a problem.  We have two way communications with a Bluetooth serial app on a smart phone.

Then we'll try an example of setting up a WiFi access point.  That also goes without a problem.

Now we have tested the major pieces and are ready to put them together.  We'll start with the LIDAR and BT serial.  That uses 72% of Flash and 12% RAM.  It works nicely .

We'll create a webserver to display the range data next.  We set the web page to auto refresh every second.   It uses 51% of Flash and 11% RAM.  It works just fine.  A lot of features can be added, such as displaying a live graph and changing registers etc.

The ease of create a working IoT system with arduino is quite amazing.


Tuesday, January 22, 2019

Multimeter measurement of resistance

How does a multimeter measure resistance?  A lot of online answers suggest that a constant current stimulus is used.  I looked into it and found that the stimulus current is not constant at all for digital multimeter.  Perhaps it was true back in the analog meter days.  The digital multimeter uses a constant voltage with a resistor in series.  For different measurement range, different resistor value is used, large resistor value for large measurement range.  Some meters also change the constant voltage for different ranges, normally large voltage at lower resistance range.  The series resistor and the resistor under measurement form a resistor divider.  The resistance measurement is calculated from the divider voltage.

It is fairly easy to find out the stimulus voltage.  First set the ohm meter to manual range.   Use a volt meter  to measure the voltages of the ohm meter for two known resistance.  From the two equations, we can solve the stimulus voltage and the series resistance.

For Fluke 87, the stimulus voltage is 1.235V, the series resistances over the ranges are 6.5K (400-Ohm), 15.7K (4K-Ohm), 106K (40K-Ohm), 1.02M (400K-Ohm), 10M (4M-Ohm) and 10M (40M-Ohm).

For Cen-Tech multimeter, the stimulus is 3V for 200-Ohm range and 0.3V for others.  The series resistance is 1.59K (200-Ohm), 3.34K (2K-Ohm), 12.5K (20K-Ohm),  103K (200K-Ohm),  and 1M (2M-Ohm).

For high-end digital multimeters, like Keysight 34401A (6.5-digit), it uses current source, 1mA (100 and 1K-Ohm), 100uA (10K), 10uA (100K), 5uA (1M), 0.5uA (10M), 0.5uA||10MOhm (100M).

Friday, January 18, 2019

Aukey Dash Cam GPS Antenna

The GPS antenna ($20) has 4-conductor 3.5mm plug that goes into the Aukey Dash Cam for location information to be included in the recorded video. 


We'll try to decipher to the interface signals.  From a picture of the disassembled GPS antenna, we know the pinouts for the plug, VCC, GND, TX, RX.  It is more than just an antenna; it is a GPS module.  We'll take a look what the protocol is.  First we want to know the VCC voltage.  VCC is measured to be 3.3V, so are TX and RX.   The we'll look at the TX and RX to see what kind of signals they are.  There is no activity on RX.  TX shows what appears to be 3.3V UART signals.  The minimum pulse width is about 104us, so the baud rate is 9600.  The messages come in 580ms burst every second.  We connect TX to a UART receiver.  We can see the standard NMEA GPS strings.  The messages include GPRMC (recommended minimum), GPVTG (vector track over ground), GPGGA (fix information), GPGSA (satellite data), GPGSV (detailed satellite data), GPGLL (lat/lon data).

We can tap into the TX signal to extract GPS data for other purpose.

Sunday, December 30, 2018

0.96" I2C 128X64 Blue OLED Display Module

I ordered a 0.96" I2C 128X64 Blue OLED Display Module from eBay for $2.85 (shipping included).   It claims: voltage 3-5V,  power consumption of full lit screen 80mW, SSD1306 driver IC, compatible with Arduino.  When it arrived about three weeks later, the circuit on the back looked a little different from the product pictures on eBay.

Notably there is no regulator IC that would generate 3.3V from 5V.   It also lacks the level shifters  that are on the similar product by adafruit.   I'm a little skeptical that it can run on 5V..  So we'll start with 3.3V supply.  The two I2C signals are pulled up with 10K resistors.

We will test it using esp32-pico-kit with Arduino on Linux.  The CP210x UART Bridge is mapped to /dev/ttyUSB0.  Adafruit SSD1306 library (along with GFX library) claims to be compatible with ESP32.  We will try the example sketch ssd1306_128x64_i2c.   We need to know the default I2C pins.  It took a while to poke around the ESP32 code to find the pin definition: SDA=21 and SCL=22.   We compile and upload the code.  We open the serial monitor (9600 baud) and see some output, but there is nothing on the display.

We'll try a different library, "ESP8266 and ESP32 Oled Driver for SSD1306 display".  After modifying the I2C pins, the example SSD1306SimpleDemo works nicely.  The current for the module is 4 - 12mA as the program runs through different screen drawings.


Sketch uses 166885 bytes (12%) of program storage space. Maximum is 1310720 bytes.
Global variables use 11444 bytes (3%) of dynamic memory, leaving 283468 bytes for local variables. Maximum is 294912 bytes.
esptool.py v2.1
Connecting........__
Chip is unknown ESP32 (revision 1)
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 8192 bytes to 47...

Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 7540.8 kbit/s)...
Hash of data verified.
Compressed 14128 bytes to 9213...

Writing at 0x00001000... (100 %)
Wrote 14128 bytes (9213 compressed) at 0x00001000 in 0.1 seconds (effective 818.5 kbit/s)...
Hash of data verified.
Compressed 168032 bytes to 92899...

Writing at 0x00010000... (16 %)
Writing at 0x00014000... (33 %)
Writing at 0x00018000... (50 %)
Writing at 0x0001c000... (66 %)
Writing at 0x00020000... (83 %)
Writing at 0x00024000... (100 %)
Wrote 168032 bytes (92899 compressed) at 0x00010000 in 1.6 seconds (effective 861.6 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 122...

Writing at 0x00008000... (100 %)
Wrote 3072 bytes (122 compressed) at 0x00008000 in 0.0 seconds (effective 4691.0 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting...
ets Jun  8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:956
load:0x40078000,len:0
load:0x40078000,len:13076
entry 0x40078ad0