Go here to sign up for The Embedded Muse.
TEM Logo The Embedded Muse
Issue Number 295, December 21, 2015
Copyright 2015 The Ganssle Group

Editor: Jack Ganssle, jack@ganssle.com

   Jack Ganssle, Editor of The Embedded Muse

You may redistribute this newsletter for noncommercial purposes. For commercial use contact jack@ganssle.com.

Contents
Editor's Notes

Give your team the tools they need to operate at a measurably world-class level, producing code with far fewer bugs in less time. This is what my one-day Better Firmware Faster seminar is all about. It's fast-paced, fun, and uniquely covers the issues faced by embedded developers. Information here shows how your team can benefit by having this seminar presented at your facility.

I'm now on Twitter.

Quotes and Thoughts

Productivity can decrease by as much as 25% when workers put in 60+ hour weeks for a prolonged time. And, turnover is nearly 3x higher among workers who work extended hours. Absenteeism among companies with extended hours is more than twice the national average. (From Circadian Technologies Shiftware Practices survey)

Tools and Tips

Please submit clever ideas or thoughts about tools, techniques and resources you love or hate. Here are the tool reviews submitted in the past.

Scott Whitney likes the LogicPort logic analyzer:

I'm also a huge fan of the LogicPort, and the built-in decoders for various bit-level protocols are worth their weight in gold. It blows my mind that some of the better-known MSO vendors out there charge extra to add these software-based decoders to their basic logic analysis capability!

I first used it to help with debugging a particularly nasty display interface issue. We would get data for a while, and then the display would inexplicably go dark. We suspected that the clock was getting killed, but trying to find problems with individual signals using a scope was a nightmare, and like shooting in the dark. It took a bit to get all of the control lines connected up, but once we did so we were able to capture data up until a particular clock signal stopped being generated.

I had communicated with the folks an Intronix before buying my LogicPort, and they brought a trigger out port to a 2-pin header, and we were able to use this to fire an oscilloscope in single acquisition mode. A few runs later, and we discovered some gi-normous ground bounce on the clock and data lines going to the display.

More recently, I used it to help me debug some code to read/write MicroWire (sort of like SPI) EEPROMs, and to read/write 1-Wire EEPROMs via an I2C-to-1 Wire bridge IC. The built-in decoders made this so much easier than trying to sift through tons of edges looking for the "right" patterns. I'd probably still be working on that code a month later if I hadn't had the LogicPort handy.

One other tip for people who plan to buy one of these babies: Do yourself a favor and get an extra connector cable and extra micro-grabber clips. If you have a complicated test setup, you can then leave the relatively inexpensive cable in place while you borrow the LogicPort to debug some other project! Also, the connectors on the cables do wear out over time, so don't be surprised if you find that you need to put a new connector on one of the pins down the road. Overall, the thing has been wonderfully robust. I keep it in an old CD player Velcro case when I'm not using it to keep everything together and protected.

Another tip: Try to get your hardware counterpart to put some 0.1" square post headers on the board at key test points. This lets you slip the female connectors right over the headers, without having to clip a micrograbber onto anything. It's a much more secure connection, but you have to plan ahead for it.

Highly recommended! Glad to hear that my purchase was not just a fortunate fluke.

Scott's advice about getting an additional cable and grabbers is spot-on. The cheapest source for grabbers that I know of is actually Intronix themselves, where they are advertised for $1.75 each.

Chris Deckard responded to my comment about a source for mechanical parts:

I only learned of these guys recently when they sent me an unsolicited catalog (I mention this as an indicator for decent customer service): www.accuratescrew.com

Their focus is, "Electronic Hardware and Fasteners".

Not sure how they compare to McMaster -- they (M-C) are the gold standard, after all.

Freebies and Discounts

Intronix LogicPort giveaway

The LogicPort is probably the best USB-connected logic analyzer I've reviewed (review here). The hardware sparkles at 500 MHz and 34 channels, and the user interface is great. I'm giving my LogicPort away to a lucky Muse subscriber (it does not come with the grabbers). The contest closes December 31, 2015. Go here to enter. It's just a matter of filling out your email address. As always, that will be used only for the giveaway, and nothing else.

More Quadrature Routines

The last Muse had code for debouncing quadrature data. Daniel Wisehart has an alternative:

On the subject of quad encoders, it is important to know what processor you are designing for.  With an 8051 Paulsen gave what is probably a nearly optimum design.  But ARM processors have an integer pipeline that keeps getting better as you move from ARM7 to ARM11:

Something like this may be better suited to a pipelined processor, because it allows multiple branches to be processed in parallel:  http://cmsc411.com/history-arm-integer-pipeline (this link seems to be broken).

int  quadDecode( int prev, int enc ) 
               { 
      static int result[] = {  0,  1, -1,  0, 
                              -1,  0,  0,  1, 
                               1,  0,  0, -1, 
                               0, -1,  1,  0 }; 
      return result[ prev << 2 & enc ]; 
               } 

Of course, in an FPGA, this is best done in a LUT, which it just takes a single clock cycle to perform (and very little fabric).

As always, all of these methods work best with a good helping of debouncing the inputs as previously discussed.

Peter House implemented another routine in Z80 assembler:

Here is a neat quadrature routine I wrote in Z80 assembler many years ago based on an article I read somewhere (maybe from you).  I have rewritten since in other languages and cannot seem to put my hand on them.

Have used this same logic with knobs and motors and works very well as long as it is called by interrupt or fast enough to not miss anything.  Can easily be implemented in c using a simple switch() statement.

; >>>>> Subroutine <<<<<
; RE_Quad
; Rotary Encoder Quadrature Calculation
; Called Periodically by Timer Interrupt or Hardware Change  Interrupt
; If Called every 8ms it works pretty well and will only  miss
;    VERY FAST rotations of the knob
;
; The Quadrature Output looks like this:
;    1|0 0 1 1|0 Phase A
;    1|1 0 0 1|1 Phase B
;
; There are only 4 possible current positions.
; Each Position has a two possible neighbor positions.   One of 
; these represents Up (CW) and One represents Down (CCW).
;
; If you take these four bits (two current position and 2  last position)
; it is very easy to make a Jump Table.
; 1101 CCW
; 1011 CCW
; 0010 CCW
; 0100 CCW
; 1110 CW
; 1000 CW
; 0001 CW
; 0111 CW
; Any other combination is not allowed and should be  ignored.
; 0000 No Move
; 0101 No Move
; 1010 No Move
; 1111 No Move
; 0011 Invalid
; 1001 Invalid
; 1100 Invalid

 
 
 

;
; The QuadLast should be initialized by the Init  routine.  If this is
;    not done then the initial knob position  can cause a false reading
;    of rotation.
         .DATA
; Stores the current Knob Position.  A positive number  indicates
; CW rotation and a negative Number indicates CCW rotation.
KnobPosition:
         .RMB    1
; The last position of the knob is stored in the lowest two  bits.
; Bits 2 and 3 hold old data which should be discarded.
QuadLast:
         .RMB    1
; Quadrature Routine Error Counter
QuadError:
         .RMB    1
         .CODE
; Routine Entry Point
RE_Quad:
; Prepare  QuadLast
         LD      A, (QuadLast)    ; Get it
         AND     A,  03h          ; Mask Off unused  bits
         SLA     A                ; Shift Left
         SLA     A                ; 
         LD      (QuadLast), A    ; Save It
; Get the Current  Position (bits 1 and 0)
         CALL    Get_Quad_Raw
; AND with  QuadLast
         AND     A,  03h          ; Mask Off Unused  bits
         LD      HL, QuadLast     ; Get Pointer  to QuadLast
         OR      A,  (HL)         ; Or with QuadLast
         LD      (QuadLast), A    ; Save for Next time
        ; Jump Table  Based on Last and Current bits
         CP      00001101b        ; CCW Rotation Detected
         JP      Z, QuadCCW
         CP      00001011b        ; CCW Rotation Detected
         JP      Z, QuadCCW
         CP      00000010b        ; CCW Rotation Detected
         JP      Z, QuadCCW
         CP      00000100b        ; CCW Rotation Detected
         JP      Z, QuadCCW
         CP      00001110b        ; CW Rotation Detected
         JP      Z, QuadCW
         CP      00001000b        ; CW Rotation Detected
         JP      Z, QuadCW
         CP      00000001b        ; CW Rotation Detected
         JP      Z, QuadCW
         CP      00000111b        ; CW Rotation Detected
         JP      Z, QuadCW
         CP      00000011         ; Invalid
         JP      Z, QuadErr
         CP      00001001         ; Invalid
         JP      Z, QuadErr
         CP      00001100         ;  Invalid
         JP      Z, QuadErr
         CP      00001110         ; Invalid
         JP      Z, QuadErr
