Category Archives: General

ReflowR on indiegogo.com

This will be my shortest post ever. But I just spotted a project on indiegogo.com that I think is worth mentioning: A small and affordable tool to do reflow soldering. It’s basically a heating plate specifically designed for reflow soldering. So it can reproduce JEDEC temperature profiles, it does data logging and and you can even control it via a web interface if you spend an extra 9$ on the wifi upgrade.

Here’s the link: https://igg.me/at/reflowr/x/15560432 or http://reflowr.com

I’ve been looking around for some kind of reflow oven for a while but nothing affordable quite convinced me. This morning I just stumbled accross this project by chance. I’ve ordered a “Large ReflowR” with the wifi upgrade and an external thermoucuple  and will report on how it performs once I get it which should be some time in February next year.

Ultrasonic Anemometer Part 24: New Microcontroller and Software Controlled Gain

It’s been almost three weeks since my last post and some further progress has been made. I’ve upgraded the microcontroller and can now control the gain of the second amplifier stage in software. But let’s look at the changes in some more detail.

20160625_AnemometerDriver_008

New microcontroller: PIC32MX250

I mentioned last time that I was running out of code space, i.e. flash memory on the PIC32MC220. That particular model has only 32k of flash and I’m using the free version of the XC32 compiler. That free version only performs limited amounts of optimization and therefore produces rather large and slow code compared to the standard and professional version. But the other two are rather costly (around USD 500 and 1000, respectively) and are not really an option here.  And at least so far I’ve always had all the speed I needed so the only issue was flash memory.

So the straight forward solution was to upgrade the microcontroller to an otherwise identical model with more memory. The 250 I’m using now has four times more of both flash (now 128k) and ram (now 32k). I unsoldered the old chip using a hot air gun and soldered in a PIC32MX250 in its place. Now we have all the flash we need to continue our journey.

20160625_AnemometerDriver_005

Getting I2C to work

My design uses a dual op amp for the necessary amplification of the received signal. The first stage is ground-referenced and uses a simple resistive divider to set the gain (currently set at 11).

The second stage is biased to 1.65V (i.e. half way between ground and 3.3 volts) and has its gain controlled by a I2C digipot. The idea is to have the PIC control the digipot so it can adjust the gain as needed to compensate for any effect that might change the amplitude of the received signal.

