Wednesday, October 7, 2015

$2 esp8266 4MB ESP-12-E module

One of the recent goodies to arrive in the mail was a new esp8266 module.  When I ordered it, the price was 208c, but as of the time of this writing it has gone up.  Although it is advertised as an ESP-12-E module, the module I received is labeled ESP-12-Q, as can be seen in the photo above.  Other vendors are selling the same modules for 201c now.

One of the reason I ordered the module is because I intend to test the ADC function, and the ADC pin is not broken out on my ESP-01 module.  The other reason is that I read a couple postings from people that had received ESP8266 modules with a larger 4MB flash instead of the 512KB flash typical of the first ESP8266 modules released.

Since the modules have pads at 2.0mm spacing, I made an adapter board with some protoboard.  I just hot glued the module to the protoboard, and soldered short wires from the pads to the 0.1" spaced pin headers.  It is a bit more tedious work than using one of the pre-made adapter boards on the market, but I didn't have to wait for an adapter board, and my solution leaves more available space for connections on a breadboard.  Aside from the wire connecting EN with VCC, the rest of the connections are wired to the respective protoboard header pins.

After connecting power and Tx/Rx to a USB-TTL module, and pulling down GPIO15 to ground with a 1K resistor (to select boot from serial flash), I opened a terminal program to 9600bps, pulsed the reset line with a brief 1K short to ground, and got the following output:
NodeMcu 0.9.6 (Doit.am Version) build 20150701  powered by Lua 5.1.4

ESP8266 Started
Start soft AP
>

I also did a wifi scan with my phone and found an SSID named DoItWifi.  Since eLua was pre-flashed to the module, I could easily check the flash size with the node.info() function:
> =node.info()
0       9       6       16398478        1458400 4096    2       40000000

The 4096 indicates 4096KB (4MB) of flash.  The 512KB of flash on the ESP-01 module had been enough for the kind of progams I was writing using esp8266/Arduino, but now with a 4MB module I have plenty of memory to start experimenting with the ESP RTOS.

I measured the power consumption of the module at idle and with a wifi client connecting.  Idle consumption was consistently around 60mA, and with a wifi client connecting power consumption was around 90mA with a couple peaks to 140mA.

With this module I also decided to do some tests on the boot modes.  While the boot modes are reasonably well documented, there is little documentation on the default state of GPIO0, 2, & 15 at boot time.  This posting on the espressif bbs states they all have weak pullups, and my testing confirms this.  I held reset low with a 1K resistor to ground, and measured the voltage on the pins.  TXD0, RXD0, GPIO0, 2, & 15 all read 3.26V, while GPIO4 & 5 were 0V.  Connecting a 10K resistor to GPIO0, 2 & 15 caused the voltage to drop to 0.8V for each of them.  Calculating for the voltage divider ratio results in an internal pullup resistor value of around 33K Ohms.

I also tested the pins after booting from the on-board flash.  GPIO15 was low, GPIO0 was still pulled high, however GPIO2 was in output high state (a 10K resistor to ground resulted in a voltage drop of less than 100mV).  I also did some tests without GPIO15 pulled low, which, according to the documentation, should put it in the boot from SD card mode.  Every time I reset the module without GPIO15 pulled low, the module started outputting a 26Mhz signal on GPIO0.  Some googling indicates that this is what some people are calling the "zombie" mode.  Perhaps all that is required to avoid the zombie mode is to ensure GPIO15 is pulled low.

The final thing I tested was the deep sleep wakeup pin, GPIO16.  By connecting this to RST, it is possible to reset the module out of deep sleep.  I had previously tried connecting GPIO16 to RST on a ESP-03 module, but then had problems resetting the module.  The module was faulty in other ways, so I wasn't certain of the problem.  With the ESP-12-Q module, GPIO16 is driven high during reset and after reset.  Perusing the ESP8266 GPIO control files in the SDK indicates that GPIO16 does not have an internal pullup available, explaining why it is in output high mode.  This means that in order to be able to manually reset the module, a diode or a resistor of about 1K should be used between GPIO16 and RST.  Otherwise connecting RST to ground with a 1K resistor will not result in enough of a voltage drop to reset the module, and a dead short from RST to ground could result in enough current through GPIO16 to damage the chip.

