I just bought a couple of Teensy 3.1 boards to play with. The Teensy is a pretty small processor board that looks to be quite capable. It is smaller than the Arduino Nano boards I have been using for various other projects and still it has more I/Os, is cheaper and has a much more powerful processor, an MK20DX256, which is a 32-bit ARM Cortex-M4 from Freescale running at 72 MHz with 256 kB flash and 64 kB RAM.
The downside is perhaps that it is a proprietary design and while the schematics is available, the bootloader running on it is not, so unlike with the Arduino Nano, it is not possible to start out with a Teensy for prototypes and then move to a custom layout while still being able to use the same bootloader.
It is possible to develop programs for the Teensy using both an adapted version of the Arduino environment as well as using Eclipse. There are quite a few libraries available, including NeoPixel, OneWire, Xbee, capacitive sensing, IR remote controls, LCD displays, PS2 keyboard input, CAN, stepper motor control etc.
First you need to install the normal Arduino environment, and then the above mentioned adaptations. When you subsequently run the Arduino environment, a number of Teensy board versions are now available as target boards. Also several example programs are available in the menu File -> Examples -> Teensy.
To get started I took the very simple LED-blinking program Blinky and added some parameters to modify the blinking to make it easy to see if I was successful in uploading the new program. Here is the code I came up with:
/* LED Blink, Teensy Tutorial #1
http://www.pjrc.com/teensy/tutorial.html
This example code is in the public domain.
Modified by Per Magnusson
*/
// Teensy 3.1 has the LED on pin 13
const int ledPin = 13;
const int ontime = 50; // LED on time in ms
const int offtime = 50; // LED off time in ms
const int pausetime = 1000; // Pause time between bursts
const int blinks = 10; // Number of blinks per burst
// the setup() function runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
}
// the loop() function runs over and over again,
// as long as the board has power
void loop() {
for(int i=1; i<=blinks; i++)
{
digitalWrite(ledPin, HIGH); // turn the LED on
delay(ontime); // wait
digitalWrite(ledPin, LOW); // turn the LED off
delay(offtime); // wait
}
delay(pausetime-offtime); // wait for the next burst of blinks
}
Uploading of the sketch to the device turned out to be a bit messy. It seems to be necessary to press the button on the Teensy prior to uploading. Pressing the Auto button in a small window that appears on the screen might also help. Just uploading without doing anything special results in a timeout and the previous sketch being stopped.
Anyway, so far so good. Getting to the equivalent of Hello World turned out to be almost as easy as with an Arduino.
I wanted to build a capacitive detector that can sense the proximity of a conductive object, like a finger or a piece of metal. I have some idea what I could use such a detector for, but the following prototyping exercise quickly diverged into a quick just-for-fun hack.
There are many ways to build capacitive detectors. A very common one is the variety of touch sensing solutions provided for micro controllers from companies like Atmel (QTouch), NXP, Cypress (CapSense), Microchip (mTouch) and others. In addition to these proprietary solutions, there are also some open source micro controller based solutions, some using ADC inputs and others using just plain digital I/O pins.
Another solution would be to build an oscillator whose frequency is dependent on the (small) capacitance that one is trying to sense. This seemed appealing to me as i felt like building some analog RF circuitry, so I decided to go down this route. Since the capacitance that is to be sensed is pretty small, on the order of a few pF, a relatively high oscillation frequency is required to have the change in capacitance correspond to a reasonably large change in oscillation frequency.
Again, there are many options on how to build an oscillator. I decided to use an incarnation of a Colpitts oscillator, namely the common collector type. The general schematics is shown below.
R1 and R2 (and R3) provide bias to the transistor. C1 and C2 provide feedback while L1 together with the series combination of C1 and C2 determine the oscillation frequency. C3 has a value large enough to act like a short at the oscillation frequency and prevents the inductor from ruining the biasing of the transistor.
After some quick simulations in LTspice, I ended up with the below circuit.
The addition of R4 helps to make the output more sinusoidal as it provides negative feedback at high frequencies via the miller capacitance between the collector and base of Q1. The oscillation frequency with the above component values is around 34 MHz.
So which node do we use as the sensing node? One could consider using either the output or the node labeled Base, but it is probably better to use the Base as adding capacitance there does not change the feedback ratio, while adding capacitance at the output would change the feedback and possibly risk stopping the oscillation. To use the Base as a sensor, it needs to be connected to a relatively large metal plate whose capacitance will then be modulated by nearby conductive objects.
Adding a pF at the Base will change the frequency by about 500 kHz. This is certainly easy to detect if one is using e.g. a counter input of a fast micro controller.
I decided however to make the change even easier to detect (especially by slower micro controllers) by mixing the output of the variable oscillator with the output of a fixed oscillator with a slightly lower frequency to produce a signal with a frequency that is the difference between the two frequencies. The difference signal will thus see a much larger relative shift in frequency than the initial signal.
Building another identical oscillator (but without the capacitive sensing plate) is straightforward. This oscillator should however be trimmable so that it can be adjusted to have a frequency suitably below the frequency of the sensing oscillator. Typically one would do this with a trimming capacitor, but as I was building the circuits using parts from my junk bin and I had inductors with trimmable cores, I used one of those instead.
The main question that remains is how to build the mixer that shall essentially multiply the signals from the two oscillators to produce tones at the sum and difference frequencies of the original signals. There are of course many mixer circuits on the market and one can also build them using discrete components. I decided however to do it in a somewhat non-conventional manner, namely by using an XOR gate. The signals from the oscillators happen to have enough amplitude so that they can drive TTL (or CMOS) gates and I had a bunch of old 74LS86 quad XOR gates in 14-pin DIL packages. Ideally one would like to have gates with schmitt trigger inputs when driving them with analog signals. 74HC86 are XOR gates with such inputs, but since I did not have any of those laying around and did not feel like ordering any just for this quick hack, I went with the somewhat inferior (for this purpose) 74LS86.
What remains is to low-pass filter the output of the XOR gate to get rid of the high-frequency mixing products. I used a simple RC-filter for this, although an RLC-filter would have been more elegant and effective. To tidy up the signal and get a nice buffered square wave I used another of the XOR gates in the same package. Again it would have been nice to have a gate with a schmitt trigger input.
The complete circuit diagram is shown below.
C7 is meant to represent the sensor plate. The decoupling capacitors C9 and C10 have no effect in the simulation but are good to have in reality as there is plenty of inductance in the wires from the power supply to the circuit.
I built the whole thing on single-sided copper clad board as shown below.
Here is a labeled picture of the board:
For the 5 V rail I used another slice of copper clad board on top (using hot glue) of the main board. Similarly, I glued small pieces of copper clad to serve as the base and emitter nodes of the transistors. For the sensing node, I milled out a slice of the main ground plane using a hand-held Dremel. The 74LS86 XOR gate package is placed upside down to provide easy access to the pins. The GND pin is bent down and soldered to the GND plane while the VCC pin is bent and soldered to the 5V rail. A drawing of the pinout when viewed from below is very useful when wiring up the XOR gates like this. I left unused XOR inputs floating, which is not exactly good practice, but generally works fine for 74LS chips. I would not have done that with a CMOS chip like 74HC86.
I used components I had on hand throughout, so there is a mix of old and new components. The inductors probably come from some radio or TV set that I disassembled 25 or more years ago. Some of the capacitors are surface mount and perhaps hard to see. The base-emitter capacitors are 0603 types soldered directly on the legs of the transistors.
So does it work?
Yes, it does. In fact I was surprised how little trouble I had getting the oscillators to oscillate and getting everything connected right. I started out by building the sense oscillator and it worked right away. When I later added the reference oscillator and the XOR gates they also worked without any issues. No troubleshooting opportunities this time.
Below are oscilloscope screenshots showing the signals at the output of the mixing XOR gate (CH1, yellow), at the output of the low-pass filter (CH2 blue) and at the output of the buffering XOR gate (CH3, green). The first plot shows the circuit free-running without any object close to the sensing plate and the second plot shows how the frequency is reduced when a metal object is close to the sensing plate.
In the first case the mixed signal has a frequency of 1.79 MHz while it has been reduced to 671 kHz in the second case. The XOR gate is working at frequencies close to the limit of its abilities (and with input signals with poor slew rate at that), so it does not reach full swing (yellow trace), but it is still good enough for this purpose.
A couple of weeks ago, I was using an ANNE-50+ 50-ohm SMA termination from Mini-Circuits, but noticed that it did not seem to work right. When I measured it using an ohm-meter, the resistance was around 100 ohms instead of the expected 50 ohms. I put the termination aside and I just got around to taking a better look at it since I was curious about how it was constructed inside. Below are two photos of what the termination looks like.
ANNE-50+ termination
Before I started taking it apart, I remeasured the resistance. This time it was no longer 100 ohms, but rather an open circuit. So something had apparently happened inside it, although I am certain that it was not used while waiting for the autopsy.
Then it was time to start uncovering the secrets of the termination. I began by filing down the back side of it, which consists of a black plastic cap inside a brass tube.
Less than a mm below the surface, some more metal was revealed in the center of the device. This metal turned out to be electrically connected to the outer shell (ground).
Further filing next to the central metal piece allowed the plastic to be removed, revealing a 360 degree low-inductance metal connection between the center stud and the shell.
Going a bit further allowed the central stud to fall out. It turned out to be a (cracked) resistor. It seems to be either a carbon film or metal film resistor on a ceramic core. The fact that it has somehow become cracked is of course the reason the device failed in the first place.
A few final strokes with the file allows the remains of the pressed-in metal piece that connected the resistor to the connector shell to be easily removed. The center pin of the connector with its (teflon?) insulation and the other end of the broken resistor also easily falls out after this. The different pieces are shown in the photos below.
One can see that the diameter of the hole in the shell of the termination is different in the section with the connector pin and the section with the resistor. The first diameter is dictated by the dimensions of the SMA connector and is almost certainly designed to give a 50-ohm impedance with the pin diameter and the dielectric used. The second diameter might be chosen to give the best possible return loss given the dimensions of the film resistor, but it might also be chosen primarily for mechanical convenience.
This termination is specified to have a return loss of better than 21 dB up to 18 GHz. I have heard that some other terminations which are not specified to perform well up to such high frequencies use standard SMD resistors inside, but performance to 18 GHz probably benefits from the coaxial design of this device.
So what might have caused the failure of the termination? I do not know for sure, but since the center pin is largely held in place by the apparently brittle body of the resistor, it seems like a strong force or torque on the center pin is the probable cause. This might have occurred because the termination was mated to a damaged SMA connector or for some other reason.