; No movement if  Code Gets Here
         JP      PastQuad
; Error
QuadErr:
; Increment Error  Counter
         LD      A, (QuadError)
         DEC     A
         LD      (QuadError), A
         JP      PastQuad
; Clockwise Rotation
QuadCW:
         LD      A, (KnobPosition)
         DEC     A
         LD      (KnobPosition), A
         JP      PastQuad
; Counter Clockwise Rotation
QuadCCW:
         LD      A, (KnobPosition)
         INC     A
         LD      (KnobPosition), A
         JP      PastQuad
PastQuad:
          RET
CAD and Privacy

Stephen Phillips replied to an article in the last Muse about CAD and Privacy:

This was a problem I had with Protel (98SE). So I found an option to flat file the data. This removes a lot of the problem.

The real issue is the 'desire' by many EDA vendors to use a "magic" database for storage of the data.

A data base is great for the RIGHT use. However for the wrong use it is dangerous. Protel 98SE suffered from the use of a 'common' providers faulty RDMS system so they gave the tool user the option to flat file the data. This made the tool WORK immensely better (side affect I guess) and of course when it did crash (which was seldom when it used a flat file), it was easy to recover your files.

  • KiCAD (http://kicad-pcb.org/) is an open source tool for doing "EDA" stuff. It does several things that make security less of an issue.
  • No data base, it is almost all flat text files.
  • Although it does have a central repository for ones schematic capture symbols, PCB foot prints, and 3d models. These are not part of your design, period.  Their is no link, instead it creates a part cache and that part cache is part of your design. I would prefer they make it not a cache (because if you add items to the cache they can disappear if you don't use them immediately).
  • It's open source, seriously, it's maintained by some fairly (crazy) individuals who talk about what to 'fix' next.

The current version is 4.0.0 (new release as matter of fact on Nov 29, 2015).

It's NOT perfect nor do they claim it to be able to do cross stitch as well as RF signal analysis. (Joke really ... really.) They are working on the plugin system, still (much to my eternal ... where is the documentation for the plugin interface chagrin).

It does have some nice tools include creapage and clearance (electrical spacing)., track width and current, transmission line, RF attenuators, color code (thingy) and for those who are making cost effective boards it gives information for board classes and tolerances for the class so they can proper specify the class to the fabricator.

It's not the greatest tool, it DOES have a learning curve.

Fortunately you have freenode irc and #kicad if you have some questions. The tutorials are good enough. The interesting thing is by far it was the easiest EDA tool to start using. I just poked around for a bit and found myself making symbols for parts in about 3/4 of an hour. Things get more complicated as your begin to have a more complicated design, and the PCB <=> schematic conversion takes a bit getting use too.

However if you want to "hand" your design out, it's supported and open source. So the 'earning curve' of using it is not so bad (pun intensive).


Jobs!

Let me know if you’re hiring embedded engineers. No recruiters please, and I reserve the right to edit ads to fit the format and intents of this newsletter. Please keep it to 100 words. There is no charge for a job ad.

Joke For The Week

Note: These jokes are archived at www.ganssle.com/jokes.htm.

Vic Plichota sent in this which I ran last week:

There are two types of people in this world:

1 - those who can extrapolate from incomplete data,

Helmut Drobny suggested something similar:

2 - Those who can interpolate from no data

And Dave Hansen wrote:

Just a quick note to let you know your joke of the week reminded me of one of my favorite lines from a novel. 

The inimitable Vlad Taltos from Steven Brust's _Issola_ says something like, "I’m generalizing from one example, here, but everyone generalizes from one example. At least, I do."

Advertise With Us

Advertise in The Embedded Muse! Over 25,000 embedded developers get this twice-monthly publication. .

About The Embedded Muse

The Embedded Muse is Jack Ganssle's newsletter. Send complaints, comments, and contributions to me at jack@ganssle.com.

The Embedded Muse is supported by The Ganssle Group, whose mission is to help embedded folks get better products to market faster.