With the 4MB ESP modules available for $2, I think they will now be my preferred choice for projects requiring an MCU.  The modules use too much power to work from a CR2032 coin cell, so for such things I'd likely use an AVR.

Tuesday, September 29, 2015

Under $3 Chinese Arduino UNO compatible board

With UNO compatible boards selling for under $3 on AliExpress, I decided to order one.  Some people might think you're only going to get cheap crap for that price, but in some ways it is even better than the original Arduino UNO R3.

Some boards can be found with a microUSB connector, but I prefer the full-size connector since it is much more robust, and I have half a drawer full of the old cables with no more use for them.   One thing that could be better on the board is the choice of USB-ttl chip.  It uses the CH340G chip, which, depending on your OS, can be problematic when it comes to drivers.  Prolific and FTDI have both done some nasty things with their drivers to deal with clone chips, so I wouldn't recommend either of them.  The Silicon Labs CP2102 would probably be my first choice.

The board arrived with the female headers and ICSP header already soldered on.  The vendor could have done a better job with the packing, as the ICSP header pins were bent (though easily straightened out).  The red power LED, like many other boards I've seen, is a little bright for my liking.  It uses a 1K SMD current limiting resistor, which I may replace if it gets too annoying.

There's a part by the ICSP header that I haven't been able to identify, that looks like some kind of diode.  It is in parallel with the adjacent 10K reset pullup resistor.  If anyone knows what it is, drop a line in the comments.  The board uses a 16Mhz SMD resonator to clock the ATmega328p, and strangely also has a couple of (22pf?) loading capacitors.  While crystal oscillators usually require loading capacitors, ceramic resonators do not.  A quick frequency check by toggling a pin at 2Hz confirmed it is clocked slow.  With the frequency counter on my multimeter I measured 1.984Hz, or 0.8% slow.

To make a more exact frequency measurement, I used my Rigol 1054z to probe the oscillator pins, and measured 15.8537, or 0.9% slow.  I then decided to remove the caps.  I have a hot air gun, but was concerned the heat could damage the SMD oscillator.  Instead I used the 2 soldering-iron technique to heat both ends of the SMD capacitors and remove them.  With the caps removed, the frequency measured 15.9410Mhz, or 0.4% slow, within the +- 0.5% typical rating of ceramic resonators.

I think the board is well worth 268c price, for someone starting out with AVR MCUs I think one of the Nano clones is a better idea.  For less than $2 you get a board that is simpler to use with a breadboard than a full-size UNO.

Thursday, September 24, 2015

145c ATmega328 Pro Mini

Last month when I saw an Aliexpress listing for a 145c Pro Mini (no longer listed), and it was a version that I hadn't seen before, I quickly ordered it.  The board design has pads for a regulator, although I haven't seen a version of this board for sale with the regulator populated.  I power most of my Pro Mini projects from 5V or even 3V battery power, so the lack of an on-board regulator is not an issue for me.

While waiting for the board to arrive, I reviewed the photo posted by the seller and noticed there doesn't seem to be any decoupling capacitors on the board.  The two small (0603) caps appeared to be connected to the reset button (for the DTR-controlled auto-reset), and to AREF for reducing ADC noise.  So when the board arrived, the first thing I did was probe the connections, confirming that there is no on-board decoupling cap.  The pre-tinned pads for a regulator provided a good spot for a 0.1uF 0805 decoupling cap.  So in addition to soldering the side header pins, I added a decoupling capacitor.

When I powered up the module, the green LED connected to pin 13 (PB5) started flashing every two seconds or so.  The power LED is also green, and almost blindingly bright.  A quick check with my meter revealed the current-limiting resistors for both LEDs were 470 Ohm.  Most of my SMD parts are 0805, but I do have a reel of 15K 0603 resistors.  Changing the resistor for the power LED to 15K changed it to a modest but still clearly visible glow.  Having a 470 Ohm resistor with a low-Vf LED (I measured ~2V) risks attenuating the slew rate of the SPI SCK signal which is the secondary function for PB5.  While I was able to check the fuse settings with a USBasp without problems, I still decided to change the resistor from 470 Ohm to 7.5K Ohm.

Speaking of the fuse settings, here's the readings from avrdude:
avrdude: safemode: Fuses OK (E:00, H:DA, L:FF)

Those fuses correspond to a 2K bootloader, 4.3V brown-out detection, and low-power clock 8-16Mhz, slow rising power (65ms from reset).  The clock fuse settings are detailed in table 9-4 of the ATMega328 datasheet (pdf).  I flashed my picobootSTK500 bootloader to free up 1.5K of space for code, and I may also change the brownout fuse bits to 2.7V so I can power it at 3.3V.

Unlike the Baite Pro Mini's I've bought before that have a crystal oscillator, these modules have a SMD ceramic resonator.  While the resonators take up much less board space, they are not as accurate as a crystal oscillator.  The accuracy of crystal oscillators is typically +-20ppm, and ceramic resonators are typically +- 0.5% (5000ppm).  I probed PB6/PB7 of the ATmega with my scope, and measured a frequency of 15.9837Mhz, which is 0.1% slow.  The timing wouldn't be good enough for a clock (it would run about 1.5 minutes slow per day), but it is perfectly adequate for high-speed (115kbps) serial UART or even low-speed (1.5mbps) USB.

While I am satisfied with my purchase, I've noticed that the price for the Baite Pro Minis with the on-board L05 regulator and large MLCC capacitors are now selling for 149c.  Even if I don't use the regulator, I'd spend the extra 4c just for the on-board decoupling caps.  The latest Baite boards also use > 1K Ohm resistors for the LEDs.

Monday, September 21, 2015

Diodes, diodes everywhere

I recently was breadboarding a circuit and needed a couple diodes.  I couldn't find my 1n4148s, so I used a couple of 1n4006s.  With their heavy gauge leads for high current carrying, the 1n4006 diodes are hard to plug into a breadboard.  Then I remembered the bag of tl431s I have, and that just like the zener diodes they are meant to replace, they can be used forward biased.  The tl431 block diagram above shows the diode from the anode to cathode.

One other difference I noticed with the 1n4006 diodes is their lower voltage drop.  As I discussed in my 5c lithium ion battery charger post, diodes don't have a fixed voltage drop, but have a voltage drop that increases with increased current.  At 1mA, 1n4148 diodes have voltage drop of 0.6 - 0.65V, while 1n4006 diodes have a voltage drop around 0.5V.  None of the datasheets for the 1n4148 or 1n400x had detailed specs for low current.  The first couple of 1n400x datasheets I found didn't even show current below 100mA.  However Jack Smith has a great write-up on the forward voltage of the 1n400x diodes including curves going down to 10uA.   I measured the forward voltage of the 1n4006 diodes using my multimeter (which uses a current of about 500uA) in the .502V to .515V range.  Jack's tests don't include the 4006, though my measurements would suggest that it falls in between the curves of the 4005 and the 4007.

Next I measured the voltage drop across the tl431 anode-cathode diode:
.542, .546, .540, .543, .539, .546, .541V

I also measured reference-cathode diode.  It isn't a discrete diode like one between the anode and cathode, it is the diode formed by the base-collector of the reference input transistor:
The variability of the A-K diode was about +-0.7%, the R-K diode was more consistent at around +-0.2%:
.729, .730, .728, .728, .727, .728, .730V

I also measured the base-emitter voltage of some old 2N2222a NPN transistors:
.601, .608, .612, .608V

and I measured the base-collector voltage too:
.605, .613, .616, .614V

Another common but often forgotten diode is the clamping or protection diodes on MCU input pins.  Here's a diagram from an Atmel AVR datasheet:

Although the datasheet and schematic suggest there is no difference between the protection diodes, there is a noticeable difference in the voltage drop.  The measurements for the protection diodes going to Vcc on an ATtiny13a were as follows:
.631, .631, .633, .629, .628V
and from ground:
.560, .561, .538, .537, .538V

The measurements from an ATtiny85 going to Vcc and from ground were as follows:
.634, .612, .613, .633, .634V
and
.554, .555, .555, .551, .553V

