Make Electronics

(nextflipdebug2) #1
What Next? 309

Experiment 35: Checking the Real World

Notice what’s happening here. First we get a value in b0, and then on the next
line, we do some arithmetic with it. The asterisk means “multiply.” So the state-
ment says, “Take whatever value is in b0, multiply by 5, and transfer it to an-
other variable, w1.” We have to use a w variable, because when we multiply the
value of b0 by 5, we may get a number that is bigger than 255—too big to fit
into a byte variable.


Finally, we take variable w1 and use it with a “pause” statement instead of a
fixed number value. We’re saying to the PICAXE, “pause for whatever number
of microseconds you get by checking the value of w1.”


So the software checks a variable resistance, turns it into a number, and ap-
plies that number to adjust the flashing speed of the LED.


Think back to the need of the cart powered by stepper motors. It was supposed
to check two photoresistors, and adjust the speed of each motor accordingly.
Well, this PICAXE program is a step in that direction. It can measure voltage on
a pin and change the output frequency on another pin. If you had two PICAXE
chips, you could wire each of them to a photoresistor and a motor. Then you
could adjust the behavior of your cart by editing the second line in the pro-
gram, where it converts the value of b0 to the value of w1 which will be used in
the “pause” command to determine the number of pulses per second. Instead
of multiplying by 5 you could multiply by 7 or whatever number gives you the
result you need. This leads to an important conclusion: a big advantage of a
programmable chip is that you can make adjustments in software.


Because the PICAXE 08M actually has more than one ADC input, and has three
pins that can be used for output, you might wonder whether you could use
just the one chip to control both motors in response to inputs from two sen-
sors. 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.

Free download pdf