Skip to end. I had several interations each interesting but the last one was the most useful.....
I am building a sequencer based on the 28x2 for my analog synth. I wanted to share what I found to be the best way to sequence the ports. Rather than set the port each time use a for next loop with a bit shift command. Doing this you have to start the loop on %00000001 outside the loop or you miss the first port. You can make it setp backwards by using a port to determine direction and a set of if then statements. See the code below. Real simple but something people need to do so I thought I'd share the way I did it. I am using the good old 4066 cmos switch but if I did it again I'd look to the never DG403 like switches. I am seeking an addressable 16 or 32 channel multiplexer to do this using one port but that will be version 2.0.
I am building a sequencer based on the 28x2 for my analog synth. I wanted to share what I found to be the best way to sequence the ports. Rather than set the port each time use a for next loop with a bit shift command. Doing this you have to start the loop on %00000001 outside the loop or you miss the first port. You can make it setp backwards by using a port to determine direction and a set of if then statements. See the code below. Real simple but something people need to do so I thought I'd share the way I did it. I am using the good old 4066 cmos switch but if I did it again I'd look to the never DG403 like switches. I am seeking an addressable 16 or 32 channel multiplexer to do this using one port but that will be version 2.0.
Code:
'16 channel sequencer
Let dirsA=%00010000
Let dirsB=%11111111
Let dirsC=%11111111
main:
Let pinsC =%00000000
Let pinsB =%00000001
If Pina.2=0 and Pina.3=0 then goto GoForward
If Pina.2=1 and Pina.3=0 then goto GoBackwards
If Pina.2=0 and Pina.3=1 then goto Dual_8ch_Forward
If Pina.2=1 and Pina.3=1 then goto Dual_8ch_Backward
GoForward:
For b0=0 to 7 step 1
Readadc a.0,w3
If pina.1=0 then let b2=1: Endif 'set speed multiplier
If pina.1=1 then let b2=10:Endif
Let b1 = %00000001 << b0
Let pinsB=b1
w3=w3*b2
w3=w3+1
Pause w3
Next b0
Let pinsB =%00000000
Let pinsC =%00000001
For b0=0 to 7 step 1
Readadc a.0,w3
If pina.1=0 then let b2=1:Endif
If pina.1=1 then let b2=10:Endif
Let b1 = %00000001 << b0
Let pinsC=b1
w3=w3*b2
w3=w3+1
Pause w3
Next b0
Goto main
GoBackwards:
For b0=7 to 0 step -1
Readadc a.0,w3
If pina.1=0 then let b2=1: Endif 'set speed multiplier
If pina.1=1 then let b2=10:Endif
Let b1 = %00000001 << b0
Let pinsB=b1
w3=w3*b2
w3=w3+1
Pause w3
Next b0
Let pinsB =%00000000
Let pinsC =%00000001
For b0=7 to 0 step -1
Readadc a.0,w3
If pina.1=0 then let b2=1:Endif
If pina.1=1 then let b2=10:Endif
Let b1 = %00000001 << b0
Let pinsC=b1
w3=w3*b2
w3=w3+1
Pause w3
Next b0
Goto main
Dual_8Ch_Forward:
Let pinsB =%00000000
Let pinsC =%00000001
For b0=0 to 7 step 1
Readadc a.0,w3
If pina.1=0 then let b2=1: Endif 'set speed multiplier
If pina.1=1 then let b2=10:Endif
Let b1 = %00000001 << b0
Let pinsB=b1
Let PinsC=b1
w3=w3*b2
w3=w3+1
Pause w3
Next b0
Goto main
Dual_8Ch_Backward:
Let pinsB =%00000000
Let pinsC =%00000001
For b0=7 to 0 step -1
Readadc a.0,w3
If pina.1=0 then let b2=1:Endif
If pina.1=1 then let b2=10:Endif
Let b1 = %00000001 << b0
Let pinsB=b1
Let pinsC=b1
w3=w3*b2
w3=w3+1
Pause w3
Next b0
Goto main
Attachments
-
144.5 KB Views: 33
-
19.7 KB Views: 98
Last edited: