Assuming you haven't read the introduction to this project, go to the intro blog:
Assuming that you have read the intro above, let's talk about the hardware. To begin with, I'm not going to explain every piece of hardware on the board. We have already chosen the PIC12F615 as the microprocessor, now we need to get on with the rest of it.
The challenge of this portion of the hardware is the user interface. Here is what the hardware must be able to do:
1) The analog signal from each button must be different enough from the others that the 12F615 will be able to tell the difference between each button.
2) There needs to be a way to ensure that varying levels in VDD don't cause the software to misinterpret what button was entered by the user.
3) The hardware must be able to create a digital interrupt on each button press.
To address the first topic, let's consider the voltage between each button. To maximize the difference between each button, let's simply divide Vin by 6 (the number of buttons). We can use this to determine the largest possible voltage gap between each button. However, for this circuit, I had to eventually divide by 8. If I hadn't, the last button wouldn't work correctly. It will be easier to demonstrate what I mean by simply showing you my simulations.
Before I can do that, we first need to discuss the second issue. How do we handle a variable VDD? Or why is this even important?
The reason that knowing VDD is important is because the upper and lower ranges for each button will depend on the level of VDD. This is more easily explained using a table of values showing the voltages on each button for varying input voltages:
VDD (V) | Vb1 (V) | Vb2 (V) | Vb3 (V) | Vb4 (V) | Vb5 (V) | Vb6 (V) |
---|---|---|---|---|---|---|
5 | 5 | 4.375 | 3.75 | 3.125 | 2.5 | 1.875 |
4.5 | 4.5 | 3.9375 | 3.375 | 2.8125 | 2.25 | 1.6875 |
4 | 4 | 3.5 | 3 | 2.5 | 2 | 1.5 |
3.5 | 3.5 | 3.0625 | 2.625 | 2.1875 | 1.75 | 1.3125 |
3 | 3 | 2.625 | 2.25 | 1.875 | 1.5 | 1.125 |
2.5 | 2.5 | 2.1875 | 1.875 | 1.5625 | 1.25 | 0.9375 |
2 | 2 | 1.75 | 1.5 | 1.25 | 1 | 0.75 |
*Formula: | VDD*(8-(bn-1))/8, where bn is the button number <1:6> |
Table 1: Button Voltages based on VDD
Looking at the table, it is obvious that the varying VDD can cause some potential hiccups, as different buttons can take on the same voltage value. For example, look at Vb1 and Vb2 when VDD is 4V and 3.5V. They are the same! Our software is not going to know what VDD is, so we need to develop a software/hardware solution to get around this issue.
Here is how we get around this: We first put a voltage divider on the ADC pin. Even better: Let's set the voltage divider up to equal the voltage gap between each button! This will save us some serious heartache later when it comes to the software. For those who aren't familiar with what a voltage divider is, it's based around Ohm's law. Here are a couple of tutorials I found online from Sparkfun and Wikipedia. You can easily find more by doing a quick Google search. I know that the gap I am using is VDD/8. So I want to simulate my circuit in LTSpice, and find what resistor values I need to find that ratio. I will explain more in the software portion of this blog on why this is so helpful.
Here is the circuit I built in LTSpice:
Figure 1: Voltage Divider Circuit
Now, let's take a look at the plot of Vin vs VAnalog:
Figure 2: Plot of VAnalog/Vin
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
Now, we want to find the slope of each line. Actually, the goal is to find the line with slope that is closest to the value of 1/8 or 0.125. We can do this by double clicking on VAnalog and moving the cursors that show up to opposite ends of the plot that is selected. We can move between plots by using the up and down arrow on each end. Here is what it will look like (I've selected the top most plot):
Figure 3: Slope of VAnalog/Vin = 0.13117
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
If it isn't immediately obvious, each of the individual plots in the figure above correlates to a value in {R1} from the circuit shown in FIgure 1. The top plot (the one that is selected) correlates with {R1} = 5kΩ. As you can see, the slope of this line is more than 0.125, the value we are looking for. After a little more looking, I found that 4.7kΩ was the value I was looking for, and yielded a slope of 0.12484. The error between the desired slope, 0.125, and the slope I found, 0.12484, is 0.13%. I would say that is an acceptable error! One thing to note: I selected the 33kΩ at random, you could probably choose any value you like, within reason. You would want to consider how much power the voltage divider is using, as it will be acting as a constant drain on the power source.
Now that we figured out the voltage divider, we need to determine the resistors we are going to use on the buttons. The trick to this is to remember that each button is going to be it's own individual voltage divider, and that the resistance going into button n must include the resistance going into button 1 to button (n-1). To understand what I mean, let's get a look at the button portion of the circuit:
Figure 4: 6-Button Interface
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
Notice how R13 and R14 create a voltage divider of their own when none of the buttons are pressed down. Also notice how all the resistors are in series, so that each button has a different input resistance, that is totaled up by all the the resistors in front of it. To simulate the different values of the resistors, I will still use the circuit shown in fig. 1. What I will do is continue to vary {Vin}, but will set Rground to 4.7kΩ, and set Rbutton to {R1}. Then we will find what resistor value matches up with Vin*(9-bn)/8 by using the plot tool as well. I've shown an example of this below in the next 3 figures.
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
Figure 5: Simulator Circuit
Figure 6: Plot of VAnalog vs {R1}
Figure 7: Plot VAnalog vs {R1} with cursor
Here is what we are looking at: the lower resister value is 55.0368 when the input voltage is (2*7/8)V (Button 2), and gives an output voltage of 1.75001V. You are going to want to get the resistor information for each different voltage input for button 2 (Vin*7/8). Then do the same for button 3 (Vin*6/8), and so on, down to button 6 (Vin*3/8). After I had all the values, I found the average resistor value for each button over the {Vin} range. Here is what I wound up with:
Button 1: Total input resistance = 0
Individual input resistor = 0
Button 2: Total input resistance = 39Ω
Individual input resistor = 39Ω
Button 3: Total input resistance = 95Ω
Individual input resistor = 56Ω
Button 4: Total input resistance = 185Ω
Individual input resistor = 90Ω
Button 5: Total input resistance = 353Ω
Individual input resistor = 168Ω
Button 6: Total input resistance = 777Ω
Individual input resistor = 424Ω
Note: I only used 3 - 5.25 volts for the range of my {Vin}. The reason for tracking the total input resistance is to allow us to simulate the circuit with the correct input resistances. This time, we are going to check to make sure that the digital interrupt input is triggered correctly. I altered the parameter sweep for {R1} to match my input resistances of {R1}. I don't need particular values for this next simulation. I am checking to make sure that the switch stays on for all the resistor values we are using. I also need to check to make sure that the switch is off when no buttons are being pressed.
Figure 8: Simulator Circuit
Figure 9: Plot of Plot of VAnalog vs {R1} (Button Pressed}
Figure 10: Plot of Plot of VAnalog vs {R1} (No button pressed}
As we can see, when all the buttons are open (meaning none of them are pressed down), then {R1} →∞, which we can see means that the switch is open, and the input on the INT pin is low. Exactly what we want!
In the next blog, I will go over the hardware set up and testing it. Just because the simulator says everything works, doesn't mean that everything is going to work the way we expect. There could be settings that I didn't adjust to match the characteristics of the devices I am using.