My Journey into CPLD Programming

One thing I never learned in school was FPGA/CPLD programming. I have done a lot of projects with programming microcontrollers and writing PC applications but never done anything with FPGAs or CPLDs. From my research knowing VHDL seems to be pretty in-demand right now so I think I am going to try to teach myself VHDL. A while back I bought a Xilinx Coolrunner II CPLD starter kit and I think I am going to pull it out and use it to learn VHDL. Once I get the hang of the language I think I will do a project with a CPLD, right now I am thinking a stepper motor controller would be a fun project but maybe I’ll think of something else. This is the dev kit I bought:

Currently I’m downloading the massive 5.9GB Xilinx development software will post more about my journey into VHDL as I get farther.

Andrew

PCB Buisness Card

Thought I would work on a new project over the Canada Day long weekend for a change of pace. I am going to make a PCB business card as something that I could show off at a job interview and things like that. I’ve decided to do a little circuit with the Microchip PIC10F208. This is a really neat little microcontroller; it comes in a tiny SOT23-6 package, with 0.75KB flash 24 Bytes of RAM, 1 x 8 Bit Timer, 1 Comparator. The best part is it’s cheap only $0.78 on Digikey for 1 chip. I could easily use a bigger microcontroller but sometimes it’s fun to have the challenge of a very limited microcontroller like this. If this goes well I might try doing more projects with it.

The Circuit

Microchip has a app note on how to do make a Capacitive touch button using two pins on it so I am going to try that and have the microcontroller blink a couple LEDs when it detects a touch. The circuit is very simple; the capacitive touch part is just a schottky diode, resistor and the capacitive sensing pad, a battery and two LEDs. The microcontroller pins can sink/source 25mA so I can easily drive an LED from these. I’m powering the whole thing with a 20mm coin cell battery since the mircocontroller is going to be sleeping most of the time so it should last a really long time.

Software

I haven’t programmed in assembly for a long time but the software should be real simple it will sleep most of the time and wake up one and a while to check the capacitive touch button like every 500ms or so and if it detects a touch it will blink the LEDs for a few seconds if it doesn’t detect a touch it will go back to sleep.

The PCB

Here’s a picture of the layout. It has the battery in the top right corner. The microcontroller/LED circuit in the top middle, the capacitive touch button on the bottom right, my name and contact info on the middle and a QR code leading back to my website on the bottom left. I am going to have it done with black silkscreen since I think that will look really nice and made with 0.8mm FR4 to make it a little thinner than normal and more business card like.I haven’t priced it all out but including the PCB the total BOM cost should come to around $7 which isn’t too bad most of the cost is from the connector batty and battery clip. I could use an SMT battery to save some cost but I would like it to be replaceable.

I’m going to send the Gerber files off to iTead Studio today and should hopefully get my PCBs back in a few weeks. Once I’ll blog about it once I get something up and running.

Schematic Here

Andrew

I Love LTSpice

A few weeks ago I went to a seminar put on by Arrow Electronics on Linear Tech’s free SPICE program LTSpice. This is an excellent program and the best part about it is the low, low price of $0. I had played with it a couple times in the past with simple circuits but this week at work I was working on designing a circuit and it came in extremely handy. There is s a bit of a learning curve to the program but the help in the program is well done and there are a lot of resources on the internet. The circuit I was simulating was fairly simple it’s a protection circuit with a couple transistors that turn’s off a P-FET when a voltage across a transistor gets too high. Some great features of the program are:

Simulating Circuits Over Different Temperatures
This circuit in particular had to operate over a wide temperature range of 0 to 85C. For analog circuits made out of discrete transistors this can have a huge impact since the Vbe of a bipolar transistor varies over temperature. These tests can be done on the actual circuit in an environment chamber and the simulation is not environment chamber replacement but you can quickly get a good idea if your circuit is going to work over this temperature range or not. It will also help give you the intuition about how temperature affects the circuit and will help you debug a circuit if you do find you have problems at high or low temperatures.

Testing to See How Noise or Transient Events Affect a Circuit
With the circuit I was working on I didn’t want it to be affected by short transient events such as Electrical Fast Transients (EFT) I was able to easily simulate a 4kV EFT being coupled onto my sense resistor and was able to tweak some values so that it was not triggered by the transient events.

Quickly Testing How Changing a Component Value Affects a Circuit
Want to see how changing R7 between 1K and 100K affects your circuits output. With one command you can have the simulation run with a list of different values and you can see how that affects the circuit.

AC Analysis of a Circuit
It is a great tool for analog filter or feedback circuit design since you can quickly do Bode plots for frequency response of the circuit

Calculating Power Dissipation in a Part
After running a simulation just Alt+Click on a part to have the power dissipation plot over the simulation time, this is great for seeing the switching power dissipation in a transistor. And then Ctrl-Click on the plot to integrate the plot and get the average and RMS power dissipation.

The program is not a perfect representation of you end circuit and is not a replacement for an understanding electronics or a replacement for calculations as some might use it, just because the circuit works in simulation doesn’t not guarantee that the circuit will work the exact same. Another limitation of the program is as your circuits get more complex the simulation times get huge event with my Quad core i5 processor I had a simulation that was going to take hours to complete. Even with some of it’s limitations it is a great tool for understanding how your circuit will react over many different operating points and fringe conditions

I am still learning the all the features of the program but it is an extremely powerful tool and should be in the tool kit of any electronics engineer.

LTSpice can be downloaded from Linear Tech’s website:
http://www.linear.com/designtools/software/#LTspice

Andrew

More Quadcopter Progress

I have been working on the quad copter some more and have made some more progress, although I sliced the tip of my finger open pretty good and broke one of the propellers in the process, but now the other axis id tuned fairly well. It doesn’t work as nice as the other axis right now though. It seems like one of the ESCs are stronger than the other, one of the motors runs significantly faster than the other as I mentioned in the previous post and I have narrowed it down to the ESC. Before I suspected it was the motor but swapped the two motors and the same side was stronger but after I swapped the ESCs the other motor was stronger. I have tried to calibrate out the difference to some success but it’d not perfect I may have to order a new ESC. Anyway here is a video of this axis working:

I still don’t have it flying though, I am going to have to work on that some more but that is enough for tonight.

Andrew

Quadcopter Progress

Well I have recived my new Lithium Polymer battery and have been working on my quadcopter some more. I have one axis tuned and working fairly well heres a cool Youtube video of it working:

Currently having a slight issue with the other axis, when I first turn on the PID loop one of the motors shoots off in one direction and then after a bit it gains control probably due to the integrator kicking in. I don’t think there is a software problem, since the code for the two axis are the same. I’m wondering if there are some tolerances in these motors which would cause one to be stronger than the other, maybe the Kv (motor velocity constant) of the motor is significantly different between the two.

Andrew

Need More Power

Well minor setback…

Looks like the quadcopter doesn’t have enough power to lift itself. I even cracked the motors to full power and it still flew like a lead balloon. I think I need to change the battery. I originally chose a LiFePO4 battery over a Lithium Polymer battery for safety reasons; the Lithium Polymer batteries have a tendency to catch on fire if treated improperly. I currently have a 3 series cell LiFePO4 battery I could go to a 4 series cell battery but that would significantly increase the weight. I think I am going to have to switch to a lithium polymer battery which has a higher voltage per cell and slightly less weight per cell.

So the project is on hold until I get a new battery in.

Quadcopter Feedback Loops

Wow it’s been a long time since I’ve posted anything here. I promise I have not abandoned this blog or my quadcopter and I am going to try to post more often…

Anyway recently I have been working on getting the feedback loops to control the pitch and roll angles of my quadcopter so it will fly straight. At this point it is stable with a step input although it does oscillate a bit so I probably could make some improvements.

Currently the step responses for my two PID loops look like this:

As you can see there is till a bit of oscillation but I do have both axis’ stable which is the first step. Some of the oscillation I think is die to the fact that the kalman filter cannot track fast movements very well so when the quadcopter is rotating fast there is an inherent lang in the output of the kalman filter. This may or may not be an issue in the quadcopter since these loops are just used to maintain a constant set-point and should never be moving very fast. If I do have problems I think I might be able to improve this by running the kalman filter and sensor sampling at a faster rate than the feedback loop. I might investigate that in the future.

Somethings I have learned in this exloration with implementing PID loops:

There are two was of implementing derivative action in a PID loop; error feedback and rate feedback. In error feedback you take the derivative of the error the same as the integral and proportional parts. With rate feedback you take the derivative of the output and add that to the error and the integral of the error. The advantage of this is you don’t have any effects from a changing setpoint so normally you have less overshoot.

Block diagram for PID feedback loop with derivative on the error
Block Diagram for PID feedback loop with derivative on the output

There is no worng choice between the two but I chose to use rate feedback in my quadcopter. One thing to note with rate feedback is you need a negative Kd or to subtract it from the Integral and Proportional parts else you get positive feedback and an unstable loop. That took me a while to figure out…

A couple important thing I learned about implementing the integrator. The first is to have some sort of anti-windup scheme implemented in your integration. I did it the easiest way by setting a saturation limit on the output of the integrator:

if(I_Value_Pitch >100)
I_Value_Pitch = 100;
else if(I_Value_Pitch<-100)
I_Value_Pitch = -100;

This way the output of the integrator will never go over 100. A wound up integrator can be very dangerous especially when dealing with propellers spinning at thousands of RPM.The second thing is to always reset the integrator when stopping and restarting the PID loop or it will quickly shoot off in one direction the moment you restart it.

Anyway with two stable PID loops next step see if I can get it to fly!

Andrew

 

Quadcopter Hardware Complete

Now the hardware for my Quadcopter and a good portion of the software is complete for the quadcopter. The hardware really consists of 4 parts: The controller board, the quadcopter XBee board, the USB XBee board and the quadcopter frame with motors and ESCs. The quadcopter XBee board plugs into the top of the quadcopter controller board which is then mounted on the frame. The next part is to get the control loop working and then i should have a working quadcopter.

