Gas station without pumps

2013 September 3

My son’s first PC board

In Towards automatic measurement of conductivity of saline solution, I complained about not being able to use the KL25Z board, because my son was using it.  What he was doing with was building his first prototype for the light gloves project:

Here is his first PC board design, populated and mounted on the Freedom KL25Z board.  The 5cmx5cm board is a bit smaller than the KL25Z board is wide, so it only plugs in on one side (there is a screw acting as a spacer to keep it from being a cantilever).    He has not yet mounted the Bluetooth module.

Here is his first PC board design, populated and mounted on the Freedom KL25Z board. The 5cm×5cm board (the cheap size from Iteadstudio) is a bit smaller than the KL25Z board is wide, so it only plugs in on one side (there is a screw acting as a spacer to keep it from being a cantilever). He has not yet mounted the Bluetooth module.

The prototype board has many differences from the final design: no battery, no battery charger, no buck/boost regulator, no flash memory, no processor, screw terminals instead of jacks—even the LED driver chip is different, since the chip he plans to use is only available as a surface-mount device. But there is enough of the design here to start demoing and writing code.  They are hoping to keep the final board below 5cm×5cm, so as to get low PC board prices even in very small production runs.  That will mean all surface-mount parts, so I think I’ll have to get a hot-air rework tool so that they can assemble a prototype—I’ve been thinking that I might want one for myself to play with surface mount designs, so this isn’t really a hardship.

My son still owes me some money for buying him the PC board run, the screw terminals, the Bluetooth module and some heat-shrink tubing. It is a bit annoying that he isn’t old enough to get his own Visa card, so that he can do his shopping without me as an intermediary. (We’re not talking big bucks here—we’ve spent more on pizza for him when they work through dinner than they’ve spent on all parts combined.)

I’m pleased that he got his first PC board working on the first attempt—he did the design entirely on his own, though he did ask my advice about things like via sizes and how fat to make the wires. Since there can be moderately high currents for the LED driver, I recommended that he make the ground and power lines as fat as he could, and he decided to do a flood for each. The board looks quite nice:

The top view of the board with the screw terminal to be mounted on the top and sides, the header on the lower left, and the Bluetooth module on lower right.  The hole near the top right is for the screw that acts as a spacer.

The top view of the board with the screw terminal to be mounted on the top and sides, the header on the lower left, and the Bluetooth module on lower right. The hole near the top right is for the screw that acts as a spacer.


This is what the glove looks like with the five RGB LEDs lit up (I understand that the final design will have more LEDs—but the through-hole driver chip has limited pinout). They don’t have the user interface written yet, so the lights were set up by a quick-and-dirty Python script talking to the KL25Z board over a USB cable (which is also supplying power).


They have not implemented programmable flashing yet, but the pulse-width modulation (PWM) frequency is set very low here (much lower than what they intend to use in the final design), so that one gets a stroboscopic effect even with steady light settings, just from the PWM. That’s not my son in the picture, but the high-school student who started the project—my son has done most of the electronics and programming, but did not originate the idea.

The two teens spent a big chunk of the day wiring up the LEDs and writing a small test program, as they want to demo the glove tomorrow for the back-to-school event. It may also be an enticement for teens to join an Arduino/microcontroller club—look at the cool stuff you can learn to make!


Another view of the prototype light glove in action.

Once they got the demo working, they invited over a third member of the team to do some brainstorming about what else needs to be done (and how they’ll do it). It looks like they’ll be talking half the night.

Since it is clear that my son will be spending a lot of time on this engineering project this year, we decided to make it part of his official school work.  In addition to the engineering design work, he’ll also do some a paper for his econ course (on pricing the components and manufacturing, and setting a retail price for the gloves), and papers for a tech writing course.

His first tech writing assignment is to write up a description of the color space he decided to use for representation of colors in the program, and why he chose that color space out of the dozens available.  He spent a week thinking about color spaces anyway, before settling on a commonly chosen one—so writing up that reasoning for the other members of his team will be a good writing exercise.

2013 July 24

Debugging in unfamiliar territory

Filed under: Printed Circuit Boards — gasstationwithoutpumps @ 00:21
Tags: , , , ,

Today, my son tried doing some programming on the KL25Z board, which I had been playing with yesterday (after reloading the MBED download software).  I has been using the MBED online compiler, but he wanted to use gcc, using entirely code he wrote himself.

Over the weekend he had figured out how to do the clock startup and he wanted to test that, as well as the whole gnu tool chain for programming KL25 chips, as he plans to use a KL25 chip rather than an ATMega chip in the product he is designing.

