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? 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!