Contextual Electronics: CE Header Part 1 – building

The third CE project, and the first paid one, centers around a standardized header, intended for interoperability.  CE provides a keyed design meant to carry common signals, and use it in the first exercise to connect a Teensy to a sensor board.

The Teensy, specifically the Teensy 3.2, isa small USB-based microcontroller board with an ARM 32 bit processor on it.  It can be programmed using the Arduino IDE.  The board has a fair number of pins, and I chose to populate them with female headers on the bottom.  Not yet sure it was the best choice.

The first part of the project is the interface board.  It has Teensy-compatible pins one one side, and the CE header on the other, thus allowing any CE header device to talk to the Teensy.  I put male pins on the Teensy side, and female pins on the CE side.

The board has a jumper for selecting 3v3 or 5v on one of the CE header pins.

Here you can see the two boards together:

The final step of the design was the sensor board.  This board carries a bunch of things – a digital serial-to-parallel buffer that lights up LEDs, a digital (i2c) temperature sensor, and an analog (resistive) light sensor.  This was the most challenging part, as the goal was to fit a 1″ square design.  I made it harder yet by using some different (larger) components than in the reference design.  Some of the components are not yet populated, as I’m still trying to decide what to use.

All three boards stacked together:

Contextual Electronics

Did I mention lack of focus?  Yet another program I’m following is the Contextual Electronics course.  The focus here is very practical.  It teaches KiCad, the free open source schematic and PCB design tool, and practical design skills.

This is a paid program, but the fees are quite reasonable and there’s tons of live support.  The first few projects are free.

You can also get a Digilent Analog Discovery 2 at a discount price, which is a really nice piece of gear, especially if one doesn’t already have an oscilloscope.  I do, and mostly got this for the logic analyzer capability.

I did the design for the first project (“Shine on you crazy KiCad”) but didn’t bother building it.

The second project, “Getting to Blinky 4.0” I built, for the SMD soldering practice, mostly.

DDaCA Lab 2

Lab 2 revolved around the seven segment displays available on the DE2 board.  The project was to build a seven segment display decoder which takes as input a four-digit binary value (set with the switches on the DE2) and displays 0-F on one of the displays.

Again, the design was done graphically, but this was a much more complex circuit and got very repetitive to do this way.  Good thing no one designs logic this way for real.  On to Verilog in the next lab!

DDaCA Lab 1

The first lab of the program involved building a full adder.  The adder is designed graphically, simulated, and then synthesized to the DE2.

The graphical design is straight forward if not very efficient:

Most of the effort went into getting all the computer to board connections correct.  The first lab is detailed in how to do this, keep it handy!

Digital Design and Computer Architecture

Because I can’t focus on just one textbook at a time, I recently read Digital Design and Computer Architecture, ARM Edition, by Harris and Harris.  Mostly, I wanted to learn about FPGAs.  To that effect, I got lab materials (found under the “Companion Materials” in the link above) and bought myself an Altera DE2 board.

This is an older board, out of production, but easily found on eBay.  This one was in mint condition with all of the accessories.  It features a Cyclone II FPGA which is nice for two reasons – it’s still in production, and it’s one of the last FPGAs in production that doesn’t use a BGA footprint, making it actually usable in hobby projects.

Altera provides the free Quartus II software (Web Edition is the free version), but beware – to program a Cyclone II you need version 13.0.1 or earlier (though why go earlier I don’t know).  This seems odd to me, as they still make the chip, but don’t support it in the current tool chain.  The old versions can be downloaded from the Altera website.

I also needed one more file – the lab materials give a link to a file “DE2_pin_ assignments.csv” but, unfortunately, that link points to an on-campus only server at the author’s university.  Still a google search found the same file elsewhere.

Another useful note on this board:  I’ve been a fan of Bruce Land‘s videos from his Cornell microprocessor and FPGA classes.  In the older version of the FPGA class, the one from 2011, he uses the same boards.  I plan to attempt at least the first lab project from that lab.