The clock startup is a rather complicated state machine on the KL25 processors, which start out using a 32kHz internal clock, then need to be switched via two intermediate states to using the external 8MHz crystal with the phase-locked loop.  The state diagram for legal transitions is given in Figure 24-16 of the KL25 Sub-Family Reference Manual:

Figure 24-16, the legal state transitions for the clock generator module.

Figure 24-16, the legal state transitions for the clock generator module.

We have to get from  FEI (Frequency-locked-loop Engaged with Internal clock) to PEE (Phase-locked-loop  Engaged with External Clock), pasing through FBE (Frequency-locked-loop Bypassed External) and PBE (Phase-locked-loop Bypassed External).  There are some tests that need to be done to make sure that the external oscillator has stabilized before making the transitions.

He figured out how to do this startup with very little help from me (I’ve never seen such a complicated startup procedure)—basically we read the manual together and I explained the idea of the state diagram, but I did not read all the details about what was needed to enable the transitions or what registers needed to be set to what values to make the transitions.

He also spent a lot of time figuring out how the gnu linker scripts work, so that he could put things (like the initial stack pointer and PC values) in specific places, without having to write assembly language.  I’ve never worked with linker scripts, so he was on his own for that!

Today when he tried downloading his first program (a simple color-change blinker that used a system tick interrupt for timing), it didn’t work.  He faced the first problem of doing embedded programming—a bug results in no output.  Figuring out what went wrong is very difficult when there is no response.  He turned to me for help debugging—despite the fact that I have no knowledge of ARM assembly language nor gnu linker scripts.

Somewhat surprisingly, I was able to help him.  Here are some things that I helped him with today:

  • Linker symbols are addresses of variables, not constant integers.  When you want the value of a linker symbol in a C program you need to use &symbol to get the address.
  • To disassemble raw binary files, you can use objdump, but you need to give lots of extra options, to make up for the lack of internal information:
    objdump -D -m arm -b binary --disassembler-options=force-thumb foo.bin
    I’ve not used objdump in a long time, and never with a raw binary—we had to read the objdump manual to figure out what options were available. He spent some time disassembling both MBED binaries and the ones he generated with the gnu gcc compiler and linker, looking for important differences. He noted that the machine code generated by gcc with the default optimization setting was difficult to read, but when he turned on optimization it got cleaner and simpler, using the standard instructions for subroutine return, for example.
  • Pointer arithmetic in C knows the size of the objects pointed to, so incrementing a uint32_t* pointer to the next word is done by ++, not by +=4. He had never used pointer arithmetic before, and had not realized that pointers and integers increment differently.
  • Linker scripts do not do link-time expressions, but require constants. He had a computed location (the start of RAM on the chip, which is at 0x20000000 – (ram_size/4) ), but the linker script was not doing the computation. When he switched to using the constant 0x1ffff000 in the linker script, the initialization code he’d written for clearing the BSS region then had the correct start location to clear.
  • I asked him if he had turned on clock gating for the GPIO module and the port module he was using.  (I think that GPIO clocks can’t be turned off, but that the port module clocks can be, disabling the port to save power. GPIO uses the platform clock, but the ports use the bus clock.)
  • In linker scripts, if a block has nothing in it, then the “.” pointer is not changed, even if the block should be in RAM rather than flash memory. His bss_start address was messed up when his data block was empty, because the “.” still pointed to the word after the end of the program. He fixed this by adding .=ram_start to the appropriate place in his linker script.

Of the things I helped him debug, about the only things I knew ahead of time were the pointer arithmetic and that linker symbols are addresses.  He was doing a lot of stuff that I’ve never done (like using gcc’s __attribute__ keyword to make symbols weak so that interrupt service routines could default to a null handler, but be overridden in the linker by defining a real interrupt service routine).

By the end of the day, he had written a blinky program using the System Tick Timer with his own startup code and interrupt vector table, written entirely in C, compiled and linked entirely with the gcc toolchain downloaded with the OpenSDA chip—and he got it all to work. This is about an order of magnitude or two harder than writing the same blinky program using the MBED software development kit and online compiler. He needed to read big chunks of the KL25 reference manual to figure everything out, and some parts we had to read together.

In fact, we’re still not sure whether there is any reason to enable the clocks to port A before doing the clock startup sequence, which the MBED code does.  As far as we can tell from the manual, the port starts out with the pins defaulting to XTAL0 and EXTAL0 (the crystal), so it shouldn’t be necessary to turn on port A, but the manual is not really very clear on this point. [Update: 2013 Jluy 24 00:45.  My son checked, you do not need to enable port A.  The external oscillator starts up fine with port A left turned off, as we thought.]