So in order to control our digipot we first need to get the I2C interface working on the PIC. There are two (identical) I2C peripherals on the PIC32MX2xx and this design uses one of them (#2) exclusively to communicate to the digipot. The other one (#1) is then available to interface to the outside world.

I’ve written a set of simple functions to use the I2C interface. So far I’ve only implemented  master transmit mode since that’s the only thing we need here.

  • void app_i2c_internal_init(void);
  • bool app_i2c_internal_write(uint8_t address, uint8_t *data, uint8_t length);
  • void app_i2c_internal_writeDigipot(uint8_t value);

The functions are entirely non-blocking so they can be called from within the interrupt service routines that do the measurement.

Fixing a design bug

Unfortunately, I made a mistake in the schematic when I referenced the feedback loop of the second op amp stage to ground instead of the mentioned 1.65 volts. Now let’s look at what that did to the signal. First, below is the signal with the digipot at 0 (of 256). The gain is set to one and all is well.

AmpError_Pot0

But at a setting of 64, some clipping starts to occur as shown below.

AmpError_Pot64

With the gain turned up to 4 with a digipot setting of 192 things get really uggly with a completely unrecognizable output signal.

AmpError_Pot192

I was extremely lucky that the correct signal was available right next to the pin where I needed it so all I had to do was to cut the ground connection with a carving knife and to connect the correct signal using a tiny bit of wire.  The change is hardly visible on the photo below. Can you spot it? It’s almost at the center of the photo at pin 5 (bottom right) of the small 8-pin IC. It now connects to the 10k resistor at the bottom instead of the ground plane on its right.

20160626_AnemometerDriver_009

Controlling the gain in software

With that error fixed we can now set the gain as we please. Here some examples. Yellow is the (unamplified) input signal whereas green is the output of the (fixed) first amplifier stage.  The purple signal is calculated as the difference between the DAC+ and DAC- signals. Those two signals is what we feed into the PIC to be measured.

With the gain at 1 (digipot at 0) we get a about 2.6 volts peak-peak. A bit little but sufficient.

Amplifier_Pot0

This is probably about what we want. Digipot at 50 resulting in a peak-peak amplitude of a bit above 3 volts.

Amplifier_Pot50

Needless to say that we can jerk the gain up far more than that if we want.  Below is an example where a gain of 4 results in a seriously clipped signal.

Amplifier_Pot192

Now let’s look a a situation where such a high gain might actually be useful. In the example below I’ve lowered the input voltage to only 5 volts. As a result the received signal is only 90mV in amplitude instead of the 220mV seen above. That’s easily compensated with a bit of help from our digipot. With a setting of 170 we get a nice, clean 3 volt output signal.

Amplifier_Vin5_Pot170

Calculating the necessary gain

For the examples above I’ve explicitly set the gain in the code. But what we really want is to have the software calculate and set the necessary gain automatically.

So I’ve implemented a simple algorithm to do so. I set some target value for the peak-to-peak amplitude of the signal measured by the DAC. Knowing the amplitude and digipot setting of the last measurement I calculate the optimal gain and digipot setting for the next measurement.

AmplitudesGain1

Above is the signal without this automatic gain setting in place (gain=1). As you can see, the peak-to-peak amplitudes vary quite a bit between transducer pairs. So the gain calculations, too, work on a transducer pair basis. Each direction gets its own setting to compensate for different transducer sensitivities.

Below is a screenshot of the result. Notice how now all transducer pairs have identical (and somewhat larger) amplitudes.

EqualAmplitudes

That’s it for today. Click here for my next post.

The Art of Electronics – Third Edition

20150407_211427

The world has been waiting since 1989, now it’s finally here. The 3rd edition of the classic book The Art of Electronics by Paul Horowitz and Winfield Hill is finally out. My (Amazon.de pre-ordered) copy just arrived today.

20150407_211501

It’s slightly disappointing in size. It quite matches the 2nd edition and grew only about 50 pages in volume. Haven’t really had time to read any of it or compare the table of content.

20150407_211405

Feel free to leave any of your impressions on this or the last edition in the comments below.

Update as of August 4th, 2015

I’ve finally found the time to read the first 300 or so pages of the 3rd edition. Some of the material is very familiar to readers of the 2nd edition. But there is plenty of stuff that was not yet part of the 2nd edition. Such as a very comprehensive coverage of JFET amplifiers. Other chapters have disapeared entirely such as the one on high frequency / RF circuits. In my opinion it makes perfectly sense to own and read (!) both editions. And there is a second volume (called the AoE x-chapters) to be released at some time in the future (another 30 years?) . I’m looking forward to it.

Arduino-based Inductance Meter

_MG_1131
Incuctance meter in action. It displays the resonance frequency together with the inductance

I’ve just finished a little Arduino project. It’s a shield for the Arduino Uno that lets you measure inductance. This is a functionality that I found missing in just about any digital multi meter. Yes, there are specialized LCR meters that let you measure inductance but they typically won’t measure voltages or currents. So I had to build my inductance meter myself.

_MG_1146
Close-up of the circuit with the display removed

The basic design is really simple. It a colpitts oscillator (http://en.wikipedia.org/wiki/Colpitts_oscillator) with the coil missing. You use the test leads to connect it to a coil which will make it resonate. The Arduino then measures the frequency at which the oscillator is resonating and calculates the inductance. The capacitors are part of the shield so the capacity is known.

_MG_1132
With the test leads open, the oscillator can’t resonate. The current calibration/zero-offset is displayed in stead

There is 1uH of inductance included on the schield which is placed in series with the coil to be measured. This serves two purposes: The oscillator can resonate when you short-circuit the test leads. When you then press the push button on the shield, the software will use the current measurement as new calibration. It also puts an upper limit on the resonance frequency. This ensures that the software the rest of the circuit can keep up with the oscillator.

_MG_1139
Pressing this blue button zeroes the meter

As can be seen from the schematic, the oscillator uses two 1nF capacitors in series. Together with the 1uH inductance, this limits the frequency to about 7.1MHz. In practice, it oscillates at around 5.4MHz when the test leads are short-circuited.

_MG_1137
The Arduino shield from below

The oscillator output is followed by a comparator turning the sine wave of the oscillator into a square wave. I’ve used an inexpensive but fast Microchip MCP6561R. It has a maximum propagation delay of 80ns which allows it to keep up at the maximum frequency.

_MG_1142
Viewed from straight above

But of course, 5.4MHz is way too fast for the Arduino to keep up. The Arduino runs at 16MHz and will need at least a few dozend instructions to process each pulse from the shield. My solution was to add a 74HC590 8-bit binary counter dividing the frequency by 256. That gives a theoretical maximum frequency of 7.2MHz / 256 = 27.7kHz. That’s something the Arduino can deal with.

_MG_1145
The entire shield with the display removed

For obvious reasons, there is also a display included on the shield. And then there’s that pushbutton which is debounced in hardware by running it through an RC low-pass filter and a Schmitt-triggered buffer. The button is used to zero the meter, i.e. the current measurement is used as the new zero-offset.

_MG_1151
Even very small inductance values can be measured

All related files can be downloaded as a .zip file: LMeterShield. This includes the Arduino source code (aka sketch) as well as the Eagle files and PDFs of both the layout and the schematic.

Now there’s also a stand-alone version: https://soldernerd.com/2015/01/14/stand-alone-inductance-meter/

Arduino Ultrasonic Anemometer Part 1: Getting started

This is the first of a series of posts to follow. I will describe my attempts to build an ultrasonic wind meter (anemometer) based on an Arduino Uno. By the time of writing, I have a working prototype but it will take me a while to catch up in this blog. So this is just the first post – more will follow soon.

Click here for an overview over this series of posts on the anemometer project: https://soldernerd.com/arduino-ultrasonic-anemometer/.

The finished analog part of the circuit.
The finished analog part of the circuit.

Let me quickly outline the project: My aim is to build an ultrasonic anemometer based on a Arduino Uno board. Now what’s an anemometer? That’s just a fancy name for a wind meter. I want to be able to measure both wind speed and wind direction with high accuracy. Most wind meters are of the cup or vane variety. They turn wind into mechanical motion and then measure that motion to calculate wind speed and possibly direction. An ultrasonic anemometer on the other hand sends and receives ultrasonic pulses and measures the time-of-flight. From the time-of-flight (or the time difference, depending on your approach) you can then calculate the wind speed in a given direction. Add a second pair of senders and receivers at a 90-degree angle and you get both wind speed and direction. As so often, wikipedia gives a nice overview/introduction to the subject: http://en.wikipedia.org/wiki/Anemometer

A preliminary setup to test the basic functionality of my circuit
A preliminary setup to test the basic functionality of my circuit

Surprisingly, there seem to be very few people out there who have done this before. Basically, there is this one brave guy named Carl who has built such an anemometer from scratch and put all the relevant infomation online.His project was published on hackaday.com and this is where I found it: http://hackaday.com/2013/08/21/ultrasonic-anemometer-for-an-absurdly-accurate-weather-station/. All of his documentation can be found here: https://mysudoku.googlecode.com/files/UltrasonicAnemometer.zip. This material makes for an excellent starting point if you want to build your own. I’ve looked carefully at Carl’s schematics and have copied many of his ideas. I did end up changing quite a few things and will explain my reasons for doing so but the general approach is very much the same. Many thanks for sharing this with us, Carl.

The basic idea is simple: You send a ultrasonic pulse and measure the time until it arrives at a receiver located in some distance. Ultrasonic transducers often operate at 40kHz and so do mine. A transducer is a device capable of both sending and receiving a signal. It’s the kind of thing cars uses for their parking aids, telling you if there is an obstacle and at what distance.

The board for the digital part waiting for the components to be placed and soldered.
The board for the digital part waiting for the components to be placed and soldered.

In a 2-dimensional anemometer such as here, you will have 2 pairs of transducers for a total of 4. Let’s call them North, South, East and West for simplicity. You need to be able to send and receive pulses in all 4 directions: N->S, S->N, E->W and W->E. Not all at the same time but one after the other.

So you will need some kind of circuit to route your signals from and to any of the transducers. For example you want to send from the West transducers and receive from your East transducer or vice versa. Let’s call it the digital part even though the received signal is analog in nature. The PCB without components just above is the basis for this digital part. If you wonder who or what Jingling Ding is: That’s the name of my step daughter who helped me drawing and laying out this PCB in Eagle.

You will then need some more circuitry to process the received signal. This circuit is shared among the 4 transducers so only one can be listening at any point in time. That’s why the digital part needs to route the signal from the correct transducer to this signal processing circuit. The received signal is analog in nature and will be very weak compared to the transmitted one. So you will need quite a bit of amplification first. But this analog signal cannot directly be used by your arduino to measure the time of flight. You need some digital signal(s) that you can measure using the timer(s) on the arduino’s Atmega328 chip (in case of the Arduino Uno). Let’s call this the analog part. That’s what’s shown on the photo at the top of this page.

In my next post I will go through the details of the two circuits. Click here for the second post: https://soldernerd.com/2014/11/15/arduino-ultrasonic-anemometer-part-2-digital-circuit/

Switch debouncing using 74HC14

_MG_0978

This was one of the first PCBs I ever made myself as well my very first attempt at soldering SMD components. So if you were wondering why some of the copper on the right has not been removed – that’s why. At that time, I was not even using Eagle yet but some software called Sprint Layout. But this post is not really about this unimpressing board but about proper debouncing. Something I feel strongly about 😉

_MG_0980

As opposed to many people out there, I still prefer to do all my debouncing in hardware. Yes, of course you can do debouncing in software and sometimes you may have to but if you have a choice, debouncing in hardware will generally yield better results and reduces software complexity. Most of the time, my switches will directly trigger an interrupt on a microcontroller so you really want to avoid false triggering. All that context switching associated with an interrupt adds quite some overhead compared with just reading an input pin so there are performance implications of this as well.

_MG_0981

Jack Ganssle has written a really nice paper on this. It can be found here: http://www.eng.utah.edu/~cs5780/debouncing.pdf. He has run some experiments with a wide variety of switches and explains how to deal with them in practice. What I was doing here follows the recommended approach from Jack’s paper: You take a switch and a pull-up resistor, run the resulting signal through an RC filter and add a schmitt-triggered buffer. Cheap, simple and works perfectly every time.

Here are the signals you get when the button is pressed (top) or released (bottom). Yellow is the output of the RC filter and red is the (digital) output of the schmitt-triggered buffer. Note that the 74HC14 is an inverting buffer so the output signal goes from low to high when the button is pressed.

Debounce_Eingang_LowHigh

Debounce_Eingang_HighLow

The time constant of the RC filter and therefore the resistor and capacitor values are quite uncritical if you are working with simple switches as here. As you can see in the scope screens above, it takes around 20ms from when the button is pressed (or released) until the output signal changes. That’s more than enough time even for a pretty poor switch to have stopped bouncing. At the same time, that’s instantaneously as far as the user is concerned. Anything up to 50ms feels instantaneous even to impatient humans.That leaves 30ms for the microcontroller to take the desired action. If that’s enough depends of course on what you are trying to do but generally that’s plenty of time.

Here’s yet another screenshot. This time it’s the digital output (red) as well as the same signal in analog. This is just to convince you that what your are getting is really a clean output signal. It goes high to low in less than 10ns. That’s less than one-sixth of a clock cycle on a typical (16MHz) microcontroller. Yes, there is some ringing but there always is if you look closely enough. In this case it’s well behaved with less than 700mV pp amplitude and dies out within 50ns or so.

Debounce_HighLow_10ns

Getting the balance just right gets much trickier when you’re using rotary encoders. You won’t press a pushbutton 100 times a second but it’s not uncommon to get signals from an encoder with only a few milliseconds between them. So you have to think carefully about how much debouncing you need. Just a bit too little and you pick up bouncing noise. A bit too much and you start missing pulses.

I’ll share my lessons learned on that, too. But that’s for another post in the future.

Here you find the Eagle files as well as PDFs of the board and schematic as a zip file.

Programming sockets for PIC microcontrollers

_MG_0957

I regularly use PIC microcontrollers. I’ve tried some Atmel chips lately but I’m still by far most familiar with the PIC16 & PIC18 chip families. As you can see in my other posts, I tend to use SMD components but once in a while I need to program a DIP package.

_MG_0955

I do all my PIC programming using the MikroC for PIC compiler from Mikroelektronika. They also make this MikroProg programmer/debugger that integrates nicely into their IDE.

_MG_0956

So these DIP sockets have a 5x 100 mil header that lets me connect the MikroProg and route the signals to the respective pins of the PIC. Obviously, different chips have different pin counts and pinouts so I had to make a few of them to cover all the PICs I use.

http://www.mikroe.com/

Constant Current Dummy Load

_MG_0942

This is a constant current dummy load. It’s controlled by a PIC16F1936 microcontroller. As you can see, it’s equipped with a 4×16 character LCD display and, less obvious, a rotary encoder with push button. It accurately sets the desired current via a 16bit DAC and reads both current and input voltage with a single-channel 16bit ADC each. Temperature is measured by the microcontroller’s internal 10bit ADC.

_MG_0933

It needs a 6…16 volts supply for it’s own use. That’s what the upper pair of banana plugs is for. It can then burn up to 4.5 amps in the range of 0…22 volts. You can set any current from up to 4.5 amps in 1mA steps via the rotary encoder. By pressing the encoder you can set the ‘sensitivity’ of the encoder. There are 3 ranges: 1mA, 10mA and 100mA per (encoder) step. This way, you can quickly and precisely set any current you want.

_MG_0934

There is a LM35 temperature sensor mounted directly to the heat sink. The temperature is shown on the display as well as used for protective purposes. The software automatically limits the current if the heat sink gets too hot. Using the temperature, current and voltage, it also calculates the die temperature of the two MOSFETs and makes sure their temperature rating is not exceeded. They have a temperature rating of 125 degrees centigrade and a die-to-heatsink thermal coefficient of around 4 degrees/Watt. So with higher voltages and currents it’s entirely possible to blow the MOSFETs even with moderate heat sink temperatures.

_MG_0935

You might wonder what the Xilinx XC9572XL CPLD is doing on there. Well, this was my very first project involving an LCD display, my first project involving a rotary encoder, my first project involving external ADCs and DACs… My first project at a lot of things. So I appreciated having the flexibility to change some of the signal routing in VHDL. All the signals traveling from the rotary encoder to the microcontroller and from the microcontroller to the display travel via the CPLD so I can re-route those signals any way I want. Now the CPLD mainly takes care of the encoder

The 100mil header at the front is a I2C interface that let the dummy load communicate with the outside world. It was added later so i had to run some wires to get access to the I2C bus.

By the way, this is how I got the idea of building a dummy load: http://www.eevblog.com/2010/08/01/eevblog-102-diy-constant-current-dummy-load-for-power-supply-and-battery-testing/

Simple, resistor based Dummy Load

Another afternoon project. Some time ago I was working on a 80 watts 12-to-36 Volts DC-DC boost converter. Not one of my most successful projects but anyway.

_MG_0936

So I needed some kind of load but my home made constant current dummy load can only handle 20-something volts. A few 100 ohms 15 watt resistors were just what I needed. So I took 6 of them and made a simple, single-sided PCB that holds the resistors as well as 6 switches.

_MG_0937

The resistors are upright and have a bit of an air gap between them. That’s important, they get incredibly hot with 36 volts accross them. I know, I had to learn the hard way 😉

_MG_0938

Together with the aluminium front it has a nice weight for its size and with it’s silicone feet it sits firmly on the bench.

_MG_0939

Variable Voltage Power Supply using a LM317

_MG_0929

A classic afternoon project. I was in need of a variable voltage and didn’t have a proper lab power supply available. But I did have a solid 12 volts from an old computer PSU. So I built myself this little thing.

_MG_0930

It’s really nothing more than a LM317 in a TO220 package with a pot, two capacitors and banana jacks. It measures about 65x55mm and has rubber feet so it sits nicely on the bench. All the parts I found laying around here. The little heat sink can handle 5 to 10 watts without getting overly hot.

_MG_0931

Over a short period of time you can burn quite a bit more so you can draw up to 1.5 Amps (the LM317’s internal current limit) from anywhere between 1.25 and 10 volts when connecting it to a 12V supply.

_MG_0932