Sunday, 27 January 2013

Display and Control Section for AD9835 project

Now that the power supply and filter section for the function generator have been designed and realised it is time to concentrate on the control section.  We need a way of controlling the signal generator.  Lets discuss buttons!  We need buttons on the front panel for:

Select Sine Wave output
Select Square Wave output
Select Pulse Output
Turn the output On / Off
Select frequency
Select Amplitude
Select times 1 multiplier (units)
Select times 1000 multiplier (kilo)
Select times 1000000 multiplier (Mega)
Select increment (more)
Select decrement (less)

That is a lot of buttons!  We could use a keypad but I don't think it's really necessary in this particular situation.  What we need to keep in mind are the digital pin requirements for the microcontroller (arduino).  We have 12 digital pins available as standard and another 6 more if we use the analogue pins as digital pins which gives a maximum of 18 pins available to control the AD9835 breakout PCB, the 16x2 LCD display, the rotary encoder and all of the above buttons!  (I'm not including the RX and TX serial control pins)  See the table below:

Device Total Number of pins Number of arduino pins required
     
16x2 LCD Display 16 6
AD9835 breakout 8 6
Sine Button 4 1
Square Button 4 1
Pulse Button 4 1
units 4 1
thousands 4 1
millions 4 1
up 4 1
down 4 1
enter 4 1
frequency 4 1
amplitude 4 1
output 4 1
rotary encoder 5 3
     
Total   27

Hmm....27 digital pins needed and only 18 available!  What are we going to do?  Well...it all depends on how we would like to approach the problem.  We could remove some of the buttons and lose some of the less necessary control features.  We could remove the LCD display and control the device via the serial terminal.  We don't need a rotary encoder, we can use a potentiometer and then we have saved ourselves considerable pin requirements.  Personally I don't like this idea....losing all of those things will make our function generator very hard to use....In my experience people hate electronic devices that are hard to use!  If it doesn't make your life easy or there is something better on the market then people will avoid your product, buy someone else's or moan bitterly!  I know it doesn't matter as nobody will be buying this signal generator but it's always a good idea to keep in mind what other people think and do...that way when you are designing a commercial product you will consider all of the relevant design criteria.

Ok, so we are going to keep all of the above functionality and somehow get 27 digital arduino pins from 17.  To quote one of my favourite TV Characters (Balldrick from the Blackadder comedies) "Don't worry, I have a cunning plan!...."  We are going to invest in some multiplexing.  For the driving of the LCD display we are going to use a serial to parallel shift register - the venerable but always useful 74LS595!  I have posted about this device before.  It's very useful and in this case I'm going to use it to control the LCD in a 3 wire mode.  This means I have reduced our pin count by three pins.  Hey every little helps!

Next I'm going to invest in a parallel to serial shift register.  There are plenty to choose from but I have decided to stick with TTL (5V) logic and use the SN74HC165 - from Texas Instruments.


Sparkfun Electronics also handily sell a a breakout PCB for $3.95!  Not bad, the link is below:


This device takes 8 digital inputs and converts these inputs into serial data on 3 pins and then passes them to the microcontroller.  We then write some processing software which reads this serial data and use it for our own nefarious purposes!  I'm not going to use the breakout PCB although I could do.  I'm going to design a PCB for adding both inputs and outputs to the arduino and combine the 74HC595 and 74HC165 on one PCB.  I'm then going to use that PCB connected to the arduino to control the LCD display and buttons.  This adds another 16 inputs to our system but removes 3 therefore we now have 12 original arduino pins available and 16 dedicated outputs and 16 dedicated inputs.  This should be more than enough for the signal generator....the downside is it makes coding the control firmware on the microcontroller more difficult.     

There is a quicker and possibly cheaper alternative to all of this extra work....use an Arduino mega!  This is a different microcontroller and development board which has 52 digital inputs / outputs and has all the other requirements we need.  The only reason I'm not using one is because in this case I think its better to learn something rather than cheat and just use a bigger microcontroller...If anyone wants to use an arduino mega for their projects that also fine!

Here is the schematic for my I/O expander circuit - it could be used for many different application, not just for this project.  I also believe with some programming this PCB could be used with the Raspberry PI to add more GPIO pins.  


  The circuit basically takes the information given in the integrated circuit datasheets and applies this information to the arduino uno.  Serial data, clock and latch are provided for each device respectively.  With this circuitry we have added 16 digital outputs with the 74HC595 section and 16 inputs from the 74HC165 section.  In order to 'drive' each of these sections 6 digital pins will be required from the arduino.  6 digital I/O pins from 18 leaves 12 digital I/O pins left which should be more than enough for our requirements!

Here is the PCB layout.  If I'm honest this was a really hard circuit to lay out single sided.  I would have preferred to go dual layer however I can't fabricate this in my work shop.  I could get PCBS professionally made but I'm impatient.


Well....that's all for now, I'm going to build and test this PCB in the next few days and then I'll update the circuit to show how I'm going to use this PCB to drive the LCD display for the AD9835 signal generator.  Until then....Take care folks - Langster!





    

Tuesday, 22 January 2013

Power supply for function generator

Over the course of developing and testing the function generator I have needed a dual polarity power supply.  I have been using a bench power supply that I made some time ago.  It has two variable voltage outputs and I am linking the +ve terminal of one supply to the 0V of the other supply to create a dual +/- supply.  This is fine but I also needed a way of powering the arduino uno that I am using to control the AD9835 function generator PCB.  During the course of my testing in a massive 'ooops' moment, I managed to wire up something incorrectly and destroyed my arduino uno!  This is to be avoided obviously and I only have myself to blame!

Note to self....when testing or developing a project ensure that connecting power to the device under test is as simple and stress free as possible. A random mass of different coloured wires is Not acceptable!

Further note to self....ensure that the power supply you are using cannot supply too much voltage or current to the device under test!  This way no magic smoke or expensive and unnecessary catastrophic failures will be observed!

To stop this happening I have designed a power supply which meets all of these requirements and ensures that this shouldn't happen again - I am of course assuming that I won't make a similar mistake again and that is a significant assumption!  I often make mistakes....

The power supply is a linear power supply with the following features:

Take an input of 230V 50Hz AC (British AC line voltage)

and provide the following output:

+12V output with at least 500mA to power the op-amp filter and amplifier section
-12V output with at least 500mA to power the op-amp filter and amplifier section

+9V output with at least 500mA to power the arduino and display and control section - I know I could have used 5V here but I wanted to use slightly greater than 5V so that I am correctly powering the on board linear regulator already present on an arduino.  I'm going to use the 5V output for everything else.

With the power and functional specifications sorted I had a look at which parts I had available.    I didn't have any switching regulator devices handy and I didn't want to introduce more switching noise into my circuit.  I haven't made many switch-mode power supplies and didn't want to use this topology of power supply.   I did have plenty of linear regulators including a LM7809 and a LM7812 for positive voltage regulation and a LM7912 for negative voltage regulation.

Here are the datasheets for those devices:

Fairchild version of 78XX positive linear regulator datasheet

Fairchild version of 79XX negative linear regulator datasheet

I have been through the design and implementation of a linear power supply in previous blog posts so I'm not going to repeat myself again.  If people are interested please look at the posts concerning power supplies for how to design linear power supplies.

Here is the schematic diagram:

Linear Dual Power supply for function generator

Here is the PCB layout top and bottom layers:



The circuit is pretty classical in terms of design.  It uses a linear transformer to step down 230V AC to 15V AC.  The 15V AC is then sent to a bridge rectifier which converts the AC voltage into a postive and negative DC voltage.  These DC voltages are then smoothed with two large 2200uF electrolytic capacitors.  Next the voltages are passed through two different coloured LEDS with current limiting resistors - I added the LEDS to show that power was present, they aren't strictly necessary.  Next the positive and negative DC voltages are passed to the respective linear regulators, 7809 (arduino power), 7812 (+12V op amp power) and 7912 (-12V op amp power).

Once I had simulated the circuit to make sure it worked and I hadn't made any stupid mistakes I transferred the designed to a single sided PCB and chemically etched the circuit layout using ferric chloride.  Here is how it turned out:

Top side of the PCB


And finally the PSU running - no load!  I love blue LEDS!

Well...that is about it folks!  The next job will be to design the interface electronics for the signal generator - LCD display and buttons to control the signal generator.  Take care - Langster!