Administra: add signalgenerator (Plexus 2.10)

This commit is contained in:
Jörg Deckert 2014-11-20 16:20:23 +01:00
parent 614f239fc2
commit 7b97da36e8
3 changed files with 252 additions and 9 deletions

View File

@ -66,12 +66,13 @@ Funktion : Dieser Code wird von Administra nach einem Reset aus dem EEPr
- ein- und ausgehende Verbindungen öffnen
- Daten übertragen
Komponenten : HSS 1.2 Andrew Arsenault Lizenz unklar
SIDCog Ver. 080 Johannes Ahlebrand MIT Lizenz
DACEngine 01/11/2010 Kwabena W. Agyeman MIT Lizenz
FATEngine 01/18/2009 Kwabena W. Agyeman MIT Lizenz
RTCEngine 11/22/2009 Kwabena W. Agyeman MIT Lizenz
PropTCP 12/08/2009 Harrison Pham Lizenz unklar
Komponenten : HSS 1.2 Andrew Arsenault Lizenz unklar
SIDCog Ver. 080 Johannes Ahlebrand MIT Lizenz
DACEngine 01/11/2010 Kwabena W. Agyeman MIT Lizenz
FATEngine 01/18/2009 Kwabena W. Agyeman MIT Lizenz
RTCEngine 11/22/2009 Kwabena W. Agyeman MIT Lizenz
PropTCP 12/08/2009 Harrison Pham Lizenz unklar
Propeller Signal Generator v1.2 (C) 2012 Johannes Ahlebrand Parallax Object Exchange License
COG's : MANAGMENT 1 COG
FAT/RTC 1 COG
@ -90,7 +91,7 @@ Defines : __ADM_FAT enable FAT engine (sd card handling)
__ADM_SID enable SID player
__ADM_LAN enable LAN functions
__ADM_RTC enable RTC functions (FAT engine inherits it also)
__ADM_PLX enable plexbus
__ADM_PLX enable Plexus functions
__ADM_DCF enable DCF77 receiver
__ADM_BLT enable Bluetooth
__ADM_COM enable serial port
@ -151,6 +152,7 @@ Logbuch :
17-04-2013-dr235 - konstanten für administra-funktionen komplett ausgelagert
22-12-2013-joergd - LAN Funktionen
17-12-2014-joergd - verschiedene Administra-Code-Versionen vereinheitlicht
29-11-2014-joergd - Signalgenerator (von zille für Plexus)
Kommandoliste :
@ -352,6 +354,7 @@ OBJ
#endif
#ifdef __ADM_PLX
plx : "adm-plx" 'PlexBux
signal : "adm-signalgenerator"
#endif
#ifdef __ADM_DCF
dcf : "adm-dcf" 'DCF-77
@ -559,6 +562,15 @@ PUB main | cmd,err 'chip: kommandointerpret
' ---------------------------------------------- Venatrix-Plexus
gc#a_VexPut: plx_put_vex 'Register im Venatrix-Plexus schreiben
gc#a_VexGet: plx_get_vex 'Register im Venatrix-Plexus lesen
' ---------------------------------------------- Funktionsgenerator
gc#a_StartFunctionGenerator: plx_startgenerator
gc#a_StopFunctionGenerator: plx_stopgenerator
gc#a_PulseWidth: signal.setPulseWidth(sub_getlong)
gc#a_Frequency_HZ: signal.setFrequency(sub_getlong)
gc#a_Frequency_Centihz: signal.setFrequencyCentiHertz(sub_getlong)
gc#a_SetWaveform: signal.setWaveform(bus_getchar)
gc#a_SetDampLevel: signal.setDampLevel(sub_getlong)
gc#a_SetParameter: signal.setParameters(bus_getchar, sub_getlong, sub_getlong, sub_getlong)
#endif '__ADM_PLX
' ---------------------------------------------- WAV-FUNKTIONEN
@ -702,6 +714,8 @@ PRI init_chip | err,i,j 'chip: initialisierung d
'plx-bus initialisieren
plx.init 'defaultwerte setzen, poller-cog starten
plx.run 'plexbus freigeben (poller läuft)
FunctionGenerator:=0 'Funktionsgenerator aus
#endif '__ADM_PLX
#ifdef __ADM_LAN
@ -2379,6 +2393,11 @@ CON ''------------------------------------------------- PLX-Funktionen
#ifdef __ADM_PLX
VAR
byte FunctionGenerator 'On/Off Marker Funktionsgenerator
PRI plx_in | addr 'port einlesen
addr := bus_getchar
@ -2458,6 +2477,27 @@ PRI plx_get_vex | reg, addr 'Register im Venatrix-Pl
addr := bus_getchar 'device-adresse empfangen
bus_putchar(plx.vexget(reg,addr))
PRI plx_startgenerator
ifnot FunctionGenerator
#ifdef __ADM_SID
sid1.stop
sid2.stop
#endif '__ADM_SID
signal.start(gc#A_SOUNDL, gc#A_SOUNDR, 32)
FunctionGenerator:=1
PRI plx_stopgenerator
if FunctionGenerator
signal.stop
#ifdef __ADM_SID
'SID soundsystem initialisieren
sidreg1 := sid1.start(gc#A_SOUNDL,0) 'erste sidcog starten, adresse der register speichern
waitcnt(cnt+(clkfreq>>8)) '
sidreg2 := sid2.start(gc#A_SOUNDR,0) 'zweite sidcog starten
#endif '__ADM_SID
FunctionGenerator:=0
CON ''------------------------------------------------- End of DCF77 FUNCTIONS

View File

@ -0,0 +1,189 @@
{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Propeller Signal Generator v1.2 (C) 2012 Johannes Ahlebrand │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ TERMS OF USE: Parallax Object Exchange License │
├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
│is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}
CON MUTE = 14, SAW = 16, TRIANGLE = 18, SQUARE = 22, NOISE = 25, SINE = 32, USER = 42, PW50 = 1<<31, PW25 = 1<<30, PW12_5 = 1<<29, freqRef = 536870912
VAR
byte cog
long waveform, frequency, damplevel, pulseWidth, userWaveformP, userWaveformSize
PUB start(outPin, invertedPin, syncPin)
' ┌──────────────────────────────────────────────────────────────┐
' │ Starts PSG in a single cog │
' ├──────────────────────────────────────────────────────────────┤
' │ outPin - The pin to output the signal on │
' │ invertedPin - The pin to output the inverted signal on │
' │ syncPin - The pin to output the synchronization signal on│
' └──────────────────────────────────────────────────────────────┘
stop
waveform := MUTE
regCounter := $1C000000 | outPin | (invertedPin<<9)
noiseValue := $10000000 '| syncPin
delayLine := (1<<invertedPin) | (1<<outPin) '| (1<<syncPin)
cog := cognew(@PSG, @waveform) + 1
PUB stop
' ┌──────────────────────────────────────────────────────────────┐
' │ Stops PSG │
' └──────────────────────────────────────────────────────────────┘
if cog
cogstop(cog~ -1)
cog := 0
PUB setWaveform(waveformType)
' ┌──────────────────────────────────────────────────────────────┐
' │ Set waveform type │
' ├──────────────────────────────────────────────────────────────┤
' │ waveformType - Which waveform from the list below to use │
' │ │
' │ #MUTE = No signal │
' │ #SAW = Saw wave │
' │ #TRIANGLE = Triangle wave │
' │ #SQUARE = Square wave │
' │ #NOISE = Noise wave │
' │ #SINE = Sine wave │
' │ #USER = User definable waveform │
' └──────────────────────────────────────────────────────────────┘
waveform := waveformType
PUB setFrequency(freq)
' ┌──────────────────────────────────────────────────────────────┐
' │ Set frequency │
' ├──────────────────────────────────────────────────────────────┤
' │ freq - The frequency in hertz (0 Hz to 7500000 Hz) │
' └──────────────────────────────────────────────────────────────┘
setFrequencyCentiHertz(freq * 100)
PUB setFrequencyCentiHertz(freq)
' ┌──────────────────────────────────────────────────────────────┐
' │ Set frequency │
' ├──────────────────────────────────────────────────────────────┤
' │ freq - The frequency in centi hertz (0 Hz to 750000000 cHz) │
' └──────────────────────────────────────────────────────────────┘
frequency := freqRef / (1000000000 / freq)
PUB setPulseWidth(pulseWidthVal)
' ┌──────────────────────────────────────────────────────────────┐
' │ Set the pulse width (square only) │
' ├──────────────────────────────────────────────────────────────┤
' │ pulseWidthVal - The 32 bit pulse width value │
' │ │
' │ Predefined pulse widths │
' │ ─────────────────────── │
' │ #PW50 = 50% (1<<31) │
' │ #PW25 = 25% (1<<30) │
' │ #PW12_5 = 12.5% (1<<29) │
' └──────────────────────────────────────────────────────────────┘
pulseWidth := pulseWidthVal
PUB setDampLevel(dampLev)
' ┌──────────────────────────────────────────────────────────────┐
' │ Set damp level │
' ├──────────────────────────────────────────────────────────────┤
' │ dampLev - The damp level (Each step equals 6 dB) │
' └──────────────────────────────────────────────────────────────┘
damplevel := dampLev
PUB setUserWaveform(address, size)
' ┌──────────────────────────────────────────────────────────────┐
' │ Set user definable waveform │
' ├──────────────────────────────────────────────────────────────┤
' │ address - The address to the waveform in memory │
' │ size - The size of the waveform (2^size) │
' └──────────────────────────────────────────────────────────────┘
userWaveformP := address
userWaveformSize := 31 - size
PUB setParameters(waveformType, frequencyInHertz, dampLev, pulseWidthValue)
' ┌──────────────────────────────────────────────────────────────┐
' │ A convenient method to set all parametes at once │
' └──────────────────────────────────────────────────────────────┘
setWaveform(waveformType)
setFrequency(frequencyInHertz)
setPulseWidth(pulseWidthValue)
setDampLevel(dampLev)
DAT org 0
PSG mov ctra, regCounter
out mov ctrb, noiseValue
waitCounter mov dira, delayLine
'───────────────────────────────────────────────────────────
mainLoop cmp :par, stopValue wz
if_z movd :par, #waveform_
if_z mov regCounter, par
:par rdlong waveform_ + 6, regCounter
add :par, val512
add regCounter, #4
sar out, damplevel_
add out, dcOffset
mov frqa, out
mov frqb, frequency_
jmp waveform_
'───────────────────────────────────────────────────────────
Mute_ mov out, #0
jmp #mainLoop
Saw_ mov out, phsb
jmp #mainLoop
Triangle_ absneg out, phsb
shl out, #1 wc
sub out, dcOffset
jmp #mainLoop
Square_ sub pulseWidth_, phsb nr, wc
negc out, maxAmplitude
jmp #mainLoop
Noise_ mov out, noiseValue
mov delayLine, phsb nr, wc
rcr delayLine, #16
cmp delayLine, cmpVal wz
if_z add noiseValue, cnt
if_z ror noiseValue, noiseValue
jmp #mainLoop
Sine_ mov out, phsb wc
shr out, #19
test out, sin_90 wz
negnz out, out
or out, sin_table
shl out, #1
rdword out, out
negc out, out
shl out, #15
jmp #mainLoop
User_ mov out, phsb
shr out, userWaveformSize_
add out, userWaveformP_
rdword out, out
shl out, #16
jmp #mainLoop
'───────────────────────────────────────────────────────────
stopValue rdlong waveform_ + 6, regCounter
sin_90 long $0800
sin_table long $E000>>1
cmpVal long $FFFF
dcOffset long 1<<31
maxAmplitude long(1<<31)-1
val512 long 1<<9
regCounter long 1
noiseValue long 1
delayLine long 1
waveform_ res 1
frequency_ res 1
damplevel_ res 1
pulseWidth_ res 1
userWaveformP_ res 1
userWaveformSize_ res 1

View File

@ -329,8 +329,22 @@ A_BLT = %00000000_00000000_00001000_00000000
a_s_beep
a_s_dmpreg '199 'soundinformationen senden
' ---------------------------------------------- Eigene Erweiterungen
' 200 ... 254 frei für eigene Erweiterungen
' ############################################## mehrfach verwendete Funktionen
' 200 ... 254 können mehrfach verwendet,
' dürfen aber nur einmal
' eingebunden werden
' ---------------------------------------------- Funktionsgenerator
#210, a_startFunctionGenerator
a_stopFunctionGenerator
a_PulseWidth
a_Frequency_HZ
a_Frequency_Centihz
a_SetWaveform
a_SetDampLevel
a_SetUserWaveform
a_setParameter
CON 'BELLATRIX-FUNKTIONEN --------------------------------------------------------------------------