American library books ยป Other ยป Make: Electronics by Charles Platt (read me a book .TXT) ๐Ÿ“•

Read book online ยซMake: Electronics by Charles Platt (read me a book .TXT) ๐Ÿ“•ยป.   Author   -   Charles Platt



1 ... 113 114 115 116 117 118 119 120 121 122
Go to page:
you might wonder whether you could use just the one chip to control both motors in response to inputs from two sensors. The problem is that the three output pins on the 08M also function as the three ADC input pins. Youโ€™d do better to buy one of the more advanced PICAXE chips, such as the 18M, which has more pins to choose from. It uses the same basic set of programming instructions, and doesnโ€™t cost much more money.

Also, you should read the PICAXE documentation and look up the โ€œpwmoutโ€ command, which is short for โ€œpulse-width modulation output,โ€ but you can think of as meaning โ€œpower motor output.โ€ This is specifically intended to run stepper motors. It establishes an output frequency of pulses that will continue while the chip obeys other instructions in its program.

Fundamentals

Extra features

A complete guide to the 08M would fill a book of its own, and of course such books already exist (just search the books section of Amazon.com for keyword โ€œpicaxeโ€). But Iโ€™ll finish my introduction to the controller by listing some of its extra capabilities, leaving you to look them up and explore them. Then Iโ€™m going to suggest one last experiment.

Interrupts

The PICAXE 08M allows you to set one โ€œinterrupt.โ€ This feature tells the chip to make a mental note that if a particular event occursโ€”such as a switch applying voltage to one pinโ€”it should stop doing whatever else it was doing, and respond to the interruption.

Infrared

One pin on the PICAXE 08M can be used to receive infrared signals from a TV-style remote that you can buy from the same suppliers that sell the PICAXE itself. With an infrared sensor attached to the chip, you can issue commands remotely. If you want to build a remote-controlled robot, the chip is specifically designed with this in mind.

Servo motors

Every PICAXE chip has at least one pin that can send a stream of pulses to control a typical servo motor. On the 08M chip, itโ€™s Logic Pin 2. The width of each pulse tells the motor how far to rotate from its center position before stopping. A 555 timer can send this stream, but the PICAXE makes it easier. You can search online for more information about servo motors, which are especially useful for applications such as steering model vehicles, adjusting the flaps on model airplanes, and actuating robots.

Music

The PICAXE has an onboard tone generator that can be programmed with a โ€œtuneโ€ command to play tunes that you write using a simple code.

Alphanumeric input/output

The โ€œkbinโ€ programming command is available in the PICAXE models 20X2, 28X1 and 28X2, and 40X1 and 40X2. You can plug a standard computer keyboard into the chip, and it will read the keypresses. You can also attach alphanumeric displays, but these procedures are nontrivial. For instance, when youโ€™re trying to figure out which key someone has pressed on a keyboard, your program has to contain a list of the special hexadecimal codes that the keyboard creates.

Pseudorandom number generation

All PICAXE models can generate pseudorandom numbers using a built-in algorithm. If you initialize the number generator by asking the user to press a button, and you measure the arbitrary time that this takes, you can seed the pseudorandom number generator with the result, and the pseudorandom number generator will have a less repeatable sequence.

Visit http://www.rev-ed.co.uk/docs/picaxe_manual1.pdf to learn more.

Experiment 36: The Lock, Revisited

The combination lock that I described in Experiment 20 is especially appropriate 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.

1 ... 113 114 115 116 117 118 119 120 121 122
Go to page:

Free e-book: ยซMake: Electronics by Charles Platt (read me a book .TXT) ๐Ÿ“•ยป   -   read online now on website american library books (americanlibrarybooks.com)

Comments (0)

There are no comments yet. You can be the first!
Add a comment