I doubt that I could have done an all-C, all-gnu program any quicker than he did—and he now knows far more about ARM processors than I ever will.  I was just pleased that I have enough general debugging experience to have been able to help him the few places he got stuck.

He plans to use the KL25Z board in building a prototype of the device he has been doing PC board layouts for all summer.  He’s going to make a through-hole-part board for prototyping the electronics.  The board will not include the processor, but will have lots of connectors .  The Freedom KL25Z board is far too big to fit in the final case, but having a debugged development board and a through-hole-part PC board for the other will let him debug his design more easily than the all-SMD board that will be needed for the final product (he’s aiming for a 5cm×5cm final board size including the processor and all peripherals).  When he does get the SMD board designed, he’ll be able to use the KL25Z board as a programmer for it, since there is a simple 10-pin connector on the KL25Z board that allows using the “OpenSDA” chip on the board to program any KL25 chip through the single-wire-debug interface.  He’ll put a similar connector on the boards he designs, so that he can load firmware onto the boards (and so that hackers can load their own programs, once the open-source design is released).

2013 February 28

Pressure-sensor lab went well

Filed under: Circuits course — gasstationwithoutpumps @ 21:32
Tags: , , , ,

The pressure-sensor lab went fairly well today.  We once again borrowed soldering irons from the RF lab (where my co-instructor teaches), but we did not borrow enough board holders, so a number of students had to solder with the boards just resting on the benchtop.  This was not a major problem, but having more board holders would be good.

Many of the students had done an adequate job of doing the design ahead of time, and even those who had not mostly managed to finish within 4 hours (but the lab is supposed to be scheduled for 3 hours).  Most groups managed to demonstrate working PC boards with instrumentation amplifiers amplifying the differential output of the strain-gauge pressure sensors, generally with gains in the range 100 to 300. I have one group coming in on Monday to finish the soldering—they took the more cautious approach of debugging on a breadboard first, and had to do a little redesign to make everything work.  I think that they’ll complete with no problems on Monday, as they had good notes on what their breadboarded circuit was, and had come up with what looked like a feasible layout.

Soldering was much more routine this time than on the first soldering lab.  Students were able to check their own work for cold-soldered joints, and only one group forgot to trim the extra wire length on the back of the board after soldering (they had a short when they put the board down, from two untrimmed leads touching).

Some students called me over to help them debug at one point, but I had to refuse, as they did not have  readable schematics that I could help them debug from.  After I told them why I couldn’t help them, they redrew their schematics, and I then helped them check the design against their soldered board.  It seems that they had soldered everything up correctly according to their schematic, and the DC voltages were right at all the nodes, but the twisted-wire cable to the pressure sensor had the wires scrambled. (Luckily, they had followed my advice of using 4 different colors for the wires, though they had not followed the red=+5v, black=0v convention—several students are still using colors at random.)  When they screwed the wires into the right terminals, their circuit worked.  It seems that schematics were not the only thing that they were sloppy with!

Some of the students used PDF markup tools to add the layout of their extra wires and parts to the prototyping board PDF worksheet.  That seems to have worked well for them, producing neater and more easily checked layouts that the pencil scrawls that I (and many of the students) used.  I hope they tell me in their lab reports what tool they used, so that I can recommend it for the EKG lab and for the pressure-sensor lab next year.  No one did the wire lists that I recommended, but there were relatively few wiring errors (and those were inherited from errors in the schematics, so wiring lists would not have helped).  I think I’ll leave the wiring lists out of the assignment next year.

One thing that surprised me (another moment of culture shock), was that the seniors in bioengineering did not know what a peristaltic pump was.  I was trying to connect what they were doing to something they already knew, only to find out that what I thought was familiar to them was novel.  I demonstrated the basic principle for a couple of them by hooking two ends of the flexible tubing up to the two ports of their differential sensor, and pinching the tube between a pen and the benchtop.  By pulling the tube through the squeezed area, I could get a large pressure difference between the ports.  Since peristaltic pumps are standard lab equipment in many of the labs they are working in, I was surprised that they have never used one or even known of their existence.  I’m now wondering whether I should do the demo demonstrating the principle in class on Monday for everyone.

2013 January 7

First day of circuits class went ok

Filed under: Circuits course,Printed Circuit Boards — gasstationwithoutpumps @ 18:11
Tags: , , , ,