The voltage drop across the ground protection diodes is close to the 1N4006, which would suggest a current handling ability in the hundreds of mA.  Although circuits that take advantage of the ground protection diodes are extremely rare, the Vcc protection diodes allow for simple level shifting.  An AVR running at 3.3V can receive 5V signal simply by using a current limiting series resistor of around 1K Ohm on the input.

Sunday, August 30, 2015

Calibrating a cheap crappy tire multimeter


Anyone living in Canada is likely familiar with CT products carrying the Mastercraft branding.  They are significantly overpriced to allow for heavy sale discounts of 50-60% that usually happen a few times a year.  About 10 years ago I bought a Mastercraft model 52-0052-2 auto-ranging multimeter when it was on sale for C$20 (about US$15 at current exchange rates).  I use it for low-voltage, and have another multimeter with a current clamp that I use for household (mains) 120/240V testing.

I've been using it a lot over the last few years, and started getting a feeling that it was reading a bit high, based on readings from 3.3 and 5V regulators, and even from comparisons with battery voltage readings.  After testing a batch of TL431 voltage references, I was able to confirm that it is reading between 0.6% and 0.7% high.  I also ordered a couple 0.05% REF5050s, which will allow me to double-check my TL431 measurements.

After opening up the meter, I found there are 8 trimmer pots, and no indications on the board as to which of these adjusts the voltage.  I eventually found a discussion on EEVblog  that indicates the meter is made by the Hong Kong company Colluck, and is spec'd for 0.8% accuracy on voltage readings.  I have what DIPlover calls the old model, which measures 9cm wide and 18.5cm long.  While I still couldn't find documentation on how to adjust the calibration, I did find a review of another cheap multimeter that had several trimmer pots, and the pot labled VR1 was the voltage calibration trimmer.  I figured I had little to loose by trying the same pot on my meter.

In case VR1 didn't adjust the voltage, I needed to adjust it back to it's original position.  I used an ultra-fine sharpie to mark a small line on the top and the base of the trim pot so I could locate the original position.  I used a TL431 which was reading 2.513V, which I though should read around 2.496V, connecting it to my meter probes with a hook probes.  With the first small adjustment of the pot, the voltage reading went up to over 2.53V, so I had the right pot.  The sensitivity was a bit of a problem, as the tiniest adjustments I could make were undershooting and overshooting.  After several tries, I got a reading of 2.496V, which I think is within 0.1%.  With a couple of REF5050's it should be possible to calibrate it to +- 1mV, or 0.04%.  But given how sensitive the trim pot is, I won't touch it as long as it is within 2mV.

Thursday, August 27, 2015

Cheap TL431 voltage references


Until a year ago I had never heard of the TL431.  Then I read Ken Shirriff's blog post, as well as other mentions of the TL431 on hackaday.com and eevblog.com.  I found out the 431 is useful not only as a voltage reference, but also as a constant current control, and even a voltage controlled oscillator.

I had started suspecting my cheap (~$20) auto-ranging multimeter was reporting voltages a bit on the high side, and when I found 100 TL431s selling for less than 150c, I ordered them.  While waiting for them to arrive I tried to find out more information about the manufacturer, Wing Shing Computer Components of Hong Kong.   I could not find an active web site (at least in English), and although I found an old datasheet for the WS-TL431, I could not find anything current.  I did find another Aliexpress seller that posted a photo of a box full of WS-TL431A showing a 0.3% accuracy rating, which, considering the low price, is quite good.  Even 1% rated genuine TI TL431 parts are difficult to find for less than 2c each.

Once I received the package, I checked out the chip markings, which were all the same:
WS
TL431A
155SD

I suspect the 155 is a date code for 2015, 5th week, indicating these are new parts.  The old datasheet from Wing Shing shows the TL431A part as only 1%, and a TL431AA as 0.5%, and nothing listed for a 0.3% part.  I don't think I'm perpetuating an unfair stereotype to say that the Chinese are notorious for bad or non-existent documentation.  I think that the parts I received are actually rated to within 0.3% at 25C, and the manufacturer has not undertaken to produce an updated datasheet (or English website, for that matter).  Other compatible parts such as Linear's LT1431 is rated at a 0.4% initial tolerance, and the  price is in line with similar Chinese TL431 parts such as the ALJ TL431A and the CJ431.  After checking the WS TL431 chip markings, I setup a simple circuit on my breadboard with a 270 Ohm input resistor (which should give about 9.5mA) from a ~5V USB power supply to test the parts.

I tested a total of 25 parts with ambient temperature of 24C.  The average voltage reading was 2.513, and the range was from 2.506 to 2.517, or 2.5115V +-0.23%  The measurements are consistent with the parts being 0.3% rated, as well as suggesting my meter is reading about 0.6-0.7% high.

The next thing I tried was to crack open the TO-92 package with a pair of pliers in an attempt to expose the die.  Like Ken, I was able to expose the copper anode (seen in the very first picture), but was not able to expose the die.  The die appears to be around 0.6mm x 1mm, so even if I was able to expose the die, with only a magnifying glass, I doubt I would have been able to see much.

My intention in trying to expose the die was to see if the Wing Shing parts are fuse trimmed like the TI part depicted by Ken.  Two fuses give four different combinations of trimming options, which should show up as more than one peak in the distribution of the voltages.  Without a die, I could still analyze my measurements and look for peaks.   A simple shell command was all I needed:
sort voltages.txt | uniq -c
      1 2.506
      1 2.508
      2 2.509
      3 2.510
      2 2.511
      3 2.512
      1 2.513
      3 2.514
      3 2.515
      3 2.516
      3 2.517

Even with only a quarter of the parts tested, it is evident the voltages are concentrated around 2.510V, 2.512V, and 2.515/2.516V.  While more data points would be helpful, the testing is consistent with fuse-trimmed 0.3% parts.

The first practical circuit I made with the TL431 uses it as a 2.5V zener for battery reconidtioning.  I had been using a 270 Ohm resistor to discharge the batteries.  With the TL431 acting as a 2.5V zener, a high current red LED and 160 Ohm resistor add up to an addition 2.5V drop, very close to the 4.8V total when discharging a 12-cell battery to 0.4V/cell.

I'd like to have a discharge closer to 0.1C, which would be around 130mA, but the red LED is rated for 50mA maximum continuous current.  The TL431 datasheet has a simple constant current circuit, and by making a couple small modifications to that circuit I think I can make a 130mA constant current discharge circuit with a cut-off voltage just below 5V.

2015/09/22 Update

I did a quick test of the dynamic impedance, or the change in reference voltage vs change in shunt current.  Increasing the current from 3mA to 15mA resulted in a 2mV increase in reference voltage, indicating a dynamic impedance in the range of 0.15 to 0.2 Ohms.

2015/12/20 Update

Based on my testing with an AD584, I now believe these are 2.5V references, not 2.495.

Sunday, August 23, 2015

DC converter modules using fake LM2596 parts


Kerry Wong recently tested some cheap LM2596 DC buck converter modules, very similar to the ones I purchased off Aliexpress a over a year ago for around 80c ea.  One of the comments indicated these actually use clones of the LM2576 re-labeled as 2596.  The switching frequency of the LM2576 is around 50KHz, vs 150KHz for the LM2596, making it easy to see the difference on a scope.

I pulled out my DS1054Z, one of the DC buck converter modules that I had previously adjusted for 3.3V output, and connected the input to 5V.  Here's the output on pin 2:

Measuring of the 5us scale, two cycles takes about 36us, or 18us per cycle, or 55.5kHz.  So the ones I received are fakes.  I did test the modules after I received them, and found they are good for about 2A @5V with 12V in, so they weren't a total waste of money.

The latest "LM2596" modules I've seen online clearly do not use a real or even fake 2496.  The SOIC-8 part appears to be a MPS MP1584.  With a switching frequency of up to 1.5Mhz and a smaller form factor, the modules look like a reasonable value at 42c ea, even though they're falsely advertised as LM2596.  Strangely, some sellers correctly advertise the same modules as MP1584 converters, but at several times the price.