Edit from 2024:  The link above, to the Elsevier page, no longer works.  The book itself can be found here: https://www.amazon.com/dp/0128000562/
Some of the supporting files and labs that had been on the Elsevier page can be found here: https://pages.hmc.edu/jspjut/class/s2015/e85/#

Lab 3: Diode Circuits (Part 1 – LC resonant circuit, 1/2 wave rectifier, full wave bridge rectifier

Did these a while ago, but didn’t get a chance to post them.

Not much to say about them, other than, again, paying attention to impedance matching and loading is key.  10:1, for this low frequency stuff.  Can’t impedance match 1:1 like I’m used to with radio stuff.

3L.1.1 The LC resonant circuit worked as predicted, but I didn’t get any photos.  A 0.01uF capacitor and 10mH inductor predicted a resonant frequency of 5kHz and the actual measured frequency was 4.85kHz.  That’s 3% error, well within the 10% capacitor tolerances.

3L.1.2 The f3db values were found to be 5.18 and 4.59kHz, for an average delta-f of .3 kHz, giving a Q of 15.3.

3L.1.6 To get the ringing I had to change the current limit resistor from 100k to 10k.  Otherwise, there just didn’t seem to be enough current to do this exercise well.  Using the decay ringing to estimate Q I found about 3 cycles before the voltage dropped below 6%, for a Q value of 19.  Probably close enough to the 15.3 above.

3L.2 The half-wave rectifier worked as expected.  Vpeak was 10V, meaning the transformer was a little high (the rated 6.3Vrms of the transformer should have given me 8.9Vpeak).

3L.3 Full wave bridge rectifier was assembled on a breadboard, and, as predicted, I blew a pair of diodes before I got it right.  I begin to dislike solderless bread boards more and more.  But can’t exactly roll a custom PCB for each project. Once it was built right, it behaved as expected:

The full wave rectifier gave me a 9.3Vpeak, exactly consistent with one extra voltage drop.

3L.3.1 The ripple amplitude without filtering was the full 9.3V at 120Hz.  Once a 15uF capacitor was added, it settled down to 1.52Vpp.  Calculated ripple should have been 2.24Vpp.  Not sure why that much discrepancy.  Maybe stray capacitance in the breadboard?  Stray inductance in the leads?

3L.3.2 To design a filter for 1Vpp ripple at 20mA current, I found I needed an R of 465Ohm and a C of 160uF.  Built up, this system worked too well – actual ripple was about 840mV.

This makes sense, since the design rests on Assumptions 1 and 2 which err on the side of less ripple.

Lab 2: RC Circuits (Part 3 – “high” voltage experiments)

With the transformer box complete, I was able to finish Lab 2.  The last exercise required one to combine a 10kHz signal from a signal generator with the 60Hz output of the transformer, and then use filters to isolate one or the other.

Once again, this was an exercise in understanding impedance.  The lab mentions that the signal generator has a 50R output impedance.  Great, I thought!  I know they suggest that input impedance of the next stage (filter) should be 10x time the output impedance of the previous stage, so I’ll set the resistor (impedance of an RC filter is just the resistance of the R component) to 500R!

Except, of course, that there was also a 1k resistor in-line with the signal generator (to limit current).  So my output impedance was actually 1050R.

Additionally, I set my cutoff frequency poorly in earlier attempts.  Trying to separate 60Hz from 10kHz, I set the f3db frequency of the filter at 1kHz.  This didn’t provide nearly enough attenuation.

After some help from the awesome folks at the eevblog forum, I made it work.  An R value of 10k solved the impedance issues, and cutoff frequencies of about 5.3kHz (C=3nF) for the high-pass and 636Hz (c=25nF) for the low-pass got the signals relatively clean.

Lab 2: RC Circuits (Part 2 – transformer box)

Lab 2L.2.3 and 2L.2.4 (as well as some exercises in Lab 3) called for using a transformer to step mains voltage (115V) down to 6.3Vrms and then do various stuff with that voltage.  The parts list simply called out a transformer part number (https://www.mouser.com/ProductDetail/546-266JB6) , which arrived with bare wires:

I wasn’t about to stick the bare wires into the socket, and even just soldering on a power cord seemed unsafe.  I wanted a proper enclosure and a fuse.  So I decided to build one.  This proved a bit more of a saga then I expected.

The first thing I wanted was an entry module.  Following advice in the AoE, I didn’t want to roll my own, but rather purchase one that took a standard IEC 320-C14 cable (the standard “computer” power cable), had a fuse holder and a switch, as well as safety features like making it impossible to open the fuse compartment while the cable was plugged in.

After poking around on Digi-Key, I settled on the TE Connectivity PS0S0S000 unit.  The basic line is available with all sorts of features like noise filters, but I didn’t want that, since the noise was part of the lab.  The module required more work than I expected,  The three basic parts of the module – the receptacle, switch, and fuse holder – weren’t connected, I had to make up a bunch of jumpers.

The module uses automotive-style quick connect tabs in a less-common .187″ x .032″ size (.25″ is much more common).  I found some at a local AutoZone, but they were meant for 16-14 gauge wires, whereas I was working with 20 and 22 gauge (the transformer leads were 22 gauge, so I saw no reason to go any thicker than 20).  Fortunately, there’s a trick where you can use a larger crimp terminal to hold a thinner wire plus a stub to make up the thickness:

Using a good crimper is a must.  Forget the cheap sheet metal ones that come in kits with the crimp connectors.  Get a good ratcheting one.  I don’t recall where I got mine, but something like this one from Amazon will work great.  Or you can get a kit with a bunch of jaws.

The next challenge presented by this entry module was figuring out the fuse.  The datasheet says “1 or 2 fuses 1/4″ x 1-1/4″ or 5 x 20mm”.  As far as I can tell, the “two fuses” are only meant for 220V setups, so I opted for one.  I had trouble finding a 1/4″ x 1-1/4″ fuse that I liked (I wanted ceramic, not glass), so I bought a 5x20mm kit from Amazon.  What I didn’t realize is that the metric fuse was much smaller, and it took a bit of experimentation to get it into the fuse holder just right.

The datasheet didn’t help much, but Digi-Key had a video on how to replace the fuse in these modules, and between that and some probing with a continuity tester I was able to figure it out.  The fuse holder can go in two ways, depending on whether you use it for 110V or 220V.  Unlike the one in the video, mine didn’t labels.  The important aspects were that the smaller fuse has to go into the bottom (towards the “feet”) part of the holder, and the clip (the bit with the blue pen on it) goes on the other side.  Note the orientation of the power rails in the photos.  I ended up labeling the top to make it clear in the future:

Jumpers had to be run from the plug terminals, to the switch (which is DPST, disconnecting both sides of the line, important in case of an improperly wired outlet), to the fuse holder.  Be careful of the switch orientation – it’s rotated 90 degrees to the other parts – use a continuity checker.  (Note:  I added heat shrink to the jumpers later on, for extra safety)

Wiring the transformer came next.  The primary coil had two ways to be wired, one for 115V the other for 220V, and that was fine.  For the secondary coil, the included instructions offered “parallel” and “series”, with no further info.  A google search found their website which showed that I wanted the series connection.

To house the whole thing, I chose an aluminum project box I found at Digi-Key –  at 6″x4″ it was the perfect size, and it came with perforated side and top panels, which meant I didn’t have to worry about the transformer overheating.

To make this work, I needed to make a rectangular opening for the entry module, plus some holes for the binding posts, transformer hold-down screws, and a grounding lug.

Holes are easy – best way to make them in something like this is a step drill, available at most hardware or building supplies stores.  This one goes up to 1/2″, which is perfect.:

To make the rectangular opening for the entry module, I scribed some lines based on the datasheet, drilled a starter hole, and then used a nibbler to cut to the lines.  The nibbler was a cheap one from Amazon. There are definitely better ones out there, but this one worked ok.  Jammed on a bit of waste occasionally, but was easy enough to clear.

To get the clearance to use the nibbler from the “inside”, I had to unbend the box.  The aluminum looks like it can (and did) take a single incident of being unbent and rebent at each bend, but I wouldn’t do it twice.  Hint:  Unbend the side you want to nibble, not the opposite side (the way I did initially).  Much easier that way.

The transformer flange had two mounting holes.  Two holes in the bottom of the box, plus some generic bolts and nuts, secured it next to the output box:

I should probably add some stick-on vinyl feet or something, since right now the box rests on the two screws.

For the output, I set up binding posts.  I wanted paired ones, so that a standard double-banana plug could go in, and didn’t want to rely on getting the distance just right, so I got a dual set made by Pomona.  Unfortunately, I could only find double binding posts in red and black – not really right for AC.

To provide isolation from the chassis, the holes had to be 1/2″ in diameter, so that the plastic bushings engaged.  The step drill worked great for this.

The secondary coil of the transformer were crimped to some ring terminals  (correct gauge this time, 22-16, found at a local Ace Hardware store) and then attached to the binding posts with the provided nuts.  The two halves of the coil were connected together with a crimp-on butt splice.

Finally, a ground lug and jumper were made, to tie mains safety ground to the chassis.  This is an important safety measure – if the hot wire should come loose on the inside, it could electrify the case, presenting a serious shock hazard.  By grounding the case, such a failure would short the hot wire to ground, blowing the fuse or popping the circuit breaker rather than shocking the user.

The grounding bolt is also brought to the outside, in case one wants to tie the rest of the project to mains ground, though this is rarely a good idea – one of the advantages of using a transformer like this is to provide galvanic isolation from the mains.

That’s about it.  I added heat-shrink tubing over the crimp connectors to everything not protected by the fuse, printed on some labels, and closed up the box:

The project works flawlessly, in that I was able to get the correct AC voltage across the binding posts and complete the rest of the lab.  More on that in Part 3.

(While I have a pretty good metal shop with all sorts of measuring and marking tools, it’s currently in storage.  So this project was done without them, and it shows – nothing is square to the box.  Really should have gotten a machinist’s square or something before doing this.  Oh well).

Lab 2: RC Circuits (Part 1 – low voltage experiments)

Exercise 2L.1.1 calls for figuring out the RC constant, and then R and C of an RC low-pass filter.  In their lab, the authors hand the students a “wrapped” R and C pair.  Since I didn’t have that option, I had to improvise.  I had a pair of Elenco Resistor and Capacitor Substitution Boxes.  I pulled off the knobs, spun them in my hands, and then reinstalled them and spun the boxes to random settings.  Instant mystery filter.  (Of course I then had to use a DMM and an LCR meter to reinstall the knobs correctly…)

Despite the book’s careful explanation, I initially set the oscilloscope time base too short, and struggled to get correct values.  Eventually, I figured it out….

Exercises 2L.2.3 and 2L.2.4 gave me real pause and stopped me for quite a while.  They called for using a transformer to examine noise on the 115V electric mains.  While the transformer was one of the items on the parts list, it came as a bare transformer with some wires.  I wasn’t about to stick the bare leads into the socket.  Just soldering on an extension cord also seemed unsafe.  So a more elaborate safety enclosure seemed in order.  Details in Part 2.

Lab 1: DC Circuits

Lab 1 was very basic – using the breadboard, Ohm’s law, mostly things I already new.  However, this lab helped me internalize one critical thing – output impedance.  I’d read about it, but I didn’t really understand, on an instinctive level, why you want low output impedance and high input impedance in circuits.  This was something that needed to be played with.

Exercise 1L4 was very satisfying – it involved measuring I and V through a diode and plotting the results.  The resulting plot, done in Excel, matched exactly the expected diode curve.  The science worked!  See linear and log graphs – perfect straight line on the log graph, as predicted:

Exercise 1L3 required a little bit of work.  The lab called for using a bare meter movement to do some of the experiments.  Unfortunately, no movement was listed in the parts list.  I ended up buying an uxcell 0-100uA ammeter from Amazon:

Worked well.

The lab guide called for soldering a pair of 1N4004 across the movement, one in each direction, to protect it from excess voltage.  I did just that, as can be seen in the pictures:

The lab was otherwise uneventful.