Code:
DEVICE P8X32A, XTAL1, PLL16X
XIN 5_000_000
'following 7 variables declared and used by first cog; trying to pass these to TASK cog ***
ToneNumberSteps VAR LONG
ToneLeftPhaseStep VAR LONG
ToneRightPhaseStep VAR LONG
ToneLeftAttenuation VAR LONG
ToneRightAttenuation VAR LONG
ToneLeftPin VAR LONG
ToneRightPin VAR LONG
'other variables
ToneRunning VAR LONG 'set to 1 in Tonegen SUB; would like to set to 0 on exiting TASK ***
Frequency VAR LONG
Duration VAR LONG
Attenuation VAR LONG
LeftFrequency VAR LONG
RightFrequency VAR LONG
'SUB, FUNCs and TASK
Tonegen SUB 3,5
GetToneNumberSteps FUNC 1
GetTonePhaseStep FUNC 1
TonegenAssembly TASK
PROGRAM Start
Start:
LED PIN 0 LOW 'prepares PropBASIC program indicator LED
DO
TOGGLE LED 'blinks PropBASIC LED as minimal healthcheck
PAUSE 1000 'aids debug by slowing things down
Tonegen 400,500,3 'will eventually output test tone 400Hz, 500mS, attenuation level 3
LOOP
END
FUNC GetToneNumberSteps
' use duration as __param1
' converts the following Spin into PropBASIC: ToneNumberSteps:=(duration*(clkfreq/1000))/200)
__param2 = clkfreq / 200_000
__param1 = __param1 * __param2
'return of __param1 required
RETURN __param1 'haven't yet managed to get rid of this line
ENDFUNC
FUNC GetTonePhaseStep
' use Left or Right Frequency passed as __param1
' converts the following Spin into PropBASIC: TonePhaseStep:=(L or R Frequency*(1<<15)/(clkfreq/200))*(1<<13)*(1<<4)
__param2 = 1 << 15
__param1 = __param1 * __param2
__param2 = clkfreq / 200
__param1 = __param1 / __param2
__param2 = 1 << 13
__param1 = __param1 * __param2
__param2 = 1 << 4
__param1 / __param1 * __param2
'return of _param1 required
RETURN __param1 'haven't yet managed to get rid of this line
ENDFUNC
SUB Tonegen (frequency,duration,attenuation)ŠLeftFrequency,RightFrequency)
LED2 PIN 1 LOW 'prepares sub-routine indicator LED
ToneLeftPin=11
ToneRightPin=10
LeftFrequency=Frequency
RightFrequency=Frequency
ToneNumberSteps=GetToneNumberSteps Duration '***ToneNumberSteps is value I would like to pass to TASK
ToneLeftPhaseStep=GetTonePhaseStep LeftFrequency
ToneRightPhaseStep=GetTonePhaseStep RightFrequency
ToneLeftAttenuation=Attenuation
ToneRightAttenuation=Attenuation
ToneRunning=1
COGSTART ToneGenAssembly
TOGGLE LED2
PAUSE 1000
ENDSUB
TASK TonegenAssembly
ASM
DAT 'Assembly Tone Generator
org 0
Tonestart '***beginning of assembly tone generator
'***load input parameters from first cog to par in
'***TASK cog, given address ToneNumberSteps from
'***first cog; passed to par in TASK cog.
movd
ar,#tNumberSteps 'copies 7 parameters to location starting with tNumberSteps
mov temp1,par
mov temp2,#7 'there are 7 input parameters
ar rdlong 0,temp1
add
ar,dlsb
add temp1,#4
djnz temp2,#
ar
'loads more code here
'now closing code
'would like to set ToneRunning in first cog to 0 here! ***
COGID temp1
COGSTOP temp1
'setup parameters
tCounterMode long %00011000_00000000_00000000_00000000
dlsb long 1 << 9
'phase accumulators
LeftPhase long 0
RightPhase long 0
'main loop vars
dcnt long 200 '#clocks/main loop --> gives 400kHz update rate
offset long $8000_0000
'Working variables
temp1 res 1
temp2 res 1
wait res 1
'Input Parameters
tNumberSteps res 1 'Determines tone duration (left and right)
tLeftStep res 1 'Determines left tone frequency
tRightStep res 1 'Determines right tone frequency
tLeftAtten res 1 'Determines left tone volume (0=loud, 8=soft)
tRightAtten res 1 'Determines right tone volume (0=loud, 8=soft)
tLeftPin res 1 'Pin# for left audio output (negative number disables)
tRightPin res 1 'Pin# for right audio output (negative number disables)
ENDASM
ENDTASK
Bookmarks