|
Software
The software is written in assembly. I won't post the code here, i just started programming microcontrollers. I guess it makes more sense if i tell you about whats going on.
Mainloop
The frontpanelswitches are not debounced, no need to. They are continuously read in the mainloop. The rotaryswitches have +5V on the common pin. The other pins (4 for Speed and 7 for laststep) are led through lots of 1N4148-diodes to form the appropriate voltages for PortD's pins.
In the mainloop, the status of the switches are converted into a byte, stored in a sequencerstatus register.
Bits 0 and 1 of this register sets the timing which can have 4 states:
00 - Note advance
01 - 4th
10 - 8th
11 - 16th
Bit 2 holds the runningmode:
0 - Forward
1 - Random
Bits 3-5 hold the last step:
001 - last step = 2
010 - last step = 3
011 - last step = 4
100 - last step = 5
101 - last step = 6
110 - last step = 7
111 - last step = 8
Also in the mainloop i advance a counter (in consideration to lastStep) which constantly updates a randomNumber-register with LED-patterns of steps, e.g. 10000000, 01000000, 00100000 a.s.o. If an 'advance-step' happens, we have kind of random-step in our randomNumber-register which we only need to send to the LED-port.
Interrupt for midi
Midi is processed by UART-Interrupt. The interruptroutine analyes the incoming midibyte. All bytes except midiclock and note-On are ignored. start/stop/continue set or clear a flag to memorize the running status.
the pulses are counted and the current pulse-sum is compared to a variable which is set in the mainloop in consideration of the speed-bits in the sequencerstatus register. 24 pulses mean a 4th-note in midiprotocol. That means:
if sequencer is set to 4th, advance one step if pulsecount is 24.
if sequencer is set to 8th, advance one step if pulsecount is 12.
if sequencer is set to 16th, advance one step if pulsecount is 6.
if sequencer is set to notadvance, check if incoming noteOn is on our desired midichannel. If our midichannel is undefined, take the midichannel of the first incoming note-On.
In note-advance-forward-routine, we look if we reached the last step. If so, we reset the line to step 1.
In the note-advance-random-routine we take the byte which we find in our randomNumber-register.
|