⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sinwavegen.asm

📁 差分方程法实现信号产生的特点和原理
💻 ASM
字号:
;
;	======== ToneGen.asm ========
		.title		"Sine Wave Generator"
		.mmregs
		.data	                    ; starting address for this section is
		                            ; 300h in Data Space
;
;	======== COEFFS ========
;   The table that follows supplies the coefficients and intial
;  	conditions for the difference equation of the digital sinusoidal
;	oscillator.
;
;	The basic formulas for a second-order digital sinusoidal oscillator
;	are:
;		Difference Equation:	y(n)  = coeff*y(n-1) - y(n-2)
;		Initial Conditions:		y(-1) = 0
;								y(-2) = -A*sin(w0)
;		where
;								coeff = 2*cos(w0)
;								w0    = 2pi*f/fs
;		and
;								A  = desired amplitude of sine wave
;								f  = desired frequency of sine wave
;								fs = sampling frequency
;
;		For more on Digital Sinusoidal Oscillators see:
;
;		Proakis, J., Manolakis, D. (1988) Introduction to Digital Signal
;		Processing, pp. 373-376, MacMillan, New York.
;
;
;	Due to the algorithm used to generate the sine wave data the formulas
;	for the coefficient and the intial conditions change slightly.  They
;	become:
;		coeff = cos(w0)*32768
;		y(-2) = -A*sin(w0)*32768
;
;	The format of the sections that follow are:
;		.word		coeff		;where coeff = cos(w0)*32768
;		.word		y(-1)		;where y(-1) = 0
;		.word		y(-2)		;where y(-2) = -A*sin(w0)*32768
;
;	Each section starts with a comment stating which values were used
;	for A, f, and fs, followed by the three calculated values of coeff
;	y(-1) and y(-2).  It is important to note that only one section can
;   be used (un-commented) at a time.
;
;
; NOTE:
;   It is extemely important that when the Interrupt Mask register is setup
;   that the TXRXINT interrupt (for the Async Serial Port) be enabled in 
;   addition to any interrupts being used by the user's program.  If the
;   TXRXINT is not enabled then the monitor program will not function properly.
;
;   Just uncomment a set of COEFFS to use them in your calculations.
;   Default COEFFS are for a 1kHz sine wave

COEFFS	; for f = 500Hz, A = .25, fs = 16000
 		.word		32138
		.word		0
		.word		-1598

;COEFFS	; for f = 1kHz, A = .25, fs = 16000
; 		.word		30274
;		.word		0
;		.word		-3135

;COEFFS	; for f = 1.5kHz, A = .25 fs = 16000
; 		.word		27246
;		.word		0
;		.word		-4551

;COEFFS	; for f = 2kHz, A = .25 fs = 16000
; 		.word		23170
;		.word		0
;		.word		-5793

;COEFFS	; for f = 2.5kHz, A = .25 fs = 16000
; 		.word		18205
;		.word		0
;		.word		-6811

;COEFFS	; for f = 3kHz, A = .25 fs = 16000
; 		.word		12540
;		.word		0
;		.word		-7568

;COEFFS	; for f = 3.5kHz, A = .25 fs = 16000
; 		.word		6393
;		.word		0
;		.word		-8035

;COEFFS	; for f = 4kHz, A = .25 fs = 16000
; 		.word		0
;		.word		0
;		.word		-8192

;COEFFS	; for f = 4.5kHz, A = .25 fs = 16000
; 		.word		-6393
;		.word		0
;		.word		-8035

;COEFFS	; for f = 5kHz, A = .25 fs = 16000
; 		.word		-12540
;		.word		0
;		.word		-7568

;COEFFS	; for f = 5.5kHz, A = .25 fs = 16000
; 		.word		-18205
;		.word		0
;		.word		-6811

;COEFFS	; for f = 6kHz, A = .25 fs = 16000
; 		.word		-23170
;		.word		0
;		.word		-5793

;COEFFS	; for f = 6.5kHz, A = .25 fs = 16000
; 		.word		-27246
;		.word		0
;		.word		-4551

;COEFFS	; for f = 7kHz, A = .25 fs = 16000
; 		.word		-30274
;		.word		0
;		.word		-3135

;COEFFS	; for f = 7.5kHz, A = .25 fs = 16000
; 		.word		-32138
;		.word		0
;		.word		-1598
;
;	======== vectors ========
;
	.sect	"vectors"
		b	start                   
		b	0000h                   ;02; restart the monitor
		b	0000h                   ;04; restart the monitor
		b   0000h                   ;06; restart the monitor
		b	0000h                   ;08; restart the monitor
		b	xmitIsr                 ;0a; restart the monitor
		b	0000h                   ;0c; restart the monitor
		.space 2*16                 ;0e; Reserved Space
		b	0000h                   ;10; restart the monitor
		b	0000h                   ;12; restart the monitor
		b	0000h                   ;14; restart the monitor
		b	0000h                   ;16; restart the monitor
		b	0000h                   ;18; restart the monitor
		b	0000h                   ;1a; restart the monitor
		b	0000h                   ;1c; restart the monitor
		b	0000h                   ;1e; restart the monitor
		b	0000h                   ;20; restart the monitor
		b	0000h                   ;22; restart the monitor
		b	0000h                   ;24; restart the monitor
		.space 2*16                 ;26; Reserved Space
		b	0000h                   ;28; restart the monitor
		b	0000h                   ;2a; restart the monitor
		b	0000h                   ;2c; restart the monitor
		b	0000h                   ;2e; restart the monitor
		b	0000h                   ;30; restart the monitor
		b	0000h                   ;32; restart the monitor
		b	0000h                   ;34; restart the monitor
		b	0000h                   ;36; restart the monitor
		b	0000h                   ;38; restart the monitor
		b	0000h                   ;3a; restart the monitor
		b	0000h                   ;3c; restart the monitor
		b	0000h                   ;3e; restart the monitor
;
;	======== start ========
;
	        .text
start:	setc	intm	; INTM = 1, disable global interrupts
		clrc	cnf		; CNF = 0,  map DARAM to data space (0x200-0x2ff)
		setc	sxm		; SXM = 1, use sign extension mode
		clrc	ovm		; OVM = 0, results overflow normally in accumulator
		spm		1		; set ALU to handle fractional multiplication
		ldp		#06h    ; use the DARAM block with Direct Addressing

;	======== xmitIsr ========
;
	lar		ar3, #900h
xmitIsr:  
		ldp		#06h				; set data page pointer
	; start calculating sine wave data
		lar		ar0, #(COEFFS+2)	; ar0 = COEFFS+2
		lar		ar2, #0000h			; ar2 = 0
		mar		*, ar2				; ARP = ar2
		lacc	#0					; acc = 0
		mar		*0+					; ar2 += ar0
		sub		*-, 15				; ah = -(1/2)*y(n-2)
		dmov	*					; y(n-2) = y(n-1)
		lt		*-					; TREG = y(n-1)
		mpy		*+					; PREG = coeff*y(n-1)
		apac						; ah = coeff*y(n-1) - (1/2)*y(n-2)
		sfl							; ah = 2*coeff*y(n-1) - (1/2)*y(n-2)
		sach	*,ar3				; y(n-1) = ah
		sach	*+                  ; y(n)
	    lar		ar0,#1000h   
	    cmpr	01		            ; AR(arp)<ar0? Y:TC=1
	    bcnd	xmitIsr,TC
loop:	nop      					; enter loop and allow DSP to process
		b		loop		    	; XINT interrupts
		ret							; return to caller
		.end						; signify end of program

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -