Jump to content

pot control of DEFAULT_EXT_CLK_PULSEWIDTH?


Recommended Posts

Is it possible to poll an AIN pin to control the DEFAULT_EXT_CLK_PULSEWIDTH variable?

Maybe from 500uS to 1S? (and I realize that fast clock speeds + long pulsewidths may result in no pulse at all)

For example, when using the MIDIbox CV this would be great for controlling various gear that responds to gate length.

The read rate wouldn't have to be that frequent.

I imagine I would stick it in in here:

USER_AIN_NotifyChange
	return

(more soon on this part of the code - just looking through other examples first)

Link to comment
Share on other sites

First of all, I'm a complete ASM newbie! I'm just taking a wild shot in the dark here, using some AIN-reading code from the Magic Midi Delay.

How about something like this (with the appropraite variable declarations added beforehand):

USER_AIN_NotifyChange

	;; if pot number == 0, set the DEFAULT_EXT_CLK_PULSEWIDTH
	movf	MIOS_PARAMETER1, W

	;; we have a 10-bit result in MIOS_PARAMETER[23], but need a 8-bit value
	;; shift value two times to the right (-> value / 4)
	clrc
	rrf	MIOS_PARAMETER3, F	; 1
	rrf	MIOS_PARAMETER2, F
	clrc
	rrf	MIOS_PARAMETER3, F	; 2
	rrf	MIOS_PARAMETER2, W	; -> WREG

	;; 8-bit result is now in WREG, store value into DEFAULT_EXT_CLK_PULSEWIDTH register 
	call	PULSEWIDTH_Set		; with this function

Function to set new PULSEWIDTH (which uses a table to scale the values accordingly):
PULSEWIDTH_Set
	;; calc address to timer value: PULSEWIDTH_TABLE 
	clrf	TMP2				; clear help register
	clrc					; clear carry bit
	rlf	DEFAULT_EXT_CLK_PULSEWIDTH, W	; shift DEFAULT_EXT_CLK_PULSEWIDTH value to the left (== PULSEWIDTH * 2)
	movwf	TMP1				; save result in TMP1
	rlf	TMP2, F				; shift TMP2 to the left (it's zero, but just for info)

	TABLE_ADDR PULSEWIDTH_TABLE	; this macro sets the base address	
	movf	TMP1, W				; add DEFAULT_EXT_CLK_PULSEWIDTH offset (number *2) to TABLPTR
	addwf	TBLPTRL, F			; low-byte
	movf	TMP2, W
	addwfc	TBLPTRH, F			; high-byte (+carry bit on overrun)

	;; read value from table and copy to MIOS_PARAMETER[12]
	tblrd*+
	movff	TABLAT, MIOS_PARAMETER1
	tblrd*+
	movff	TABLAT, MIOS_PARAMETER2


	;; copy MIOS_PARAMETER2 to DEFAULT_EXT_CLK_PULSEWIDTH  (is this necessary?????)

        movff	MIOS_PARAMETER2, DEFAULT_EXT_CLK_PULSEWIDTH

	return

And now for the scaling table - and I know these numbers need to be tweaked if I want to get the pulse width up to 1 second:

PULSEWIDTH_TABLE

	dw	0xFFFF	; PULSEWIDTH: 0
	dw	0xFFFF	; PULSEWIDTH: 1
	dw	0xFFFF	; PULSEWIDTH: 2
	dw	0xFFFF	; PULSEWIDTH: 3
	dw	0xFFFF	; PULSEWIDTH: 4
	dw	0xFFFF	; PULSEWIDTH: 5
	dw	0xFFFF	; PULSEWIDTH: 6
	dw	0xFFFF	; PULSEWIDTH: 7
	dw	0xFFFF	; PULSEWIDTH: 8
	dw	0xFFFF	; PULSEWIDTH: 9
	dw	0xFFFF	; PULSEWIDTH: 10
	dw	0xFFFF	; PULSEWIDTH: 11
	dw	0xFFFF	; PULSEWIDTH: 12
	dw	0xFFFF	; PULSEWIDTH: 13
	dw	0xFFFF	; PULSEWIDTH: 14
	dw	0xFFFF	; PULSEWIDTH: 15
	dw	0xFFFF	; PULSEWIDTH: 16
	dw	0xFFFF	; PULSEWIDTH: 17
	dw	0xFFFF	; PULSEWIDTH: 18
	dw	0xFFFF	; PULSEWIDTH: 19
	dw	0xFFFF	; PULSEWIDTH: 20
	dw	0xFFFF	; PULSEWIDTH: 21
	dw	0xFFFF	; PULSEWIDTH: 22
	dw	0xFFFF	; PULSEWIDTH: 23
	dw	0xFFFF	; PULSEWIDTH: 24
	dw	0xFFFF	; PULSEWIDTH: 25
	dw	0xFFFF	; PULSEWIDTH: 26
	dw	0xFFFF	; PULSEWIDTH: 27
	dw	0xFFFF	; PULSEWIDTH: 28
	dw	0xFFFF	; PULSEWIDTH: 29
	dw	0xFFFF	; PULSEWIDTH: 30
	dw	0xFFFF	; PULSEWIDTH: 31
	dw	0xFFFF	; PULSEWIDTH: 32
	dw	0xFFFF	; PULSEWIDTH: 33
	dw	0xFFFF	; PULSEWIDTH: 34
	dw	0xFFFF	; PULSEWIDTH: 35
	dw	0xFFFF	; PULSEWIDTH: 36
	dw	0xFFFF	; PULSEWIDTH: 37
	dw	0xFFFF	; PULSEWIDTH: 38
	dw	0xFFFF	; PULSEWIDTH: 39
	dw	0xFFFF	; PULSEWIDTH: 40
	dw	0xFFFF	; PULSEWIDTH: 41
	dw	0xFFFF	; PULSEWIDTH: 42
	dw	0xFFFF	; PULSEWIDTH: 43
	dw	0xFFFF	; PULSEWIDTH: 44
	dw	0xFFFF	; PULSEWIDTH: 45
	dw	0xFFFF	; PULSEWIDTH: 46
	dw	0xFFFF	; PULSEWIDTH: 47
	dw	0xFE50	; PULSEWIDTH: 48
	dw	0xF91F	; PULSEWIDTH: 49
	dw	0xF424	; PULSEWIDTH: 50
	dw	0xEF5A	; PULSEWIDTH: 51
	dw	0xEAC0	; PULSEWIDTH: 52
	dw	0xE652	; PULSEWIDTH: 53
	dw	0xE20E	; PULSEWIDTH: 54
	dw	0xDDF2	; PULSEWIDTH: 55
	dw	0xD9FB	; PULSEWIDTH: 56
	dw	0xD628	; PULSEWIDTH: 57
	dw	0xD277	; PULSEWIDTH: 58
	dw	0xCEE6	; PULSEWIDTH: 59
	dw	0xCB73	; PULSEWIDTH: 60
	dw	0xC81D	; PULSEWIDTH: 61
	dw	0xC4E3	; PULSEWIDTH: 62
	dw	0xC1C3	; PULSEWIDTH: 63
	dw	0xBEBC	; PULSEWIDTH: 64
	dw	0xBBCC	; PULSEWIDTH: 65
	dw	0xB8F4	; PULSEWIDTH: 66
	dw	0xB631	; PULSEWIDTH: 67
	dw	0xB383	; PULSEWIDTH: 68
	dw	0xB0E9	; PULSEWIDTH: 69
	dw	0xAE62	; PULSEWIDTH: 70
	dw	0xABEE	; PULSEWIDTH: 71
	dw	0xA98A	; PULSEWIDTH: 72
	dw	0xA738	; PULSEWIDTH: 73
	dw	0xA4F5	; PULSEWIDTH: 74
	dw	0xA2C2	; PULSEWIDTH: 75
	dw	0xA09E	; PULSEWIDTH: 76
	dw	0x9E88	; PULSEWIDTH: 77
	dw	0x9C80	; PULSEWIDTH: 78
	dw	0x9A84	; PULSEWIDTH: 79
	dw	0x9896	; PULSEWIDTH: 80
	dw	0x96B4	; PULSEWIDTH: 81
	dw	0x94DD	; PULSEWIDTH: 82
	dw	0x9312	; PULSEWIDTH: 83
	dw	0x9152	; PULSEWIDTH: 84
	dw	0x8F9C	; PULSEWIDTH: 85
	dw	0x8DF1	; PULSEWIDTH: 86
	dw	0x8C4F	; PULSEWIDTH: 87
	dw	0x8AB7	; PULSEWIDTH: 88
	dw	0x8928	; PULSEWIDTH: 89
	dw	0x87A2	; PULSEWIDTH: 90
	dw	0x8624	; PULSEWIDTH: 91
	dw	0x84AF	; PULSEWIDTH: 92
	dw	0x8342	; PULSEWIDTH: 93
	dw	0x81DC	; PULSEWIDTH: 94
	dw	0x807E	; PULSEWIDTH: 95
	dw	0x7F28	; PULSEWIDTH: 96
	dw	0x7DD8	; PULSEWIDTH: 97
	dw	0x7C8F	; PULSEWIDTH: 98
	dw	0x7B4D	; PULSEWIDTH: 99
	dw	0x7A12	; PULSEWIDTH: 100
	dw	0x78DC	; PULSEWIDTH: 101
	dw	0x77AD	; PULSEWIDTH: 102
	dw	0x7683	; PULSEWIDTH: 103
	dw	0x7560	; PULSEWIDTH: 104
	dw	0x7441	; PULSEWIDTH: 105
	dw	0x7329	; PULSEWIDTH: 106
	dw	0x7215	; PULSEWIDTH: 107
	dw	0x7107	; PULSEWIDTH: 108
	dw	0x6FFD	; PULSEWIDTH: 109
	dw	0x6EF9	; PULSEWIDTH: 110
	dw	0x6DF9	; PULSEWIDTH: 111
	dw	0x6CFD	; PULSEWIDTH: 112
	dw	0x6C06	; PULSEWIDTH: 113
	dw	0x6B14	; PULSEWIDTH: 114
	dw	0x6A25	; PULSEWIDTH: 115
	dw	0x693B	; PULSEWIDTH: 116
	dw	0x6855	; PULSEWIDTH: 117
	dw	0x6773	; PULSEWIDTH: 118
	dw	0x6694	; PULSEWIDTH: 119
	dw	0x65B9	; PULSEWIDTH: 120
	dw	0x64E2	; PULSEWIDTH: 121
	dw	0x640E	; PULSEWIDTH: 122
	dw	0x633E	; PULSEWIDTH: 123
	dw	0x6271	; PULSEWIDTH: 124
	dw	0x61A8	; PULSEWIDTH: 125
	dw	0x60E1	; PULSEWIDTH: 126
	dw	0x601E	; PULSEWIDTH: 127
	dw	0x5F5E	; PULSEWIDTH: 128
	dw	0x5EA0	; PULSEWIDTH: 129
	dw	0x5DE6	; PULSEWIDTH: 130
	dw	0x5D2E	; PULSEWIDTH: 131
	dw	0x5C7A	; PULSEWIDTH: 132
	dw	0x5BC8	; PULSEWIDTH: 133
	dw	0x5B18	; PULSEWIDTH: 134
	dw	0x5A6C	; PULSEWIDTH: 135
	dw	0x59C1	; PULSEWIDTH: 136
	dw	0x591A	; PULSEWIDTH: 137
	dw	0x5874	; PULSEWIDTH: 138
	dw	0x57D2	; PULSEWIDTH: 139
	dw	0x5731	; PULSEWIDTH: 140
	dw	0x5693	; PULSEWIDTH: 141
	dw	0x55F7	; PULSEWIDTH: 142
	dw	0x555D	; PULSEWIDTH: 143
	dw	0x54C5	; PULSEWIDTH: 144
	dw	0x542F	; PULSEWIDTH: 145
	dw	0x539C	; PULSEWIDTH: 146
	dw	0x530A	; PULSEWIDTH: 147
	dw	0x527A	; PULSEWIDTH: 148
	dw	0x51ED	; PULSEWIDTH: 149
	dw	0x5161	; PULSEWIDTH: 150
	dw	0x50D7	; PULSEWIDTH: 151
	dw	0x504F	; PULSEWIDTH: 152
	dw	0x4FC8	; PULSEWIDTH: 153
	dw	0x4F44	; PULSEWIDTH: 154
	dw	0x4EC1	; PULSEWIDTH: 155
	dw	0x4E40	; PULSEWIDTH: 156
	dw	0x4DC0	; PULSEWIDTH: 157
	dw	0x4D42	; PULSEWIDTH: 158
	dw	0x4CC6	; PULSEWIDTH: 159
	dw	0x4C4B	; PULSEWIDTH: 160
	dw	0x4BD1	; PULSEWIDTH: 161
	dw	0x4B5A	; PULSEWIDTH: 162
	dw	0x4AE3	; PULSEWIDTH: 163
	dw	0x4A6E	; PULSEWIDTH: 164
	dw	0x49FB	; PULSEWIDTH: 165
	dw	0x4989	; PULSEWIDTH: 166
	dw	0x4918	; PULSEWIDTH: 167
	dw	0x48A9	; PULSEWIDTH: 168
	dw	0x483B	; PULSEWIDTH: 169
	dw	0x47CE	; PULSEWIDTH: 170
	dw	0x4762	; PULSEWIDTH: 171
	dw	0x46F8	; PULSEWIDTH: 172
	dw	0x468F	; PULSEWIDTH: 173
	dw	0x4627	; PULSEWIDTH: 174
	dw	0x45C1	; PULSEWIDTH: 175
	dw	0x455B	; PULSEWIDTH: 176
	dw	0x44F7	; PULSEWIDTH: 177
	dw	0x4494	; PULSEWIDTH: 178
	dw	0x4432	; PULSEWIDTH: 179
	dw	0x43D1	; PULSEWIDTH: 180
	dw	0x4371	; PULSEWIDTH: 181
	dw	0x4312	; PULSEWIDTH: 182
	dw	0x42B4	; PULSEWIDTH: 183
	dw	0x4257	; PULSEWIDTH: 184
	dw	0x41FB	; PULSEWIDTH: 185
	dw	0x41A1	; PULSEWIDTH: 186
	dw	0x4147	; PULSEWIDTH: 187
	dw	0x40EE	; PULSEWIDTH: 188
	dw	0x4096	; PULSEWIDTH: 189
	dw	0x403F	; PULSEWIDTH: 190
	dw	0x3FE9	; PULSEWIDTH: 191
	dw	0x3F94	; PULSEWIDTH: 192
	dw	0x3F3F	; PULSEWIDTH: 193
	dw	0x3EEC	; PULSEWIDTH: 194
	dw	0x3E99	; PULSEWIDTH: 195
	dw	0x3E47	; PULSEWIDTH: 196
	dw	0x3DF6	; PULSEWIDTH: 197
	dw	0x3DA6	; PULSEWIDTH: 198
	dw	0x3D57	; PULSEWIDTH: 199
	dw	0x3D09	; PULSEWIDTH: 200
	dw	0x3CBB	; PULSEWIDTH: 201
	dw	0x3C6E	; PULSEWIDTH: 202
	dw	0x3C22	; PULSEWIDTH: 203
	dw	0x3BD6	; PULSEWIDTH: 204
	dw	0x3B8B	; PULSEWIDTH: 205
	dw	0x3B41	; PULSEWIDTH: 206
	dw	0x3AF8	; PULSEWIDTH: 207
	dw	0x3AB0	; PULSEWIDTH: 208
	dw	0x3A68	; PULSEWIDTH: 209
	dw	0x3A20	; PULSEWIDTH: 210
	dw	0x39DA	; PULSEWIDTH: 211
	dw	0x3994	; PULSEWIDTH: 212
	dw	0x394F	; PULSEWIDTH: 213
	dw	0x390A	; PULSEWIDTH: 214
	dw	0x38C6	; PULSEWIDTH: 215
	dw	0x3883	; PULSEWIDTH: 216
	dw	0x3840	; PULSEWIDTH: 217
	dw	0x37FE	; PULSEWIDTH: 218
	dw	0x37BD	; PULSEWIDTH: 219
	dw	0x377C	; PULSEWIDTH: 220
	dw	0x373C	; PULSEWIDTH: 221
	dw	0x36FC	; PULSEWIDTH: 222
	dw	0x36BD	; PULSEWIDTH: 223
	dw	0x367E	; PULSEWIDTH: 224
	dw	0x3640	; PULSEWIDTH: 225
	dw	0x3603	; PULSEWIDTH: 226
	dw	0x35C6	; PULSEWIDTH: 227
	dw	0x358A	; PULSEWIDTH: 228
	dw	0x354E	; PULSEWIDTH: 229
	dw	0x3512	; PULSEWIDTH: 230
	dw	0x34D8	; PULSEWIDTH: 231
	dw	0x349D	; PULSEWIDTH: 232
	dw	0x3464	; PULSEWIDTH: 233
	dw	0x342A	; PULSEWIDTH: 234
	dw	0x33F1	; PULSEWIDTH: 235
	dw	0x33B9	; PULSEWIDTH: 236
	dw	0x3381	; PULSEWIDTH: 237
	dw	0x334A	; PULSEWIDTH: 238
	dw	0x3313	; PULSEWIDTH: 239
	dw	0x32DC	; PULSEWIDTH: 240
	dw	0x32A6	; PULSEWIDTH: 241
	dw	0x3271	; PULSEWIDTH: 242
	dw	0x323C	; PULSEWIDTH: 243
	dw	0x3207	; PULSEWIDTH: 244
	dw	0x31D3	; PULSEWIDTH: 245
	dw	0x319F	; PULSEWIDTH: 246
	dw	0x316B	; PULSEWIDTH: 247
	dw	0x3138	; PULSEWIDTH: 248
	dw	0x3106	; PULSEWIDTH: 249
	dw	0x30D4	; PULSEWIDTH: 250
	dw	0x30A2	; PULSEWIDTH: 251
	dw	0x3070	; PULSEWIDTH: 252
	dw	0x303F	; PULSEWIDTH: 253
	dw	0x300F	; PULSEWIDTH: 254
	dw	0x2FDE	; PULSEWIDTH: 255

Link to comment
Share on other sites

I fear that much more modifications have to be added (I cannot write them down "blind" without trying them out by myself)

First of all, DEFAULT_EXT_CLK_PULSEWIDTH is a constant value, which will be compiled directly into the firmware. In cv_clk.inc, it will be loaded with "movlw", but if you want to use it as a variable, it would have to be loaded with "movf <name>, W", where <name> is a free register address defined in app_defines.inc

(e.g., 0x60 is free, you could use it)

Second issue: the pulsewidth is a 8bit value (0..255) which allows you to vary the width from 500 uS... 127.5 mS. The delay counter in cv_clk.inc has to be changed to 16bit in order to achieve delays >= 128 mS

Accordingly, also the PULSEWIDTH variable needs to be 16bit (PULSEWIDTH_L, PULSEWIDTH_H, assigned to addresses 0x60 and 0x61)

Best Regards, Thorsten.

Link to comment
Share on other sites

Oops - I just remembered that J5 is used for the Gate Outputs! However, there are also two extra pins used as gate outputs on the AOUT board. Ugh, I'm going to have to disable one of the gate-out J5 pins and reassign it as a pot input.

Thanks goodness for this line in j5_dout.inc:

	;; (note: if you want to use some of them as input instead, just set the appr. line to "bsf TRISx, x"

(also - does the Pulsewidth have to be a 16bit if I interpolate values between .5ms and 1s? Can't I just use a select number of pre-defined pulse widths from a table?)

Thanks!

michel

Link to comment
Share on other sites

OK - I sort of have it working - even though I didn't use CV_CLK_PULSEWIDTH_L or CV_CLK_PULSEWIDTH_H (uh-oh!)

If I send Pin 1 of J5 0v, the pulse is really short. If I send it close to 5V, the pulse is much longer. Good so far.

But it's not a linear function - sometimes it get shorter, sometimes longer (and vice versa) as I turn the pot. I'm obviously manipulating this variable incorrectly.

This is what I've done so far:

main.asm

- Added:

;;  set this define to 1 if you want to use pots
#define USE_POTS 1


;; initialize the AIN driver

	;; use 1 pot
#if USE_POTS
	movlw	1

#else
	movlw	0
#endif
call	MIOS_AIN_NumberSet

=======================================

USER_AIN_NotifyChange

	;; if pot number == 0, set the DEFAULT_EXT_CLK_PULSEWIDTH
	movf	MIOS_PARAMETER1, W


;; we have a 10-bit result in MIOS_PARAMETER[23], but need a 8-bit value
	;; shift value two times to the right (-> value / 4)
	clrc
	rrf	MIOS_PARAMETER3, F	; 1
	rrf	MIOS_PARAMETER2, F
	clrc
	rrf	MIOS_PARAMETER3, F	; 2
	rrf	MIOS_PARAMETER2, W	; -> WREG

	;; 8-bit result is now in WREG, store value into DEFAULT_EXT_CLK_PULSEWIDTH register 
	call	PULSEWIDTH_Set		; with this function

	return

app_defines.h -Added:
CV_CLK_PULSEWIDTH_L	EQU	0x60	; used by cv_clk.inc
CV_CLK_PULSEWIDTH_H	EQU	0x61	; used by cv_clk.inc
cv_clk.inc - Changed:
movf	DEFAULT_EXT_CLK_PULSEWIDTH, W  ; changed from - movlw DEFAULT_EXT_CLK_PULSEWIDTH
j5_dout.inc - Changed:
	bsf	TRISA, 0	; Pin RA.0 = output off (chaged from bcf)
app_ain.inc - New routine:

PULSEWIDTH_Set

	;; copy MIOS_PARAMETER2 to DEFAULT_EXT_CLK_PULSEWIDTH  

    movff	MIOS_PARAMETER2, DEFAULT_EXT_CLK_PULSEWIDTH

	return

Am I smoking crack here? What's going on here?

Link to comment
Share on other sites

It's already declared in main.asm as part of the MIDIbox CV code:

#define DEFAULT_EXT_CLK_PULSEWIDTH 1

that's not a variable declaration and this is probably your problem.

this is a precompiler directive which tells the compiler to use this as a constant.

(actually replaces the name with the value before compiling)

to declare a variable you need equ and register address.

...

First of all, DEFAULT_EXT_CLK_PULSEWIDTH is a constant value, which will be compiled directly into the firmware.

...

(e.g., 0x60 is free, you could use it)

...

so you need (for example):

SNEAK_THIEF_CW_VAR EQU 0x060

and replace DEFAULT_EXT_CLK_PULSEWIDTH in the code you added with SNEAK_THIEF_CW_VAR

(name the var something better, hehe)

edit: just saw you are using that addy already.

still you are using DEFAULT_EXT_CLK_PULSEWIDTH like a var when it is const,

so writing to it writes to resister address 0x01

reading like a var instead of const also will use reg 0x01...

anywhere you wanted to write to DEFAULT_EXT_CLK_PULSEWIDTH

write instead to CV_CLK_PULSEWIDTH_L and CV_CLK_PULSEWIDTH_H

ok someone familiar with the code that actually sets the clock width will need

to step in to help convert that code to use your

new 16 bit value, CV_CLK_PULSEWIDTH_L, and CV_CLK_PULSEWIDTH_H.

(i'm not that guy)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...