I went into the class with the following to-do list:

  1. Introduce teaching staff
  2. Go over syllabus, with the main points here:
    • Goal is not to make them EEs, but to bring them to electronics hobbyist levels, so they can design stuff that isn’t too tricky and talk with EEs about tricky designs.
    • Accepted as circuits course for BME, but not as prereq for other EE courses.
    • Lab centric—theory taught as needed for design labs.
    • Prelabs to be shown at beginning of Thursday labs. Oops, I forgot to mention this.
    • Lab demos to be done in Thursday labs. I forgot to mention lab demos also.
    • Post-lab writeup is major portion of grade (in both courses) due Mondays after labs. We talked quite a bit about the importance of engineering reports and who the audience for them is (not the professors!).
    • Parts kit to be sold Wednesday.
    • Free on-line books in place of hard-copy textbooks.
    • Rotating partners (prelab separately, postlab together or separate).
    • Academic integrity boilerplate.
    • Disability accomodations boilerplate. There wasn’t time for this, but I did mention in response to one question about allergies and sensitivities that we could try to work something out. The syllabus does have the needed info about requesting accommodation for disabilities.
  3. Demo of pressure sensor and EKG with Arduino data logger code.

The EKG board, which I checked over the weekend, refused to work for me in my tests before class, so I waved it around but didn’t demo it. I did demo the pressure sensor board, which worked fine. I used the v1.0.0b4 version of the Data Logger, (available from under “tags”, which is the latest named version. The version currently installed in the labs is v1.0.0b2, I believe, and I have to decide whether to update before Thursday’s lab or not. The b2 version should work well enough, I think, but if students switch Arduinos between different versions without uploading again, they might have problems.

I’ve put an improved version of the parts list up on the class web site and told the lab-support staff about it, so that they can start figuring out how much the student lab fee will have to be next year.  This year, students are paying $30 for the Arduino and $65.50 for parts and tools, but I doubt that the lab fee will be less than $150 next year.

The board designs for the three PC boards used in the course have also been released (with an appropriate Creative Commons license—non-commercial, since I’ve not paid the Eagle license fee needed for commercial designs).

Finally, I’ve tentatively lined up a biologist to talk about excitable cells and action potentials towards the end of the quarter, before the EKG lab.

In other news, my son told me yesterday that his Christmas present to me (which he had told me he would get me later), was the Data Logger code. He couldn’t have given me a nicer present: it was something I wanted, that he put a lot of thought and effort into, that he made himself, that I couldn’t have bought in a store, and that would have been a lot of trouble to do for myself. OK, so we’re both geeks, seeing a software package for teaching a course as a good present, but it really was.

2012 November 24

Hysteresis board

Now that we’re using a 74HC14 Schmitt trigger in the capacitive touch sensor for the hysteresis oscillator, that lab can be the first soldering project, in addition to learning about hysteresis.

I tried laying out a very compact PC board for the students to solder (still requiring them to do some design—they’ll have to breadboard their design first to get appropriate R and C values). I came up with one very compact design that could get 4 copies into the 50mm×50mm limit of the $1 boards from ITEAD, making the boards only 25¢ each.

Compact layout to get 4 hysteresis oscillator boards out of one 50mm×50mm board. The gutters are pretty narrow, though, and I’m not sure I’m skillful enough with the board shears to cut that accurately.  The yellow “airwires” are Eagle telling me that the Gnd and +5V wires are not connected between the different copies.

It seemed a little silly to try to squeeze the price down to 25¢, when the other parts cost 90¢: 59¢ for the screw terminals, 28¢ for the Schmitt trigger chip, 1¢ for the resistor, and 2¢ for the capacitor. With this layout it is also a little tricky for the students to properly wire the unused inputs high.

Given the high risk of ruining the boards trying to cute them with the board shears, I decided to redesign for a 50¢ board.

Much looser layout, having only two copies on the 50mm x 50mm board. This version makes it easier for the students to see how things are connected, and has lots of room for the board shears to make the cut.

The lab would now require that the students measure the thresholds of the Schmitt trigger, breadboard the hysteresis oscillator, make a touch pad out of foil and packing tape, measure the frequency of the oscillation to estimate the touch pad capacitance, adjust the parameters of the Arduino program to match the frequencies of their oscillator, solder up the board, and demonstrate it working to control an LED. I think that is plenty for a 3-hour lab.

When I set up the web pages for the course, I’ll try to make sure I put the Eagle design files (.brd and .sch) for each board the students use on the web, so that future instructors can easily order more copies of the board, even if my laptop gets run over by a beer truck.  That will also make it easier for instructors at other schools to try to duplicate the course.

Next Page »

The Rubric Theme. Blog at


Get every new post delivered to your Inbox.

Join 274 other followers

%d bloggers like this: