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 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
.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:

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.

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.

Sunday, August 9, 2015

Pigggy-prog project ideas

I've started working on a new project I'm calling piggy-prog.  The hardware requirements are cheap and simple - a Pro Mini and a breadboard.  The pro mini boards are cheaper than a USBasp (around 150c on Aliexpress), and by piggy-backing over a DIP AVR (like the ATtiny pictured above), no jumper wires or custom programming cable will be required.  The plan is to support the 8-pin tinies like the tiny13a and the tinyx5, and the 14-pin tiny84.

The piggy-prog should be a lot safer than socket-based programmers like the stk500, especially for the 8-pin parts like the tiny85. With the 8-pin AVRs, putting the chip in the wrong way around (rotated 180 degrees) results in reversing the polarity of the power - Vcc to Gnd and Gnd to Vcc:

By selectively powering the pins of the target chip with the low-current I/O pullup power from the Pro Mini, it is possible to probe and detect the target chip without any risk of damage to either the target chip or the pro mini.  Given the lack of a clamping diode on the reset pin going to Vcc, it is possible to detect which pin is reset, and therefore detect when the chip is rotated 180 degrees.

I'll use the stk500 protocol since it is supported by avrdude, and is the protocol used when "AVR ISP" is selected in the Arduino IDE programmers menu.  And since my picobootSTK500 bootloader implements a stripped down version of the stk500 protocol, I'll be able to leverage some of the code I've already written.

Proof of concept

To test the idea, I wired up an ATtiny85 on a breadboard with connections to piggyback a pro mini running ArduinoISP.
I modified the code to change LED_ERR from 8 to 2, since pin 8 connects to Gnd on the tiny85, and I changed LED_PMODE to 3.  I first tested the ArduinoISP code without the connection to the tiny85, but was always getting a "programmer not responding" error:
$ avrdude -C /etc/avrdude.conf -c avrisp -p t85 -P com16 -b 19200
avrdude: stk500_recv(): programmer is not responding

After connecting an LED and resistor to pin9, I could see the LED heartbeat, but whenever I ran avrdude the heartbeat would stop (and another LED connected to LED_ERR would not light up).  This seems to be a but in the ArduinoISP code, since when I plugged the pro mini into the breadboard on top of the tiny85 it worked fine:

$ avrdude -C /etc/avrdude.conf -c avrisp -p t85 -P com16 -b 19200

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.06s

avrdude: Device signature = 0x1e930b

avrdude: safemode: Fuses OK (E:FE, H:DF, L:E1)

avrdude done.  Thank you.

If I can find the but that is causing the ArduinoISP code to hang when there is no target, I'll probably build on that code rather than starting from scratch.