PICAXE as a selection controller
Basically I wanted THIS:

A knob that you could turn and select a waveform. Ive previously just played around with CMOS squarewave sound sources. In a previous experiement, I found that the NAND works as a great gate for squarewaves.
The easiest way I could find to convert a pot value to a discrete value was using the LM339. Basically you have a series of comparators. You need to set up a resistive network so that you have values that you compare against.
Pretty neat. Its basically the lightbar graph. Not overly complicated, but it can be simplified using the PICAXE.
Instead of building the resistor network, you can use the READADC command on the PICAXE.
The circuit looks like this:
The first piece of code simulates the circuit I was trying to build in the first place. The Light bar circuit. Now the PICAXE is too slow to do a really smooth light bar, but it does read a pot fast enough for a good reading.
The code is as follows.
' # bar1.bas
' # Simple PICAXE program to simulate an LM399
' # Type application (like a lightbar) where
' # the voltage on input 4 is translated to
' # 4 states (000, 100, 110, 111)
symbol readValue =4
symbol v0 = 0
symbol v1 = 1
symbol v2 = 2
symbol tmpValue=b10
init:
' ## initialize it all pins to zero
low v0
low v1
low v2
start:
' ### read value
readadc readValue,tmpValue
if tmpValue < 64 then stateZero
if tmpValue < 128 then stateOne
if tmpValue < 192 then stateTwo
stateThree:
high v0
high v1
high v2
goto start
stateTwo:
high v0
high v1
low v2
goto start
stateOne:
high v0
low v1
low v2
goto start
stateZero:
low v0
low v1
low v2
goto start
Here is the circuit I used to demonstrate the selections. Its a little abridged.
First video
The problem with the simple code is that when you have a value that close to the edge, it toggles. I demonstrate this in the end of the video. To fix this you need hysteresis.
This can be done with a bit of effort and still have room to spare on the chip.
' # bar_w_hyst.bas Robert Stave 2008
' # Simple PICAXE program to simulate an LM399
' # Type application (like a lightbar) where
' # the voltage on input 4 is translated to
' # 4 states (000, 100, 110, 111)
' #
' # Added code to simulate hysteresis
symbol readValue =4
symbol v0 = 0
symbol v1 = 1
symbol v2 = 2
symbol tmpValue=b10
symbol state = b8
init:
' ## initialize it all pins to zero
low v0
low v1
low v2
state = 0;
start:
' ### read value
readadc readValue,tmpValue
if tmpValue < 64 then stateZero
if tmpValue < 128 then stateOne
if tmpValue < 192 then stateTwo
stateThree:
high v0
high v1
high v2
state = 3
goto start
stateTwo:
' # check if we are above 186 if so and we
' # are coming from 3, just ignore it for now
if tmpValue > 186 then
if state = 3 then
goto start
endif
endif
high v0
high v1
low v2
state = 2
goto start
stateOne:
' # check if we are above 120 if so and we
' # are coming from 2, just ignore it for now
if tmpValue > 120 then
if state = 2 then
goto start
endif
endif
high v0
low v1
low v2
state = 1
goto start
stateZero:
' # check if we are above 58 if so and we
' # are coming from 1, just ignore it for now
if tmpValue > 58 then
if state = 1 then
goto start
endif
endif
low v0
low v1
low v2
state = 0
goto start
The Second video shows a different program in the same circuit. This program selects only one pin at a time.
Here is the code for the Exclusive pattern. Basically only one pin is selected. This is the type of controller that can be used with a 4066 to select things like sine/triangle/square.
Here is the code for a 3 bit counting version.
Back to PICAXE projects


