for a microcontroller, because it requires a series of operations that resemble a computer program. I’m going to show how this project can be redesigned using a PICAXE 08M, and then leave it to you to consider how some of the other projects in this book could be converted.
You will need:
• The same type of keypad and relay recommended in Experiment 20.
• A transistor or Darlington array to amplify the output from the PICAXE so that it can drive the relay.
Getting the User Input
Any of the input pins on the PICAXE can sense a switch closing. The trouble is that we only have three pins capable of doing this, and even the most advanced PICAXE chip has fewer than 10 such pins. So how can we attach a 10- key keypad to the 08M?
I have a suggestion: attach various resistors to the keypad, so that each key
applies a different voltage to one of the ADC pins. Then use the ADC feature to
convert the voltage to a number, and use a table of possible numbers to figure
out which key is being pressed. This may not be the most elegant solution, but
it works!
The keypad can be wired as shown in Figure 5-147. The asterisk key is still being used to supply power, as in the original experiment, while the pound key resets the relay at the end of your computing session, as before.
Current flows through a series of resistors, beginning with one that has a value of 500Ω. Because this is not a standard value, you will either have to make it by combining other resistors in series, or by presetting a trimmer potentiometer.
After that, each button is separated from the next button by a 100Ω resistor. Finally, at the end of the chain, a 600Ω resistor separates the last button from the negative side of the power supply. Again, this is not a standard value, and you may have to use a trimmer.
Add up all the resistances and you have 2K, which is the range that the PICAXE wants us to use. When you press a button, you tap into the chain of resistances. Button 9 puts 600Ω between the PICAXE ADC pin and ground. Button 6 is 700Ω, button 3 is 800Ω, and so on. (You may prefer to lay out the buttons so that the resistance progresses in a more logical fashion. That’s up to you. I chose to lay them out in the way that would be easiest to visualize on a keypad.)
Now look back at the ADC values that I supplied in the table on page 308. These are the values that you should get when you press various keypad buttons— but you cannot count on them being absolutely precise, because they may vary if your resistor values are not quite accurate, or if your power supply isn’t exactly 5 volts. It’s not safe to say, for example, that the PICAXE will deliver an ADC conversion value of precisely 77 when the resistance is 600Ω. It’s safer to
Comment faire comment fabrique comment creer
You will need:
• The same type of keypad and relay recommended in Experiment 20.
• A transistor or Darlington array to amplify the output from the PICAXE so that it can drive the relay.
Getting the User Input
Any of the input pins on the PICAXE can sense a switch closing. The trouble is that we only have three pins capable of doing this, and even the most advanced PICAXE chip has fewer than 10 such pins. So how can we attach a 10- key keypad to the 08M?
I have a suggestion: attach various resistors to the keypad, so that each key
applies a different voltage to one of the ADC pins. Then use the ADC feature to
convert the voltage to a number, and use a table of possible numbers to figure
out which key is being pressed. This may not be the most elegant solution, but
it works!
The keypad can be wired as shown in Figure 5-147. The asterisk key is still being used to supply power, as in the original experiment, while the pound key resets the relay at the end of your computing session, as before.
Current flows through a series of resistors, beginning with one that has a value of 500Ω. Because this is not a standard value, you will either have to make it by combining other resistors in series, or by presetting a trimmer potentiometer.
After that, each button is separated from the next button by a 100Ω resistor. Finally, at the end of the chain, a 600Ω resistor separates the last button from the negative side of the power supply. Again, this is not a standard value, and you may have to use a trimmer.
Add up all the resistances and you have 2K, which is the range that the PICAXE wants us to use. When you press a button, you tap into the chain of resistances. Button 9 puts 600Ω between the PICAXE ADC pin and ground. Button 6 is 700Ω, button 3 is 800Ω, and so on. (You may prefer to lay out the buttons so that the resistance progresses in a more logical fashion. That’s up to you. I chose to lay them out in the way that would be easiest to visualize on a keypad.)
Now look back at the ADC values that I supplied in the table on page 308. These are the values that you should get when you press various keypad buttons— but you cannot count on them being absolutely precise, because they may vary if your resistor values are not quite accurate, or if your power supply isn’t exactly 5 volts. It’s not safe to say, for example, that the PICAXE will deliver an ADC conversion value of precisely 77 when the resistance is 600Ω. It’s safer to
Comment faire comment fabrique comment creer
No comments:
Post a Comment