-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20040131b-sah-3c-w_clock.bas
210 lines (189 loc) · 6.66 KB
/
20040131b-sah-3c-w_clock.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
'====================================================
'OPEN SOURCE FOREVER / PUBLIC DOMAIN
'====================================================
'*****************************************************************
' Module: PSIM-1 REV1a / REV1b
' Processor Type: Basic Micro - Basic Atom Pro24M
' Description: Chromatic Quantized Sample and Hold / 3 Channel with Clock In
' Developed by Brice D. Hornback - http://www.SynthModules.com
' Special Thanks to Grant Richter for his assistance.
' Special Thanks to dr.mabuse of the Modern Implement Company
' Revision Date: 2004/01/31 5:02 AM
' Status: DRAFT ONLY
'*****************************************************************
'
'INTRODUCTION
'
'SAH-3C-w_clock.bas is three channel Sample & Hold with Chromatic Quantizer
'built-in. IN-4 is for CLOCK IN. I can only get this to successfully work
'using a very short pulse (Blacet Binary Zone Short Pulse Clock Out) or also
'using a TRIANGLE Wave from my Blacet VCO as well as using the Pulse Output
'set to a very short pulse. Improvements can surely be made to this.
'Timing is *not* verified and your results may vary.
'
'Also, OUT-4 is not being used. This could be programmed and used as a
'Gate/Trigger/Clock OUT signal with a 10.666V max output.
'
'*****************************************************************'
' Basic Micro Atom Pro-24M Configuration
'
' (Note: P0 is I/O 0 and NOT pin 0 on the microprocessor.)
'
' P0 - Analog IN-1 (0-5 VDC)
' P1 - Analog IN-2 (0-5 VDC)
' P2 - Analog IN-3 (0-5 VDC)
' P3 - Analog IN-4 (0-5 VDC)
' P4 - START Button (Momentary Normally Open Switch)
' P5 - STOP Button (Momentary Normally Open Switch)
' P6 - I2C/SDA (Reserved) - J3 Pin 1
' P7 - I2C/SDL (Reserved) - J3 Pin 2
' P8 - AUX (Digital I/O - NO BUFFERING)
' P9 - STOP LED
' P10 - RUN LED
' P11 - DAC - LOADDACS
' P12 - DAC - SERDATA
' P13 - DAC - CLOCK
' P14 - RXD (Reserved) - J5 Pin 1
' P15 - TXD (Reserved) - J5 Pin 2
'************************************************************************
'Define Variables
LOADDACS CON 11 ' Pin OUT to DAC LOADDACS
SERDATA CON 12 ' Pin OUT Serial Data to DAC (16-bit)
CLOCK CON 13 ' Pin OUT to Clock DAC
STOPLED CON 9 ' Red LED
RUNLED CON 10 ' Green LED
BSTART CON 5 ' Start Button
BSTOP CON 4 ' Stop Button
AUX CON 8
ADC1 CON 0
ADC2 CON 1
ADC3 CON 2
ADC4 CON 3
MINFREQ CON 0 ' DAC - Sets to 0 VDC
MAXFREQ CON 4095 ' Maximum value for 12-bit DAC is 4096 (or 0 TO 4095)
RAWDAC1 VAR WORD ' RAW DAC DATA 1
RAWDAC2 VAR WORD ' RAW DAC DATA 2
RAWDAC3 VAR WORD ' RAW DAC DATA 3
RAWDAC4 VAR WORD ' RAW DAC DATA 4
DAC1V VAR WORD ' DAC Value to be Sent to DAC Channel
DAC2V VAR WORD ' DAC Value to be Sent to DAC Channel
DAC3V VAR WORD ' DAC Value to be Sent to DAC Channel
DAC4V VAR WORD ' DAC Value to be Sent to DAC Channel
ADC1V VAR WORD ' Value of Analog IN-1
ADC2V VAR WORD ' Value of Analog IN-2
ADC3V VAR WORD ' Value of Analog IN-3
ADC4V VAR WORD ' Value of Analog IN-4
I VAR WORD ' Misc Counting Variable
TEMPO VAR WORD ' TEMPO
BPM VAR BYTE ' Beats Per Minute (Value 0 to 254)
TONE VAR WORD ' Frequency in Hertz
FREQ VAR WORD ' Temporary Frequency Counter
GATEON VAR WORD ' GATE ON Time
GATEOFF VAR WORD ' GATE OFF Time
NOTE VAR WORD ' Note to Play
WORK VAR BYTE ' Workspace for BUTTON instruction.
'************************************************************************
'Initialize Module
DIRS = %1111110000000000 ' Configure Pins 1=input 0=output
OUTS = %1111111111111111 ' Configure State 1=low 0=high
WORK=0
TONE=440 ' Change this to frequency in Hz. to output from the AUX jack.
' This can be used as a tuning frequency to beat your VCO's
' against.
'BPM=120 ' Change this to how ever many Beats Per Minute you want.
'TEMPO=60000/BPM ' Do not change
GOSUB INIT
'************************************************************************
RUN:
IF IN5 = 1 THEN ENDPROGRAM ' Pressing Stop button resets program
'Removing the above line may speed up the program and may result
'in more accurate timing of the clock in signal. Basically, if you
'don't need it... don't use it.
LOW RUNLED
LOW STOPLED
CLOCKIN:
GOSUB SCANADC
IF ADC4V >= 500 THEN' If IN-4 is HIGH then Clock Is Active
DAC1V=(ADC1V/16)*32
DAC2V=(ADC2V/16)*32
DAC3V=(ADC3V/16)*32
HIGH RUNLED
TOGGLE AUX ' Outputs 5V on AUX port to use as a Gate/Trigger
GOSUB LOADALLDACS
ENDIF
GOTO RUN
IF ADC3V < 500 THEN' If IN-4 is low then WAIT
GOTO CLOCKIN
ENDIF
GOTO RUN
'************************************************************************
' SUBROUTINES - DO NOT MODIFY!
'************************************************************************
INIT:' by Brice D. Hornback - http://www.SynthModules.com
' Resets DAC values, flashes LEDs, then waits for Start button.
LOW RUNLED
GOSUB RESETDAC
FOR I=1 TO 12
TOGGLE RUNLED
PAUSE 50
TOGGLE STOPLED
PAUSE 50
NEXT
LOOP1:
TOGGLE STOPLED
PAUSE 100
IF IN4 = 1 THEN RUN
IF IN5 = 1 THEN ENDLOOP1
GOTO LOOP1
ENDLOOP1:
RETURN
PLAYFREQ:' by Brice D. Hornback - http://www.SynthModules.com
'Plays a tone (Variable FREQ) on the AUX jack until Stop button is pressed.
LOW STOPLED
HIGH RUNLED
LOOP0:
IF IN5 = 1 THEN ENDLOOP0
FREQOUT AUX,1000,TONE ' This is the command to output the frequency (TONE) for 1000 ms.
GOTO LOOP0
ENDLOOP0:
LOW RUNLED
HIGH STOPLED
RETURN
RESETDAC:' by Brice D. Hornback - http://www.SynthModules.com
'Sets all DAC channels to 0V and refreshes all four DAC channels.
DAC1V=0
DAC2V=0
DAC3V=0
DAC4V=0
GOSUB LOADALLDACS
RETURN
LOADALLDACS: ' by Grant Richter of Wiard Synthesizer Company as of 17 Jan 2004
'Add addresses to values no speed improve with OR over +
RAWDAC1=DAC1V+49152
RAWDAC2=DAC2V+32768
RAWDAC3=DAC3V+16384
'RAWDAC4=DAC4V
'shift out 16 bits mode 4 gotta bang loaddacs pin for each channel
'skew from ch. 1 to 4 = 400 usecs. Aprox 1 msec execution time for sub.
SHIFTOUT SERDATA,CLOCK,4,[RAWDAC1\16]
PULSOUT LOADDACS,1
SHIFTOUT SERDATA,CLOCK,4,[RAWDAC2\16]
PULSOUT LOADDACS,1
SHIFTOUT SERDATA,CLOCK,4,[RAWDAC3\16]
PULSOUT LOADDACS,1
'SHIFTOUT SERDATA,CLOCK,4,[RAWDAC4\16]
'PULSOUT LOADDACS,1
RETURN
SCANADC:' by Grant Richter of Wiard Synthesizer Company as of 17 Jan 2004
'load buffers with actual a/d values
ADIN ADC1, ADC1V
ADIN ADC2, ADC2V
ADIN ADC3, ADC3V
ADIN ADC4, ADC4V
RETURN
ENDPROGRAM: ' by Brice D. Hornback - http://www.SynthModules.com
' Resets all four DAC channels to 0V and runs INIT subroutine
LOW RUNLED
HIGH STOPLED
GOSUB RESETDAC
GOTO INIT