Thursday, August 1, 2013

Freelance Work: The Rotary Switch Implementation

So the first job that I have been paid for was to replace a header+jumper combo used to select 1 of 10 options with a rotary switch+microcontroller board.  I think this is best explained with pictures, and in chronological order of how the design when, coupled with the design changes.  I should also mention that the client was from China, so there was a significant language barrier.

First, I when I saw the project on one of the websites I use to find jobs and interesting project ideas, it didn't look to too difficult.  The client wanted someone with experience in microcontrollers to replace simple jumper system system with a rotary switch.

Here is the picture of the board that he sent me:

 Figure 1: First Picture from client

As you can see, there is a top row and bottom row, and the bottom row pin is connected to the top row pin using a jumper.  The rotary switch that the gentleman wanted me to was a 6-pin DIP package.  Here is the information he sent me regarding the rotary switch:

 
Figure 2: The rotary switch

Figure 3: The pin-out for each position (red is connected, black is disconnected)

As you can see, the switch outputs whatever the signal is on the middle two pins (note the output on 0, where none of the corners are connected), and outputs in a binary manner:

Bit 0: Upper left corner
Bit 1: Lower right corner
Bit 2: Upper right corner
Bit 3: Lower left corner

This is where I learned my first lesson as a freelancer.  Get as much information as possible in the beginning.  Especially if you are doing design work that is going to attach to another person's work! I made a couple of bad assumptions here:
  1. The top row was the output row.
  2. The bottom row was all tied high, with a digital "1".
  3. All I needed to do was output a digital "1" or "0" to each pin on my header, and I was set!
Then I did something worse.  I designed a board around those assumptions.  Here is the first board design:

 Figure 4: Initial board design

There are some obvious and and not so obvious issues here.
  1. The capacitors are obviously too large.  This board is not going to be handling large signals, and any 0.1µF caps do not need to be large.  
  2. Some of the the traces are meeting at 90 degree angles, and that is something you want to avoid.  I read this in a great tutorial for designing PCBs (even if it was written eons ago).  Here is the link, in case anyone is interested: PCB Design Tutorial.  
  3. And in general, I am not all that pleased with the aesthetics of the board.  The board isn't as compact as it could be, and I could have done a better job.
  4. I didn't connect all the header pins.
So I am obviously going to rework the board.  I am also suspicious of the need for a microcontroller when I am pretty sure that there are binary to decimal decoders out there.  I did some snooping around, and what did I find?  This: Binary to Decimal Decoder.  This IC would take the binary value, and output a digital "1" on the corresponding pin.  For example: if the input was "1", then output 1 would be "1" and the rest are 0.  This would remove the need to have any programming done, and remove some of the peripherals he needed for the board.  The part cost $1.11 on Mouser.  I told him about the part, but he said he would really rather using the PIC16F876A because he had it on hand already.  At this point, I'm not sure if I should have told him to go with what I was suggesting, but since this was a really easy program to write, I wasn't too worried about it.

Before any redesigning was done, he wanted to iron out a price.  At this point, because I thought the project was essentially complete, I told him what I would be willing to do the project for, and we settled for a flat price, instead of an hourly wage.  I think that for the amount of work that went into this, I should have told him a flat price, and then charged by the hour for redesigns or charged him  the same price for major changes.  The reasons for this will become evident.

At this point, I began to wonder what the rest of the board looked like.  What if each of the bottom row of the header wasn't a digital logic, but was analog instead?  That would mean that the board I designed earlier wouldn't work!  So I wanted to get him to clarify some issues:
  1.  How is he going to program this chip?  
  2. Do I need to leave some headers open for his programmer?
  3. Can he send me more pictures of the board that mine will connect to, so I can get a better understanding of what he needs done?
He told me he was using this programmer, and that all he needed to program the chip was the hex file from what I did in MPLAB X (he didn't know what MPLAB X was, but said that all he needed was the hex file).  This meant that I didn't need to leave any programming input headers on the board.

He never responded to my questions about seeing the rest of his board.  But he did toss in another parameter for the board: it had to be 4.5 x 5 cm, at the largest.  So that meant I had to resize the board.  He also asked that for surface mount parts (not including the PIC, rotary switch or headers, obviously).

At this point, we discussed some other finer details about the peripherals on the board.  It was interesting that in China, if the client was any indication, they don't say 0.1µF, they say 100 nF.  It was here that we ran into the issue that I knew was coming.  He didn't understand why it was that I was using a single row header, when his board had a dual row header.  He kept asking me where the signal came in.  I initially thought he was asking where the power came in.  After I explained where that came into the board at, he said that isn't what he meant.  That is when he sent this:

 Figure 5: Bottom of the board, part 1

 Figure 6: Bottom of the board, part 2

Figure 7: Bottom of the board, part 3

Figure 8: Bottom of the board, part 4

Well.  Now I know that these are analog signals on the top row, and the jumper connects top row to the bottom row.  This means that I have to do a complete redesign of the board.  And add more parts to it.  And make the board fit his specified dimensions.  I've also done more snooping into the PIC he wants to use, and found out that there is no internal RC oscillator on board, so I have to provide an external clock source.  For that, I just used an external RC oscillator. There was no real need for specific frequency for this project, and anything between 4-8 Mhz would work fine.

So I redesigned the board.  At this point, the hours I had put into this project were not directly worth the money he paid me.  The amount of experience I was gaining made this project more than worthless.  I was working with my first client!  

Before I did the redesign, I asked him to send me a picture of how he wanted my board to connect to his board, and this is what he sent:

 Figure 9: The rotary switch
 Figure 10: The rotary switch (again)
 Figure 11: The board connection
 Figure 12: The board connection (again)

So, now I have what I need, and I design the final board:

 Figure 12: Eagle PCB
 Figure 13: SketchUp rendering of the top
 Figure 14: SketchUp rendering of the bottom
Figure 15: SketchUp rendering of board, after it is populated

As you can see, the board has drastically changed from the initial design.  Of course, after I send this to him, he tells me he is going to make this at home.  I am not actually sure that he is going to be able to do this, and I tell him that.  I designed this board around the assumption that he was going to have a PCB manufacturer build the board, so I didn't worry about making the traces wide enough for a  home built board.  And after having built a number of boards at home, I know that is critical for a successful DIY PCB.

The code part of this project was really easy, and not really worth delving into.

Edit: Final Product, p2.
After a couple of weeks, the gentleman I was working with asked me to contact his partner about some board design changes.  They decided that they wanted to put my board and the board together onto a single PCB.  This led to some back and forth for an evening over Skype, because they didn't have the schematics for their board.  So I had to look at pictures they had sent me previously, and come up with the schematics.  After doing this, and rearranging the final PCB to their liking, I wound up with a finished product, and the pictures are below.

Figure 16: PCB in Eagle
 

Figure 17: SketchUp rendering of the top
 

Figure 18: SketchUp rendering of the bottom

 
Figure 19: Sketch rendering of the board, after it is populated

Thanks for reading!
George










No comments:

Post a Comment