Here are a few pictures of the hardware to date:

PCB Board Houses for Hobbyists

Back in high school I etched my own PCBs with copper clad board and Ferric Choloride acid. It was messy but it did the job. Nowadays it just isn’t worth making your own PCBs when you can get professionally made one for such a cheap price with silkscreen, solder mask and plated through holes which are difficult to do at home. There aren’t a ton pf PCB houses that cater to hobbyists but here are a few places I have used:

Batch PCB:

www.BatchPCB.com

Pricing:

$10 setup fee (shown as a handling charge) – $2.50 per square inch for 2 layer designs, $8.00/sq. in. for 4 layer designs.

Limits:

  • 2 or 4 layer boards – 0.062″ FR4 material
  • 2 Layer sizing:
    • 8mil (~0.2 mm) spacing minimum
    • 8mil (~0.2 mm) traces minimum
    • 20mil (~0.5 mm) minimum drill size
  • 4 Layer sizing:
    • 6mil (~0.15 mm) spacing minimum
    • 6mil (~0.15 mm) traces minimum
    • 13mil (~0.33 mm) minimum drill size
    • No blind/buried vias
  • 500mil (~12.7 mm) maximum drill size
  • All drill hits are plated through
  • No internal routes, no v-scoring, only drill files are sent to the fab house
  • Board is routed to the indicated border (very clean edges, you can get creative with the shape as well!)
  • Soldermask both sides
  • 1oz Copper
  • No limit on the number of vias
  • No limit on pads or components
  • Multiple designs, multiple copies are allowed!
  • Any size up to 10×15″, measured in inch increments (254mm x 381mm)
  • Minimum billable size 1×1″ (smaller boards are allowed but rounded up)
  • Your design can be any size – 1 inch is the minimum

Comments:

The pricing is very reasonable for small runs of boards and from my experience it would take about 3 weeks to get the boards I ordered. You can now pay extra to have your order expedited, I have not used this service but it would be helpful if you can’t wait 3 weeks to get your boards. I was very happy with the boards I have received from them plus they usually over deliver and you get twice the amount of boards you order at no extra cost. Here are a few of my boards I have had them manufacture.

IdeadStudio

www.IteadStudio.com

Pricing:

Green 2 Layer 5 cm x 5 cm, 10 Pcs starting at $9.90
Green 2 Layer 5 cm x 10 cm, 10 Pcs starting at $18.90
Green 2 Layer 10 cm x 10 cm, 10 Pcs starting at $24.90

Add $10 for different coloured solder mask

Limits:

  • Multi Layers: 1-2
  • PCB Material: FR-4
  • Minimum Qty: 10
  • Maximum Size: 50mm X 50mm
  • Board Thickness: 1.6mm
  • Thickness Tolerance (t≥0.8mm): ± 10%
  • Thickness Tolerance (t<0.8mm): ± 10%
  • Insulation Layer Thickness: 0.075mm–5.00mm
  • Minimum Line: 6mil (Recommend >8mil)
  • Minimum Space: 6mil (Recommend >8mil)
  • Out Layer Copper Thickness: 1oz(35um)
  • Inner Layer Copper Thickness: 17um—100um
  • Drilling Hole (Mechanical): 0.3mm—6.35mm
  • Finish Hole (Mechanical): 0.3mm—6.30mm
  • Diameter Tolerance (Mechanical): 0.08mm
  • Registration (Mechanical): 0.09mm
  • Aspect Ratio: 8:1
  • Solder Mask Type: Photosensitive ink
  • SMT min Solder Mask Width: 0.1mm
  • Min Solder Mask Clearance: 0.1mm
  • Plug Hole Diameter: 0.25—0.60mm
  • Surface Finish: HASL

Comments:

IteadStudio’s pricing blows Batch PCBs Pricing out of the water where you can get 10 PCBs 5 cm x 5 cm for $9.90 at that price there is no reason anyone should make their own PCBs anymore. I just ordered some PCBs from Itead, the process was smooth and the PCBs arrived in 2 weeks which is great and a week faster than BatchPCB. I havent noticed any flaws in the PCBs from Itead though they were a very simple design. If there is any con I can find with Itead it is that I like the shade of green solder mask that BatchPCB used better but for the price I can look past that. Here are some pictures of the board I had Itead manufacture.

 

HP 54200D Oscilloscope Teardown

A few years ago I bought an HP 54200D 50Mhz Digital Oscilloscope but what I didn’t realize is that Digital oscilloscopes of the 80’s were very primitive and did not compare to the Analog scopes of those day. I’ve used the oscilloscope a few times but with the small sample memory, slow sample rate and slow waveform update rate the scope is not that useful. So I decided to take it apart and see what’s inside.

Sorry for the poor quality I need to get a better camera but there still are some cool pictures. Anyway here is some sexy old school electronics.

[flickr-gallery mode=”photoset” photoset=”72157628367143665″]

The build quality of the oscilloscope was amazing they certainly don’t make them like they used to. I can’t let it all go to waste I think I’m going to hang the PCBs on the wall by my work bench.

Andrew