NEW DATABASE - 350 MILLION DATASHEETS FROM 8500 MANUFACTURERS
TMS320F240 SPRA418 TMS320 000000FA INT10 INT11 INT12 INT13 INT14 INT15 INT16 - Datasheet Archive
Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 EVM APPLICATION REPORT: SPRA418 David Figoli Digital
EVM Application #9 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM APPLICATION REPORT: SPRA418 SPRA418 David Figoli Digital Signal Processing Solutions January 1999 IMPORTANT NOTICE Texas Instruments and its subsidiaries (TI) reserve the right to make changes to their products or to discontinue any product or service without notice, and advise customers to obtain the latest version of relevant information to verify, before placing orders, that information being relied on is current and complete. All products are sold subject to the terms and conditions of sale supplied at the time of order acknowledgement, including those pertaining to warranty, patent infringement, and limitation of liability. TI warrants performance of its semiconductor products to the specifications applicable at the time of sale in accordance with TI's standard warranty. Testing and other quality control techniques are utilized to the extent TI deems necessary to support this warranty. Specific testing of all parameters of each device is not necessarily performed, except those mandated by government requirements. CERTAIN APPLICATIONS USING SEMICONDUCTOR PRODUCTS MAY INVOLVE POTENTIAL RISKS OF DEATH, PERSONAL INJURY, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE ("CRITICAL APPLICATIONS"). TI SEMICONDUCTOR PRODUCTS ARE NOT DESIGNED, AUTHORIZED, OR WARRANTED TO BE SUITABLE FOR USE IN LIFE-SUPPORT DEVICES OR SYSTEMS OR OTHER CRITICAL APPLICATIONS. INCLUSION OF TI PRODUCTS IN SUCH APPLICATIONS IS UNDERSTOOD TO BE FULLY AT THE CUSTOMER'S RISK. In order to minimize risks associated with the customer's applications, adequate design and operating safeguards must be provided by the customer to minimize inherent or procedural hazards. TI assumes no liability for applications assistance or customer product design. TI does not warrant or represent that any license, either express or implied, is granted under any patent right, copyright, mask work right, or other intellectual property right of TI covering or relating to any combination, machine, or process in which such semiconductor products or services might be or are used. TI's publication of information regarding any third party's products or services does not constitute TI's approval, warranty, or endorsement thereof. Copyright © 1999, Texas Instruments Incorporated TRADEMARKS TI is a trademark of Texas Instruments Incorporated. Other brands and names are the property of their respective owners. CONTACT INFORMATION US TMS320 TMS320 HOTLINE (281) 274-2320 US TMS320 TMS320 FAX (281) 274-2324 US TMS320 TMS320 BBS (281) 274-2323 US TMS320 TMS320 email dsph@ti.com Contents Abstract . 7 Product Support. 8 World Wide Web . 8 Email. 8 Overview. 9 Module(s) Used. 9 Input . 9 Output . 9 Background and Methodology. 10 SCI Module . 10 Interpreting Transmitted ASCII Values . 11 Frequency Manipulation . 13 Phase Manipulation. 14 Magnitude Manipulation . 15 EVM Application #9 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM Abstract This application report explains how the EVM Application #9 creates a 2 channel sine wave generator using the 12 bit digitalto-analog converter (DAC) of the Texas Instruments (TITM) TMS320F240 TMS320F240 Evaluation Module (EVM). The document contains: G G G G G An overview that includes information on the commands that control the sine waves Information on each of the three modules used Details on how to interpret transmitted ASCII values Commands to modify the frequency, magnitude and phase difference of the DAC0 and DAC1 channels of the sine wave generator The C2xx Assembly code which implements the application Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 7 SPRA418 SPRA418 Product Support World Wide Web Our World Wide Web site at www.ti.com contains the most up to date product information, revisions, and additions. Users registering with TI&ME can build custom information pages and receive new product updates automatically via email. Email For technical issues or clarification on switching products, please send a detailed email to dsph@ti.com. Questions receive prompt attention and are usually answered within one business day. 8 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 Overview This application creates a 2 channel sine wave generator using the 12 bit digital-to-analog converter (DAC) of the TI TMS320F240 TMS320F240 EVM. The generator modifies the frequency of the sine waves, the phase difference between the two waves, and the magnitude (peak to peak) of the waves according to a user's input commands. Each channel of the sine wave generator is controlled using a terminal program (e.g., Windowsâ Terminal.exe) that uses a serial port to communicate with the serial port of the EVM. The serial port allows the frequency and magnitude of each channel to be controlled and the phase difference between the sine waves to be changed by entering commands in the terminal. The commands control the sine waves: First Letter Second Letter Third Value (if a or b) f - frequency change m - magnitude change p - phase change a - DAC0 Sine wave xxxx - value b - DAC1 Sine wave r - reset to initial values - enter needs to be pressed after each command The application is implemented using C2xx Assembly code. Module(s) Used G G G Event Manager module General Purpose Timer 1 SCI module Input PC serial port (SCI) Output DAC0OUT DAC1OUT Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 9 SPRA418 SPRA418 Background and Methodology The implementation of a dual channel sine wave generator with the DAC controlled via a terminal program is a modification of Application #3 (DAC0.ASM). To control the sine waves of the DAC through the serial port of the EVM, the SCI module of the F240 needs to be used. The sine wave values can be controlled using a terminal program and connecting the serial port of the EVM to the serial port of a PC. The sine waves in this application are created using the same method described in Application #3. The sine waves are generated using the modulo counting register, interpolation, and a 256 point sine look up table. A rolling 16 bit counter is used to determine the location of the value to be placed in the DAC. A step value is added to the counter every time a new value from the sine table is to be loaded. By changing the value of the step, one can reasonably control the frequency of the sine wave. However, to be able to calculate the frequency that will be produced, a "sampling" method is used as in the previous application. The "sampling" is accomplished using a polling routine. A value is set in the period register of GP Timer 1. Because the flags of the interrupt register in the Event Manager are set regardless of whether the interrupts are masked or unmasked, the flag register can be watched until the period flag is set. Once the period flag is set, then the program can determine the next value to load into the output register of the DAC. Once the values have been updated, then the flag register is cleared, and the program returns to the polling routine to await for the next flag to be set. Since a polling routine is used for the Event Manager module, only one interrupt routine needs to be made to service interrupts generated by the SCI module of the F240. SCI Module The SCI module of the F240 uses SYSCLK to derive its own clock, as a result, one needs to know the settings of the PLL module. By knowing what the PLL module is set up to generate, then baud rate of the SCI module can be selected. In this application the PLL generates a CPUCLK of 20MHz and a SYSCLK of 10MHz. 10 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 Since the controls for the sine waves will only be ASCII (7 bits) values, the data stream of the SCI can be set up to use 7 character bits, 1 stop bit, and odd parity. The SCI is set up to be able to receive and transmit data to the terminal using the internal clock as its clock source. Additionally, since the receiving of data is what causes the program to change the values in the sine registers, the receive interrupt is enabled whereas, the transmit interrupt is disabled. The baud rate of the SCI is set to 19200.1 Interpreting Transmitted ASCII Values The values transmitted to the DSP are the corresponding ASCII values for each character entered into the terminal. Before the interpretation of the ASCII values can be performed, certain design aspects need to be considered before the algorithm can be developed. In this application, all entries are terminated by a carriage return (ASCII value - 0Dh). As a result, the values that are entered into the terminal need to be stored into a memory location until the carriage return is entered into the terminal. As a result, before anything is stored into the buffer, it is cleared to null values (ASCII value - 00h). Once the buffer is cleared, then the data from the terminal can be input. When a carriage return is entered, then the program starts interpreting the input values. The first value that can be input is either an `f', `m', or `p'. The entered values can either be lowercase or uppercase because the program is case insensitive. The ASCII values for `f', `m', and `p', are 66h, 6Dh, and 70h respectively. The program changes the case of the values to `F' (46h), `M' (4Dh), and `P' (50h), by ANDing the input ASCII values with 5Fh. To prevent changing the values of the input numbers with the AND operation, the AND operation is only performed on values that have a 1 in the 6th bit position. If the value is a 1 then the ASCII equivalent is a letter, if the value is a 0 then the ASCII equivalent is a terminal command of a number. 1 Note: The SCI configuration should not be set or altered unless the SW RESET bit is cleared. Set up all configuration registers before setting SW RESET; otherwise, unpredictable behavior can occur. Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 11 SPRA418 SPRA418 Once the first value is interpreted by the program, the appropriate routine is executed to modify the frequency, phase, or magnitude. If the first value is not a valid input value, then the routine terminates, outputs an error message, and awaits another for another carriage return to interpret another set of input data from the terminal. If the first value is a valid value, then the next value is interpreted to determine which sine value to manipulate. Once the first two values have been processed, the remaining values are numerical. Input value: fb250 f Input buffer: b 2 5 0 0066 0062 0032 F 2 0 0035 0030 000d 0030 000d AND with 5F Input buffer: B 0046 5 0042 0032 0035 In ASCII, the character values that correspond to 30h to 39h are the numbers 0 to 9. As a result, to convert the ASCII values, 30h needs to be subtracted. Once the ASCII values have been converted to digits, then the actual input number value can be determined. To convert the values, a routine multiplies a digit by 10 and then adds the next digit; this process continues until a carriage return is encountered. Once the carriage return is encountered, the input value has been completely converted from the input decimal value to the equivalent hexadecimal value. ACC (hex) Next Digit x10 00000000 2 00000000 00000002 00000002 5 00000014 00000019 00000019 0 + Next Digit 000000FA 000000FA 000000FA 000000FA 000000FA 000000FA FAh = 250 12 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 This application uses the same equations as Application #3 to determine the value to load into the appropriate registers with values to control the sine waves. However, instead of entering the step value, displacement, and Q15 magnitude, the user can input the actual frequency, phase difference, and magnitude desired. Frequency Manipulation To modify the frequency of the DAC0 channel of the sine wave generator, the user enters fafrequency or fbfrequency to modify DAC1. The entered frequency should be in Hertz. The application uses the following equation to determine the step size that should be stored into the step registers of the sine waves. step = f (TS ´ 2 n ) where f = desired frequency TS = the period of the frequency at which the DAC register values are updated step = the step increment that is added to the counter to change the frequency n = the number of bits in the counting register To return the sine waves to the same frequency that the program started with, the user should enter fr In this application, the value for TS is equivalent to the Q15 value 0001h. The smallest Q15 value was chosen to allow for the greatest range of allowable steps that can be used for manipulating the frequencies. A Q15 period of 0001h seconds equates to a 0.000031 second period which is 32.768kHz. As a result, the timers in the Event Manager are set up to update the DAC values at a rate of 32.768kHz. Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 13 SPRA418 SPRA418 Once the input value is converted, the input value is multiplied by 0001h and 216 to obtain the step value. Once the step value is obtained, the value is loaded into the appropriate channel and the program resumes back to the main line. Phase Manipulation To modify the phase difference between DAC0 and DAC1 of the sine wave generator, the user enters paphase or pbphase The entered phase should be in degrees. The designation after the p(a or b), determines which sine wave will lead. If a is entered, then DAC0 will lead DAC1 by phase degrees; the same applies to if b is entered. Once the value for the phase difference has been converted from the input value from the terminal, the converted phase in hex is checked to make sure it is an angle between 0 to 360 degrees. If the value is in between 0 and 360 degrees, then the program continues, if the value is outside the range, then the routine ends and nothing is changed. To determine the offset value between the two registers, the input phase is divided by 360 degrees and then multiplied by 216. (Refer to Application #8 about division). The channel that is chosen determines the register used. The calculated displacement is added to whichever channel is to lag, and the new value is loaded into the channel that is supposed to lead. To calculate the displacement value to load into the modulo register of the corresponding sine wave, the program uses the following formula d (f ) = f ´ 2n 360° where d(B) = displacement value for the modulo counter register B = desired phase difference in degrees n = number of bits in the counter register 14 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 To return the sine waves to a phase difference of 0 degrees, the user should enter pr. Magnitude Manipulation To modify the magnitude of the sine waves output on DAC0 and DAC1, the user enters mamagnitude or mbmagnitude. The entered peak to peak magnitude can only be in tenths of a volt. The value should be entered without the decimal point. For example, to obtain a 4.0Vpp value on DAC0, the user should enter ma40 Once the value for the magnitude has been converted from the input value from the terminal, the converted phase in hex is checked to make sure that the magnitude is between 0 and 50. If the value is inside the limits, then the program continues, if the value is outside the range, then the routine ends and nothing is changed. The value to load into the magnitude register is determined by the dividing the input value by 50 (See Application #8). The Q15 quotient is then multiplied by 215-1 (i.e. the most positive Q15 value). The resulting Q15 value is then stored into the appropriate sine wave's magnitude register. The following formula provides the value to be used in the magnitude register of the appropriate sine wave. A( m) = m ´ (2 Q - 1) 50 where A(m) = value for the magnitude register m = desired peak to peak voltage Q = Q format used (e.g. 16 bit word size, Q = 15) To return the sine waves to a 5Vpp magnitude, the user should enter mr. Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 15 SPRA418 SPRA418 Examples of input commands: fa100 fb600 fr ma35 mb23 mr pa45 pb60 pr Sets DAC0 sine wave to 100Hz Sets DAC1 sine wave to 600Hz Resets DAC0 and DAC1 to original value 500Hz Sets DAC0 sine wave Vpp to 3.5 volts Sets DAC1 sine wave Vpp to 2.3 volts Resets DAC0 and DAC1 to Vpp of 5V maximum magnitude = 50 = 5.0Vpp Sets DAC0 sine wave to lead by 45 degrees Sets DAC1 sine wave to lead by 60 degrees Resets DAC0 and DAC1 so phase difference is 0 degrees maximum phase difference = 360 Since the SCI is used to modify the values in the registers that control the sine waves and because the program uses an interrupt to update the values, the program can be run and modified indefinitely. 16 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 ;* ; File Name: scidac0.asm ; Originator: Digital control systems Apps group - Houston ; Target System: 'C24x Evaluation Board ; ; Description: Outputs 2 Sine Waves on the EVM DAC - DAC0 and DAC1 ; Sine waves generated through a look up table and ; interpolation. ; ; The sine waves can be controlled through the ; computer by using a terminal program that uses the ; serial port of the computer to communicate with the ; DSP through the EVM's serial port. ; ; To control the sine waves, the terminal program ; needs to be set to a baud rate of 19200, 1 stop ; bit, 7 character bits, and odd parity. ; ; Entering the following commands will allow control ; over the sine waves ; ; First letter: ; f-frequency m-magnitude p-phase ; Second letter: ; a-DAC0 sine wave b-DAC1 sine wave r-reset to ; initial value ; If second letter is an a or b: ; xxxx-value ; -enter needs to be pressed after each command ; ; Examples: ; ; fa100 - Sets DAC0 sine wave to 100Hz ; fb600 - Sets DAC1 sine wave to 600Hz ; fr - Resets DAC0 and DAC1 to original value - 500Hz ; ; ma35 - Sets DAC0 sine wave Vpp to 3.5 volts ; mb23 - Sets DAC1 sine wave Vpp to 2.3 volts ; mr - Resets DAC0 and DAC1 to Vpp of 5V ; maximum magnitude = 50 = 5.0Vpp ; ; pa45 - Sets DAC0 sine wave to lead by 45 degrees ; pb60 - Sets DAC1 sine wave to lead by 60 degrees ; pr - Resets DAC0 and DAC1 so phase difference is 0 ; degrees ; maximum phase difference = 360 ; ; Last Updated: 9 July 1997 ; ;* .include f240regs.h ;* ; File Name: TMS320x240 SCI Idle-line Mode Example Code Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 17 SPRA418 SPRA418 ; ; Description: This program uses the SCI module to implement a ; simple asynchronous communications routine. The SCI is ; initialized to operate in idle-line mode with 7 character ; bits, 1 stop bit, and odd parity. The SCI Baud Rate ; Registers (BRR) are set to transmit and receive data at ; 19200 baud. The SCI generates an interrupt every time a ; character is loaded into the receive buffer (SCIRXBUF). ; The interrupt service routine(ISR) reads the receive ; buffer and determines if the carriage return button, , ; has been pressed. If so, the character string "Ready" is ; transmitted. If not, no character string is transmitted. ;* ;-; I/O Mapped EVM Registers ;-DAC0 .set 0000h ;Input Data Register for DAC0 DAC1 .set 0001h ;Input Data Register for DAC1 DAC2 .set 0002h ;Input Data Register for DAC2 DAC3 .set 0003h ;Input Data Register for DAC3 DACUPDATE .set 0004h ;DAC Update Register ;-; Constant definitions ;-LENGTH1 .set 00007h ;Length of the data stream to be ;transmitted LENGTH2 .set 16 ;-; Variable definitions ;-; bss DATA_OUT,LENGTH ;Location of LENGTH byte character ;stream to be transmitted .bss GPR0,1 ;General purpose register. .bss DAC0VAL,1 ;DAC0 Channel Value .bss DAC1VAL,1 ;DAC1 Channel Value .bss DAC2VAL,1 ;DAC2 Channel Value .bss DAC3VAL,1 ;DAC3 Channel Value ;-; Initialized Transmit Data for Interrupt Service Routine ;-.data READY .word 0052h ;Hex equivalent of ASCII character 'R' .word 0065h ;Hex equivalent of ASCII character 'e' .word 0061h ;Hex equivalent of ASCII character 'a' .word 0064h ;Hex equivalent of ASCII character 'd' 18 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 .word 0079h ;Hex equivalent of ASCII character 'y' .word .word INVALID_IP 000dh 0000h ;Hex equivalent of ASCII ;Hex equivalent of ASCII NULL .word 000ah ;Hex equivalent of ASCII (NEW LINE) .word 0049h ;Hex equivalent of ASCII character 'I' .word .word .word .word .word .word .word .word .word .word .word .word .word .word 006Eh 0076h 0061h 006Ch 0069h 0064h 0020h 0069h 006Eh 0070h 0075h 0074h 000dh 0000h ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent of ;Hex equivalent ASCII character ASCII character ASCII character ASCII character ASCII character ASCII character ASCII (SPACE) ASCII character ASCII character ASCII character ASCII character ASCII character ASCII of ASCII NULL 'n' 'v' 'a' 'l' 'i' 'd' 'i' 'n' 'p' 'u' 't' ;-; Vector address declarations ;-.sect ".vectors" RSVECT B START ; PM 0 Reset Vector 1 INT1 B INT1_ISR ; PM 2 Int level 1 4 INT2 B PHANTOM ; PM 4 Int level 2 5 INT3 B PHANTOM ; PM 6 Int level 3 6 INT4 B PHANTOM ; PM 8 Int level 4 7 INT5 B PHANTOM ; PM A Int level 5 8 INT6 B PHANTOM ; PM C Int level 6 9 RESERVED B PHANTOM ; PM E (Analysis Int) 10 SW_INT8 B PHANTOM ; PM 10 User S/W int SW_INT9 B PHANTOM ; PM 12 User S/W int SW_INT10 INT10 B PHANTOM ; PM 14 User S/W int SW_INT11 INT11 B PHANTOM ; PM 16 User S/W int SW_INT12 INT12 B PHANTOM ; PM 18 User S/W int SW_INT13 INT13 B PHANTOM ; PM 1A User S/W int SW_INT14 INT14 B PHANTOM ; PM 1C User S/W int SW_INT15 INT15 B PHANTOM ; PM 1E User S/W int SW_INT16 INT16 B PHANTOM ; PM 20 User S/W int TRAP B PHANTOM ; PM 22 Trap vector NMINT B PHANTOM ; PM 24 Non maskable Int 3 EMU_TRAP B PHANTOM ; PM 26 Emulator Trap 2 SW_INT20 INT20 B PHANTOM ; PM 28 User S/W int SW_INT21 INT21 B PHANTOM ; PM 2A User S/W int SW_INT22 INT22 B PHANTOM ; PM 2C User S/W int SW_INT23 INT23 B PHANTOM ; PM 2E User S/W int ;= ; M A I N C O D E - starts here ;= Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 19 SPRA418 SPRA418 START: SPLK SETC .text NOP INTM CLRC SXM CLRC OVM CLRC CNF #0001h,IMR LACC ACL IFR IFR ;Disable interrupts ;Clear Sign Extension Mode ;Reset Overflow Mode ;Config Block B0 to Data mem. ;Mask all core interrupts except ;INT1 ;Read Interrupt flags ;Clear all interrupt flags LDP #00E0h SPLK #006Fh, WDCR ;Disable Watchdog if VCCP=5V KICK_DOG ;Reset Watchdog counter ;= ; Initialize B2 RAM to zero's. ;= LAR AR2,#B2_SADDR ;AR2 -> B2 start address MAR *,AR2 ;Set ARP=AR2 ZAC ;Set ACC = 0 RPT #1fh ;Set repeat cntr for 31+1 loops SACL *+ ;Write zeros to B2 RAM ;= ; Initialize B2 RAM to zero's. ;= LAR AR2,#B0_SADDR ;AR2 -> B2 start address MAR *,AR2 ;Set ARP=AR2 ZAC ;Set ACC = 0 RPT #255 ;Set repeat cntr for 31+1 loops SACL *+ ;Write zeros to B2 RAM ;= ; Initialize B2 RAM to zero's. ;= LAR AR2,#B1_SADDR ;AR2 -> B2 start address MAR *,AR2 ;Set ARP=AR2 ZAC ;Set ACC = 0 RPT #255 ;Set repeat cntr for 31+1 loops SACL *+ ;Write zeros to B2 RAM ;= ; Initialize DATAOUT with data to be transmitted. ;= LAR AR2,#B1_SADDR ;Reset AR2 -> B1 start ;address RPT #(LENGTH1+LENGTH2-1);Set repeat counter for ;LENGTH1+LENGTH2 loops BLPD #READY,*+ ;loads B2 with TXDATA 20 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 ;= ; INITIALIZATION OF INTERRUPT DRIVEN SCI ROUTINE ;= SCI_INIT: LDP #00E0h SPLK #0036h,SCICCR ;1 stop bit, odd parity, 7 char ;bit ;async mode, idle-line protocol SPLK #0013h, SCICTL1 ;Enable TX, RX, internal ; SCICLK, ;Disable RX ERR, SLEEP, TXWAKE SPLK #0002h, SCICTL2 ;Enable RX INT,disable TX INT SPLK #0000h, SCIHBAUD SPLK #0040h, SCILBAUD ;Baud Rate=19200 b/s (10 MHz ;SYSCLK) SPLK #0022h, SCIPC2 ;Enable TXD & RXD pins SPLK #0033h, SCICTL1 ;Relinquish SCI from Reset. LAR LAR LAR AR0, #SCITXBUF ;Load AR0 with SCI_TX_BUF ;address AR1, #SCIRXBUF ;Load AR1 with SCI_RX_BUF ;address AR2, #B2_SADDR ;Load AR2 with TX data start ;address ;= ; INITIALIZATION OF PLL MODULE ;= LDP #00E0h ;The following line is necessary if a previous program set the PLL ;to a different setting than the settings which the application ;uses. By disabling the PLL, the CKCR1 register can be modified so ;that the PLL can run at the new settings when it is re-enabled. Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 21 SPRA418 SPRA418 SPLK #0000000001000001b,CKCR0 ;CLKMD=PLL Disable,SYSCLK=CPUCLK/2 ; 5432109876543210 SPLK #0000000010111011b,CKCR1 ;CLKIN(OSC)=10MHz,CPUCLK=20MHz ;CKCR1 - Clock Control Register 1 ;Bits 7-4 (1011)CKINF(3)-CKINF(0) - Crystal or Clock-In Frequency ; Frequency = 10MHz ;Bit 3 (1) PLLDIV(2) - PLL divide by 2 bit ; Divide PLL input by 2 ;Bits 2-0 (011) PLLFB(2)-PLLFB(0) - PLL multiplication ratio ; PLL Multiplication Ratio = 4 ; 5432109876543210 SPLK #0000000011000001b,CKCR0 ;CLKMD=PLL Enable,SYSCLK=CPUCLK/2 ;CKCR0 - Clock Control Register 0 ;Bits 7-6 (11 CLKMD(1),CLKMD(0) - Operational mode of Clock Module ; PLL Enabled; Run on CLKIN on exiting low ; power mode ;Bits 5-4 (00) PLLOCK(1),PLLOCK(0) - PLL Status. READ ONLY ; Bits 3-2 (00) PLLPM(1),PLLPM(0) - Low Power Mode ; LPM0 ;Bit 1 (0) ACLKENA - 1MHz ACLK Enable ; ACLK Disabled ;Bit 0 (1) PLLPS - System Clock Prescale Value ; f(sysclk)=f(cpuclk)/2 ; 5432109876543210 SPLK #0100000011000000b,SYSCR ;CLKOUT=CPUCLK ;SYSCR - System Control Register ;Bit 15-14 (01) RESET1,RESET0 - Software Reset Bits ; No Action ;Bits 13-8 (000000) Reserved ;Bit 7-6 (11) CLKSRC1,CLKSRC0 - CLKOUT-Pin Source Select ; CPUCLK: CPU clock output mode ;Bit 5-0 (000000) Reserved ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* ;- Event Manager Module Reset ;* ;This section resets all of the Event Manager Module Registers. ;* This is necessary for silicon revsion 1.1; however, for ;silicon revisions 2.0 and later, this is not necessary ;*;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 22 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 LDP SPLK #232 ;DP=232 Data Page for the Event Manager #0000h,GPTCON ;Clear General Purpose Timer SPLK SPLK SPLK #0000h,T1CON #0000h,T2CON #0000h,T3CON ;Clear GP Timer 1 Control ;Clear GP Timer 2 Control ;Clear GP Timer 3 Control SPLK SPLK #0000h,COMCON #0000h,ACTR ;Clear Compare Control ;Clear Full Compare Action SPLK ;Register #0000h,SACTR ;Clear Simple Compare Action SPLK ;Register #0000h,DBTCON ;Clear Dead-Band Timer Control SPLK #0000h,CAPCON ;Clear Capture Control SPLK SPLK SPLK #0FFFFh,EVIFRA ;Clear Interrupt Flag Register A #0FFFFh,EVIFRB ;Clear Interrupt Flag Register B #0FFFFh,EVIFRC ;Clear Interrupt Flag Register C SPLK #0000h,EVIMRA ;Clear Event Manager Mask SPLK #0000h,EVIMRB ;Clear Event Manager Mask SPLK #0000h,EVIMRC ;Clear Event Manager Mask Control Control Control Register Register A Register B Register C ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* ;End of RESET section for silicon revision 1.1 * ;*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* ;= ; INITIALIZATION OF EVENT MANAGER MODULE ;= T1COMPARE T1PERIOD .set .set 0 610 ;Compare value not necessary ;T1PERIOD set to value equivalent to ;32.768kHz with CPULCLK = 20MHz 0001h ;Q15 period value for period of ;32.768kHz QT1PERIOD .set LDP .text #232 ;DP=232, Data Page for Event Manager ;Addresses SPLK #T1COMPARE,T1CMPR ;Initialize GP Timer 1 Compare ;Register ; 2109876543210 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 23 SPRA418 SPRA418 SPLK #0000001010101b,GPTCON ;GPTCON - GP Timer Control Register ;Bit 15 (0) T3STAT - GP Timer 3 Status. READ ONLY ;Bit 14 (0) T2STAT - GP Timer 2 Status. READ ONLY ;Bit 13 (0) T1STAT - GP Timer 1 Status. READ ONLY ;Bits 12-11 (00) T3TOADC - ADC start by event of GP Timer 3 ; No event starts ADC ;Bits 10-9 (00) T2TOADC - ADC start by event of GP Timer 2 ; No event starts ADC ;Bits 8-7 (00) T1TOADC - ADC start by event of GP Timer 1 ; No event starts ADC ;Bit 6 (1) TCOMPOE - Compare output enable ; Enable all three GP timer compare outputs ;Bits 5-4 (01) T3PIN - Polarity of GP Timer 3 compare output ; Active Low ;Bits 3-2 (01) T2PIN - Polarity of GP Timer 2 compare output ; Active Low ;Bits 1-0 (01) T1PIN - Polarity of GP Timer 1 compare output ; Active Low SPLK Register SPLK SPLK SPLK #T1PERIOD,T1PR ; SPLK 5432109876543210 #0001000000000100b,T1CON #0000h,T1CNT #0000h,T2CNT #0000h,T3CNT ;Initialize GP Timer 1 Period ;Initialize GP Timer 1 ;Initialize GP Timer 2 ;Initialize GP Timer 3 ;T1CON - GP Timer 1 Control Register ;Bits 15-14 (00) FREE,SOFT - Emulation Control Bits ; Stop immediately on emulation suspend ;Bits 13-11 (010) TMODE2-TMODE0 - Count Mode ; Selection ; Continuous-Up Count Mode ;Bits 10-8 (000) TPS2-TPS0 - Input Clock Prescaler ; Divide by 1 ;Bit 7 (0) Reserved ;Bit 6 (0) TENABLE - Timer Enable ; Disable timer operations ;Bits 5-4 (00) TCLKS1,TCLKS0 - Clock Source Select ; Internal Clock Source ;Bits 3-2 (01) TCLD1,TCLD0 - Timer Compare Register Reload ; Condition ; When counter is 0 or equals period register ; value ;Bit 1 (0) TECMPR - Timer compare enable ; Disable timer compare operation ;Bit 0 (0) Reserved ; ; 5432109876543210 SPLK #0000000000000000b,T2CON ;Not Used 24 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 ;T2CON - GP Timer 2 Control Register ;Bits 15-14 (00) FREE,SOFT - Emulation Control Bits ; Stop immediately on emulation suspend ;Bits 13-11 (000) TMODE2-TMODE0 - Count Mode Selection ; Stop/Hold ;Bits 10-8 (000) TPS2-TPS0 - Input Clock Prescaler ; Divide by 1 ;Bit 7 (0) TSWT1 - GP Timer 1 timer enable bit ; Use own TENABLE bit ;Bit 6 (0) TENABLE - Timer Enable ; Disable timer operations ;Bits 5-4 (00) TCLKS1,TCLKS0 - Clock Source Select ; Internal Clock Source ;Bits 3-2 (00) TCLD1,TCLD0 - Timer Compare Register Reload ; Condition ; When counter is 0 ;Bit 1 (0) TECMPR - Timer compare enable ; Disable timer compare operation ;Bit 0 (0) SELT1PR - Period Register select ; Use own period register ; SPLK 5432109876543210 #0000000000000000b,T3CON ;Not Used ;T3CON - GP Timer 3 Control Register ;Bits 15-14 (00) FREE,SOFT - Emulation Control Bits ; Stop immediately on emulation suspend ;Bits 13-11 (000) TMODE2-TMODE0 - Count Mode Selection ; Stop/Hold ;Bits 10-8 (000) TPS2-TPS0 - Input Clock Prescaler ; Divide by 1 ;Bit 7 (0) TSWT1 - GP Timer 1 timer enable bit ; Use own TENABLE bit ;Bit 6 (0) TENABLE - Timer Enable ; Disable timer operations ;Bits 5-4 (00) TCLKS1,TCLKS0 - Clock Source Select ; Internal Clock Source ;Bits 3-2 (00) TCLD1,TCLD0 - Timer Compare Register Reload ; Condition ; When counter is 0 ;Bit 1 (0) TECMPR - Timer compare enable ; Disable timer compare operation ;Bit 0 (0) SELT1PR - Period Register select ; Use own period register SBIT1 T1CON,B6_MSK ;Sets Bit 6 of T1CON ;Starts GP Timer 1 ;T1CON - GP Timer 1 Control Register ;Bit 6 (1) TENABLE - Timer Enable ; Enable Timer Operations ;-; Initialize Variables for Generation of Sine Wave on DAC ;- Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 25 SPRA418 SPRA418 ;The DAC module requires that wait states be generated for proper ;operation. LDP #0000h SPLK OUT #4h,GPR0 GPR0,WSGR .bss ;Set Data Page Pointer to ;0000h, Block B2 ;Set Wait State Generator for ;Program Space, 0WS ;Data Space, 0WS ;I/O Space, 1WS TABLE,1 .bss .bss .bss ;Keeps address of the ;pointer in the SINE Table TOPTABLE,1 ;Keeps the reset value for ;the pointer COMPARET1,1 ;A register to do ;calculations since the ;T1CMPR register is double ;buffered REMAINDER,1 ;Remainder of the MODREGx ;values VALUE,1 ;SINE Table Value NEXTVALUE,1 ;Next entry in the SINE Table DIFFERENCE,1 ;Difference between Entries .bss FREQSTEP1,1 .bss MODREG1,1 .bss MAG1,1 .bss FREQSTEP2,1 .bss MODREG2,1 .bss MAG2,1 .bss TEMP,1 .bss .bss .bss .bss ;Frequency modulation of the ;1st sine wave ;Rolling Modulo Register for ;1st sine wave ;Magnitude of the frequency ;for 1st sine wave ;Frequency modulation of the ;2nd sine wave ;Rolling Modulo Register for ;2nd sine wave ;Magnitude of the frequency ;for 2nd sine wave ;Register to hold temporary ;values NEW_VALUE,1 ;New value to load into ;the appropriate register .bss PREV_VALUE,1 ;Previous value before ;being changed .bss DIVISOR,1 .text NOP SPLK SPLK SPLK 26 #0000h,TABLE #STABLE,TOPTABLE #1000,FREQSTEP1 ;Controls the frequency Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 SPLK SPLK SPLK ;for DAC0 #0000h,MODREG1 ;Sets the starting point #7FFFh,MAG1 ;Maximum value, Q15 SPLK SPLK #1000,FREQSTEP2 ;Controls the frequency ;for DAC1 #0000h,MODREG2 ;Sets the starting point #7FFFh,MAG2 ;Maximum value, Q15 SPLK #0000h,TEMP SPLK SPLK SPLK SPLK LAR LAR LAR ;Initialize temporary ;register #0000h,NEW_VALUE ;Initialize new value #0000h,PREV_VALUE ;Initialize previous ;value #0000h,DIVISOR ;Initialize the maximum ;register #0000h,QUOTIENT ;Initialize the quotient AR0, #SCITXBUF ;Load AR0 with SCI_TX_BUF ;address AR1, #SCIRXBUF ;Load AR1 with SCI_RX_BUF ;address AR2, #B1_SADDR ;Load AR2 with TX data ;start address LAR CLRC WAITING AR3, #B0_SADDR INTM LDP BIT #232 EVIFRA,BIT7 ;Polling routine to wait BCND WAITING,NTC ;T1PINT Flag to be Set for ;-; Generate Sine Wave ;-;The following section performs the necessary calculations for the ;first sine wave SINE LDP LACC ADD SACL LACC SACH #0 MODREG1 ;ACC loaded with the counting ;register FREQSTEP1 ;Counting Register increased by ;specific step MODREG1 ;Store the updated counter value MODREG1,8 ;Reload the new ctr value but ;shift left by 8 bits TABLE ;Store the high bit pointer to lookup SFR ;table ;Shift the value to the right ;convert to Q15 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 27 SPRA418 SPRA418 AND SACL LACC ADD TBLR ADD TBLR LACC SUB SACL #07FFFh ;Make sure the Q15 value is ;positive REMAINDER ;Store the fractional value of ;the counting register TABLE ;Load the accumulator with the ;proper index value TOPTABLE ;Displace the ACC with the ;starting address VALUE ;Read the value from the table ;and store into VALUE #1 ;Increment the ACC to the next ;address NEXTVALUE ;Read the next value from the ;table and NEXTVALUE ;Load the ACC with NEXTVALUE VALUE ;Subtract the previous value DIFFERENCE ;Store the difference between ;the values LT DIFFERENCE ;Load the TREG with DIFFERENCE MPY REMAINDER ;Multiply the DIFFERENCE with ;REMAINDER PAC ;Move the product to the ACC SACH REMAINDER,1 ;Store the upper byte and shift ;left by 1, Q15 LACC REMAINDER ;Load ACC with new REMAINDER ADD VALUE ;Add VALUE to get the new ;interpolated value SACL VALUE ;Store the interpolated value ;into VALUE LT VALUE MPY PAC SACH ;Load the TREG with the new ;interpolated VALUE MAG1 ;Multiply VALUE by a magnitude ;Move the product to ACC DAC0VAL,1 ;Store the new value, shift to ;get Q15 ;The following section performs the necessary calculations for the ;second sine wave LACC SACL LACC ;ACC loaded with the counting ;register FREQSTEP2 ;Counting Register increased by ;specific step MODREG2 ;Store the updated the counter value MODREG2,8 ;Reload the new ctr value, shift SACH TABLE ADD MODREG2 left SFR ;by 8 bits ;Store the high bit as pointer to ;lookup table ;Shift the value to the right convert ;to Q15 28 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 AND SACL LACC #07FFFh ;Make sure the Q15 value is positive REMAINDER ;Store the fractional value of the ;counting register TABLE ;Load the accumulator with the proper ADD TBLR ADD TBLR LACC SUB SACL ;index value TOPTABLE ;Displace the ACC with the starting ;address VALUE ;Read the value from the table and ;store into VALUE #1 ;Increment the ACC to the next ;address NEXTVALUE ;Read the next value from the table ;and store NEXTVALUE ;Load the ACC with NEXTVALUE VALUE ;Subtract the previous value DIFFERENCE ;Store the difference between the ;value LT DIFFERENCE ;Load the TREG with DIFFERENCE MPY REMAINDER ;Multiply the DIFFERENCE with ;REMAINDER PAC ;Move the product to the ACC SACH REMAINDER,1 ;Store the upper byte and shift left ;by 1, Q15 LACC REMAINDER ;Load ACC with new REMAINDER ADD VALUE ;Add VALUE to get the new ;interpolated value SACL VALUE ;Store the interpolated value into ;VALUE LT VALUE MPY PAC SACH ;Load the TREG with the new ;interpolated VALUE MAG2 ;Multiply VALUE by a magnitude ;Move the product to ACC DAC1VAL,1 ;Store the new value, shift to get ;Q15 LDP #0 LACC DAC0VAL ADD #8000h ;This section outputs the SINE wave ;to the DAC ;ACC = DAC0VAL - entry from the ;lookup table ;Displace the value half the maximum SFR ;Shift over 4 places since the DAC is ;12bits SFR SFR SFR SACL DAC0VAL ;Store the new 12 bit value into ;DAC0VAL Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 29 SPRA418 SPRA418 LACC ADD SFR SFR SFR SFR SACL OUT OUT OUT RESUME LDP LACC DAC1VAL ;ACC = DAC0VAL - entry from the ;lookup table #8000h ;Displace the value half the maximum ;Shift over 4 places since the DAC is ;12bits DAC1VAL ;Store the new 12 bit value into ;DAC0VAL DAC0VAL,DAC0 ;Stores the 12 bit value ;into DAC0 register DAC1VAL,DAC1 ;Stores the 12 bit value ;into DAC1 register DAC0VAL,DACUPDATE ;Causes the DAC to output ;the value #232 EVIFRA ;DP = 232 - DP for Event Manager ;Load EVIFRA - Type A Interrupt Flags SACL EVIFRA B WAITING ;Clear the Interrupt Flags ;= ; I S R - INT1_ISR ; ; Description: The INT1_ISR first determines if the SCI RXINT ; caused the interrupt. If so, the SCI Specific ISR ; reads the character in the RX buffer. If the ; character received corresponds to a carriage ; return, , the character string "Ready" is ; transmitted. If the character received does NOT ; correspond to a carriage return, , then the ISR ; returns to the main program without transmitting a ; character string. If the SCI RXINT did not cause ; an interrupt, then the value '0x0bad' is stored in ; the accumulator and program gets caught in the ; BAD_INT endless loop. ;= INT1_ISR: 30 #00E0h SYSIVR LDP SUB BCND B RX_ISR LDP LACL #0000h #0006h RX_ISR,EQ BAD_INT MAR LACC BIT *,AR1 * *,BIT6,AR3 ;DP = 224 Address 7000h-707Fh ;Load peripheral INT vector ;address ;DP = 0 Addresses 0000h-007Fh ;Subtract RXINT offset from above ;verify RXINT initiated interrupt ;Else, bad interrupt occurred ;ARP = AR1 ;Load ACC w/RX buffer character ;Determine if the character is a ;letter Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 BCND AND NUMBER NUMBER,NTC #01011111b SACL IP_VALUE SUB BCND B CHECK_IP *+ #000Dh CHECK_IP,EQ NO_IP ;If a letter, capitalize the ;letter ;Store the character/number ;Check to see if ;If value entered is a , then ;process input ;else, wait until is pressed LAR AR3,#B0_SADDR LACC *+ SUB #0046h BCND FREQ_CHG,EQ ADD #0046h SUB #0050h BCND PHASE_CHG,EQ ADD #0050h SUB #004Dh BCND MAG_CHG,EQ ADD #004Dh SUB #000Dh BCND SCI_ISR,EQ B BAD_IP B ISR_END BAD_IP LAR SCI_ISR MAR LDP 707Fh XMIT_CHAR: ;Check to see if ASCII letter ;'F' ;If 'F' goto routine to change ;frequency ;Check to see if ASCII letter ;'P' ;If 'P' goto routine to change ;frequency ;Check to see if ASCII letter ;'M' ;If 'M' goto routine to change ;frequency ;Check to see if ASCII ;If , output "Ready" ;If neither a ;'F','P','M',or, ;then do nothing AR2,#(B1_SADDR+LENGTH1) ;Address to output ;"Invalid Input" *,AR2 ;ARP = AR2 #00E0h ;DP = 224 Addresses 7000h- LACC *+,AR0 BCND ISR_END,EQ SACL XMIT_RDY: ;AR3 = Address of first value ;entered ;ACC = ASCII equivalent of ;value *,AR2 BIT BCND B SCICTL2, BIT7 XMIT_RDY, NTC XMIT_CHAR ;Load char to be xmitted into ;ACC ;Check for Null Character ;YES? Return from INT1_ISR. ;NO? Load char into xmit ;buffer. ;Test TXRDY bit ;If TXRDY=0,then repeat loop ;else xmit next character Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 31 SPRA418 SPRA418 ISR_END: LAR AR2, #B1_SADDR LDP ;Reload AR2 w/ TX data start ;address AR3, #B0_SADDR ;Reload AR3 w/ RX data start ;address #00E0h ;DP = 224 Addresses 7000h- LACC #0Ah SACL LDP CLRC SCITXBUF #0 INTM LAR 707Fh RET NO_IP LAR AR2, #B1_SADDR LDP CLRC RET BAD_INT: LACC B #0 INTM #0BADh BAD_INT ;Cause a line feed in the ;terminal ;transmit the line feed ;DP = 0 Addresses 0000h-007Fh ;Enable Interrrupts ;Return from INT1_ISR ;Reload AR2 w/ TX data start ;address ;DP = 0 Addresses 0000h-007Fh ;Enable Interrupts ;Return from interrupt ;Load ACC with "bad" ;Repeat loop ;-;The following section will modify the frequency of the specified ;channel ;-FREQ_CHG 007Fh LDP #0 SPLK LACC SUB #0000h,NEW_VALUE ;Initialize NEW_VALUE *+ #0041h ;Check whether to modify ;Channel A FREQ_A,EQ ;If 'A', goto part that ;modifies Chan. A BCND ADD SUB #0041h #0042h BCND FREQ_B,EQ ADD SUB #0042h #0052h BCND FREQ_RESET,EQ B BAD_IP FREQ_B FREQSTEP2 PREV_VALUE CALL 32 LACC SACL WHAT_VALUE ;DP = 0 Addresses 0000h - ;Check whether to modify ;Channel B ;If 'B', goto part that ;modifies Chan. B ;Check whether to reset the ;Channels ;Else, bad input so end routine ;ACC = FREQSTEP2 ;Keep the previous value in ;case ;the new value is invalid ;Determine the entered Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 ;frequency LACC SUB BCND NO_CHGB,EQ CALL NO_CHGB NEW_VALUE PREV_VALUE FSTEP_VALUE LACC SACL NEW_VALUE FREQSTEP2 B FREQ_A ISR_END ;ACC = entered value ;If entered value is the same ;as the prev ;then, the entered value was ;invalid, so ;nothing changes, else ;Determine the equivalent step ;value ;ACC = New step value ;FREQSTEP2 = New step value ;End of the frequency change ;for Chan. B FREQSTEP1 PREV_VALUE ;ACC = FREQSTEP1 ;Keep the previous value in ;case ;the new value is invalid CALL WHAT_VALUE ;Determine the entered ;frequency LACC SUB NEW_VALUE PREV_VALUE BCND NO_CHGA,EQ CALL NO_CHGA LACC SACL FSTEP_VALUE ;ACC = entered value ;If entered value is the same ;as the prev ;then, the entered value was ;invalid, so ;nothing changes, else ;Determine the equivalent step ;value LACC SACL NEW_VALUE FREQSTEP1 B FREQ_RESET ISR_END SPLK SPLK B ;ACC = New step value ;FREQSTEP1 = New Step Value ;End of the frequency change ;for Chan. A #1000,FREQSTEP1 ;Initialize Channel A to ;original value #1000,FREQSTEP2 ;Initialize Channel B to ;original value ISR_END ;= ; Converts the entered frequency into a step value ;= FSTEP_VALUE LT NEW_VALUE MPY #QT1PERIOD PAC ;TREG = NEW_VALUE ;Multiply by the "sampling ;period" ;ACC = PREG Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 33 SPRA418 SPRA418 SACL NEW_VALUE,1 RET ;Store the new step value ;Return from routine ;-;The following section will modify the phase of the specified ;channel ;-PHASE_CHG LDP #0 ;DP = 0 Addresses 0000h 007Fh SPLK #360,DIVISOR ;Initialize the max value to ;360 deg SPLK #0000h,QUOTIENT ;Initialize the quotient value SPLK #0000h,NEW_VALUE ;Initialize NEW_VALUE LACC SUB *+ #0041h BCND PHASE_A,EQ ADD SUB #0041h #0042h BCND PHASE_B,EQ ADD SUB #0042h #0052h ;Check whether to modify ;Channel A ;Check whether to modify ;Channel B ;Check whether to reset the ;Channels BCND PHASE_RESET,EQ B BAD_IP ;Else, bad input so end routine PHASE_B LACC MODREG2 SACL PREV_VALUE CALL LACC WHAT_VALUE NEW_VALUE SUB PREV_VALUE BCND ADD ISR_END,EQ PREV_VALUE SUB BCND #360 BAD_IP,GT ADD CALL #360 DIVIDE LT QUOTIENT MPY #100h PAC 34 ;Load the Modulo Register of ;Channel B ;Save the value in case the ;entered ;value is invalid ;Determine the entered phase ;Load the value ;If input value is invalid, ;WHAT_VALUE ;sets NEXT_VALUE=PREV_VALUE ;If input is a number, then ;Check if value is larger than ;360 degrees ;If the value is okay, then ;determine ;what the Q15 fraction the ;value is of 360 ;TREG = QUOTIENT ;PREG = QUOTIENT * 256 ;ACC = PREG Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 SACH NEW_VALUE,1 ;NEW_VALUE=QUOTIENT *256; Shift LACC ADD NEW_VALUE,8 MODREG1 SACL MODREG2 B PHASE_A ;by 1 to ;remove extra sign bit ;ACC = NEW_VALUE * 256 ;Add the Modulo Register of ;Channel A ;Store the new value for ;Channel B ISR_END LACC MODREG1 SACL PREV_VALUE CALL LACC WHAT_VALUE NEW_VALUE SUB PREV_VALUE BCND ADD ISR_END,EQ PREV_VALUE SUB BCND #360 BAD_IP,GT ADD CALL ;End of phase shift for Channel ;B ;Load the Modulo Register of ;Channel A ;Save the value in case the ;entered value ;is invalid ;Determine the entered phase ;Load the value #360 DIVIDE ;If input value is invalid, ;WHAT_VALUE ;sets NEXT_VALUE=PREV_VALUE LT QUOTIENT MPY #100h PAC SACH NEW_VALUE,1 LACC ADD NEW_VALUE,8 MODREG2 SACL MODREG1 B PHASE_RESET ISR_END SPLK SPLK B ;If input is a number, then ;Check if value is larger than ;360 degrees ;If the value is okay, then ;determine ;what the Q15 fraction the ;value is of 360 ;TREG = QUOTIENT ;PREG = QUOTIENT * 256 ;ACC = PREG ;NEW_VALUE = QUOTIENT * 256; ;Shift by 1 to ;remove extra sign bit ;ACC = NEW_VALUE * 256 ;Add the Modulo Register of ;Channel B ;Store the new value for ;Channel A ;End of phase shift for Channel ;A #0000h,MODREG1 ;Initialize Channel A to ;original value #0000h,MODREG2 ;Initialize Channel B to ;original value ISR_END Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 35 SPRA418 SPRA418 ;-;The following section will modify the magnitude of the specified ;channel ;-MAXMAG .equ MAG_CHG LDP 50 #0 SPLK SPLK SPLK SPLK ;DP = 0 Addresses ;0000h - 007Fh #MAXMAG,DIVISOR ;Initialize DIVISOR #7FFFh,TEMP ;Initialize TEMP #0000h,QUOTIENT ;Initialize QUOTIENT #0000h,NEW_VALUE ;Initialize NEW_VALUE LACC SUB BCND *+ #0041h MAG_A,EQ ADD SUB BCND #0041h #0042h MAG_B,EQ ADD SUB #0042h #0052h BCND MAG_RESET,EQ B BAD_IP MAG_B LACC SACL MAG2 PREV_VALUE ;Check whether to modify ;Channel A ;Check whether to modify ;Channel B ;Check whether to reset the ;Channels ;Else, bad input so end ;routine ;ACC = MAG2 ;Store the current magnitude CALL LACC NEW_VALUE SUB PREV_VALUE BCND ADD ISR_END,EQ PREV_VALUE SUB BCND #MAXMAG BAD_IP,GT ADD CALL #MAXMAG DIVIDE CALL 36 WHAT_VALUE MAG_VALUE ;in case ;the input value is invalid ;Determine the entered ;magnitude ;ACC = Entered Value ;If input value is invalid, ;WHAT_VALUE ;sets NEXT_VALUE=PREV_VALUE ;If input is a number, then ;Check if value is larger ;than MAXMAG ;If the value is okay, ;determine what ;proportion the entered ;value is of MAXMAG ;Normalize the ratio to the Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 ;maximum ;Q15 value LACC AND NEW_VALUE #7FFFh SACL MAG2 ;Make sure the value is ;positive ;Store the new magnitude for ;Channel B B MAG_A ISR_END LACC SACL MAG1 PREV_VALUE ;End of modifying magnitude ;for Channel B ;ACC = MAG1 ;Store the current magnitude CALL WHAT_VALUE LACC NEW_VALUE SUB PREV_VALUE BCND ADD ISR_END,EQ PREV_VALUE SUB BCND #MAXMAG BAD_IP,GT ADD CALL #MAXMAG DIVIDE CALL MAG_VALUE LACC AND NEW_VALUE #7FFFh SACL MAG1 ;in case ;the input value is invalid ;determine the entered ;magnitude ;ACC = Entered value ;If input value is invalid, ;WHAT_VALUE ;sets NEXT_VALUE=PREV_VALUE ;If input is a number, then ;Check if value is larger ;than MAXMAG ;if the value is okay, ;determine what ;proportion the entered ;value is of MAXMAG ;Normalize the ratio to the ;maximum ;Q15 value ;Make sure the value is ;positive ;Store the new magnitude for ;Channel A B MAG_RESET ISR_END SPLK #7FFFh,MAG1 SPLK #7FFFh,MAG2 B ;End of modifying magnitude ;for Channel A ;Initialize Channel A to ;original value ;Initialize Channel B to ;original value ISR_END ;= Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 37 SPRA418 SPRA418 ; Converts the entered magnitude into a Q15 value ;= MAG_VALUE LACC SUB BCND QUOTIENT #08000h MAX_MAG,EQ LT TEMP MPY QUOTIENT PAC SACH NEW_VALUE,1 RET MAX_MAG SPLK RET ;If the DIVISOR=DIVIDENT, then ;set quotient to maximum Q15 ;value ;TREG = TEMP ;PREG = TEMP * QUOTIENT ;ACC = PREG ;NEW_VALUE = TEMP * QUOTIENT; ;Shift by 1 to ;remove extra sign bit ;Return from routine #7FFFh,NEW_VALUE ;Set NEW_VALUE to maximum Q15 ;value ;Return from Routine ;= ;Routine to determine the next value ;= WHAT_VALUE LACC *+ ;ACC = First place SUB BCND #000Dh NO_VALUE,EQ ;Check if the value is a ADD SUB #000Dh #0030h BCND NO_VALUE,LT ADD SUB #0030h #0039h ;Check if value is below ASCII ;0 ;Check if value is above ASCII ;9 BCND ADD VALID_VALUE NO_VALUE,GT #0039h SUB #0030h LT NEW_VALUE MPY #10 APAC SACL NEW_VALUE LACC SUB BCND *+ #000Dh EOV,EQ ADD SUB ;Make the value into a usable ;value ;TREG = Digit of entered value ;PREG = TREG * 10 ;ACC = PREG + ACC ;Store the new value ;Load the next digit #000Dh #0030h ;If it is , then End of ;Value ;Check is value is below ASCII ;0 BCND 38 NO_VALUE,LT Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 ADD SUB #0030h #0039h ;Check if value is above ASCII ;9 BCND NO_VALUE,GT ADD #0039h B VALID_VALUE NO_VALUE PREV_VALUE SACL NEW_VALUE CALL RET EOV previous value LACC ;If the entered value is bad, ;then ;store the previous value as ;the new value BAD_IP SPLK #0FFFFh,PREV_VALUE ;Valid Value, Discard ;Return from routine RET ;Return from routine ;= ; Divide Routine ;= DIVIDE LAR AR4,#DIVISOR ;AR4 = Address for DIVISOR ;value LAR AR5,#QUOTIENT ;AR5 = Address for Q15 ;quotient LAR AR6,#15 ;AR6 = 16 - 1; Number of ;times to subtract LAR AR7,#NEW_VALUE ADD MAR LACC ACL *,AR5 * *,1,AR7 LACC SUB BCND DIVIDING *,0,AR4 * ADD_ONE,GEQ *,AR7 SACL *,1,AR6 BANZ DIVIDING,*-,AR5 ;ARP = AR5 ;ACC = QUOTIENT ;QUOTIENT = QUOTIENT * 2; ;1st shift doesn't ;matter because QUOTIENT = 0 ;ACC = Value pointed by AR7 ;Subtract DIVISOR ;If ACC is still positive, ;then increment ;the ones place of the ;quotient, and shift ;the remainder in the ACC, ;else ;shift the remainder in the ;ACC ;Store the remainder * 2 to ;location ;pointed by AR7 ;AR6 = AR6 - 1; Repeat the ;dividing RET ADD_ONE MAR *,AR7 ;ARP = AR7 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 39 SPRA418 SPRA418 SACL *,1,AR5 ;Store the Remainder shifted LACC ADD SACL * #1 *,0,AR6 BANZ DIVIDING,*-,AR5 ;by 1 back ;into the buffer ;ACC = Quotient ;Increment the quotient ;Store the new value of ;quotient; ARP = AR6 ;AR6 = AR6 - 1; Repeat the ;dividing RET ;-; Sine look-up table ; No. Entries : 256 ; Angle Range : 360 deg ; Number format : Q15 with range -1 < N < +1 ;-;SINVAL ; Index Angle Sin(Angle) STABLE .word 0 ; 0 0 0.0000 .word 804 ; 1 1.41 0.0245 .word 1608 ; 2 2.81 0.0491 .word 2410 ; 3 4.22 0.0736 .word 3212 ; 4 5.63 0.0980 .word 4011 ; 5 7.03 0.1224 .word 4808 ; 6 8.44 0.1467 .word 5602 ; 7 9.84 0.1710 .word 6393 ; 8 11.25 0.1951 .word 7179 ; 9 12.66 0.2191 .word 7962 ; 10 14.06 0.2430 .word 8739 ; 11 15.47 0.2667 .word 9512 ; 12 16.88 0.2903 .word 10278 ; 13 18.28 0.3137 .word 11039 ; 14 19.69 0.3369 .word 11793 ; 15 21.09 0.3599 .word 12539 ; 16 22.50 0.3827 .word 13279 ; 17 23.91 0.4052 .word 14010 ; 18 25.31 0.4276 .word 14732 ; 19 26.72 0.4496 .word 15446 ; 20 28.13 0.4714 .word 16151 ; 21 29.53 0.4929 .word 16846 ; 22 30.94 0.5141 .word 17530 ; 23 32.34 0.5350 .word 18204 ; 24 33.75 0.5556 .word 18868 ; 25 35.16 0.5758 .word 19519 ; 26 36.56 0.5957 .word 20159 ; 27 37.97 0.6152 .word 20787 ; 28 39.38 0.6344 .word 21403 ; 29 40.78 0.6532 .word 22005 ; 30 42.19 0.6716 .word 22594 ; 31 43.59 0.6895 .word 23170 ; 32 45.00 0.7071 .word 23731 ; 33 46.41 0.7242 .word 24279 ; 34 47.81 0.7410 40 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word 24811 25329 25832 26319 26790 27245 27683 28105 28510 28898 29268 29621 29956 30273 30571 30852 31113 31356 31580 31785 31971 32137 32285 32412 32521 32609 32678 32728 32757 32767 32757 32728 32678 32609 32521 32412 32285 32137 31971 31785 31580 31356 31113 30852 30571 30273 29956 29621 29268 28898 28510 28105 27683 27245 26790 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 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 49.22 50.63 52.03 53.44 54.84 56.25 57.66 59.06 60.47 61.88 63.28 64.69 66.09 67.50 68.91 70.31 71.72 73.13 74.53 75.94 77.34 78.75 80.16 81.56 82.97 84.38 85.78 87.19 88.59 90.00 91.41 92.81 94.22 95.63 97.03 98.44 99.84 101.25 102.66 104.06 105.47 106.88 108.28 109.69 111.09 112.50 113.91 115.31 116.72 118.13 119.53 120.94 122.34 123.75 125.16 0.7572 0.7730 0.7883 0.8032 0.8176 0.8315 0.8449 0.8577 0.8701 0.8819 0.8932 0.9040 0.9142 0.9239 0.9330 0.9415 0.9495 0.9569 0.9638 0.9700 0.9757 0.9808 0.9853 0.9892 0.9925 0.9952 0.9973 0.9988 0.9997 1.0000 0.9997 0.9988 0.9973 0.9952 0.9925 0.9892 0.9853 0.9808 0.9757 0.9700 0.9638 0.9569 0.9495 0.9415 0.9330 0.9239 0.9142 0.9040 0.8932 0.8819 0.8701 0.8577 0.8449 0.8315 0.8176 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 41 SPRA418 SPRA418 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word 42 26319 25832 25329 24811 24279 23731 23170 22594 22005 21403 20787 20159 19519 18868 18204 17530 16846 16151 15446 14732 14010 13279 12539 11793 11039 10278 9512 8739 7962 7179 6393 5602 4808 4011 3212 2410 1608 804 0 64731 63927 63125 62323 61524 60727 59933 59142 58356 57573 56796 56023 55257 54496 53742 52996 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 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 126.56 127.97 129.38 130.78 132.19 133.59 135.00 136.41 137.81 139.22 140.63 142.03 143.44 144.84 146.25 147.66 149.06 150.47 151.88 153.28 154.69 156.09 157.50 158.91 160.31 161.72 163.13 164.53 165.94 167.34 168.75 170.16 171.56 172.97 174.38 175.78 177.19 178.59 180.00 181.41 182.81 184.22 185.63 187.03 188.44 189.84 191.25 192.66 194.06 195.47 196.88 198.28 199.69 201.09 202.50 0.8032 0.7883 0.7730 0.7572 0.7410 0.7242 0.7071 0.6895 0.6716 0.6532 0.6344 0.6152 0.5957 0.5758 0.5556 0.5350 0.5141 0.4929 0.4714 0.4496 0.4276 0.4052 0.3827 0.3599 0.3369 0.3137 0.2903 0.2667 0.2430 0.2191 0.1951 0.1710 0.1467 0.1224 0.0980 0.0736 0.0491 0.0245 0.0000 -0.0245 -0.0491 -0.0736 -0.0980 -0.1224 -0.1467 -0.1710 -0.1951 -0.2191 -0.2430 -0.2667 -0.2903 -0.3137 -0.3369 -0.3599 -0.3827 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word 52256 51525 50803 50089 49384 48689 48005 47331 46667 46016 45376 44748 44132 43530 42941 42365 41804 41256 40724 40206 39703 39216 38745 38290 37852 37430 37025 36637 36267 35914 35579 35262 34964 34683 34422 34179 33955 33750 33564 33398 33250 33123 33014 32926 32857 32807 32778 32768 32778 32807 32857 32926 33014 33123 33250 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 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 203.91 205.31 206.72 208.13 209.53 210.94 212.34 213.75 215.16 216.56 217.97 219.38 220.78 222.19 223.59 225.00 226.41 227.81 229.22 230.63 232.03 233.44 234.84 236.25 237.66 239.06 240.47 241.88 243.28 244.69 246.09 247.50 248.91 250.31 251.72 253.13 254.53 255.94 257.34 258.75 260.16 261.56 262.97 264.38 265.78 267.19 268.59 270.00 271.41 272.81 274.22 275.63 277.03 278.44 279.84 -0.4052 -0.4276 -0.4496 -0.4714 -0.4929 -0.5141 -0.5350 -0.5556 -0.5758 -0.5957 -0.6152 -0.6344 -0.6532 -0.6716 -0.6895 -0.7071 -0.7242 -0.7410 -0.7572 -0.7730 -0.7883 -0.8032 -0.8176 -0.8315 -0.8449 -0.8577 -0.8701 -0.8819 -0.8932 -0.9040 -0.9142 -0.9239 -0.9330 -0.9415 -0.9495 -0.9569 -0.9638 -0.9700 -0.9757 -0.9808 -0.9853 -0.9892 -0.9925 -0.9952 -0.9973 -0.9988 -0.9997 -1.0000 -0.9997 -0.9988 -0.9973 -0.9952 -0.9925 -0.9892 -0.9853 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 43 SPRA418 SPRA418 .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word .word 44 33398 33564 33750 33955 34179 34422 34683 34964 35262 35579 35914 36267 36637 37025 37430 37852 38290 38745 39216 39703 40206 40724 41256 41804 42365 42941 43530 44132 44748 45376 46016 46667 47331 48005 48689 49384 50089 50803 51525 52256 52996 53742 54496 55257 56023 56796 57573 58356 59142 59933 60727 61524 62323 63125 63927 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 281.25 282.66 284.06 285.47 286.88 288.28 289.69 291.09 292.50 293.91 295.31 296.72 298.13 299.53 300.94 302.34 303.75 305.16 306.56 307.97 309.38 310.78 312.19 313.59 315.00 316.41 317.81 319.22 320.63 322.03 323.44 324.84 326.25 327.66 329.06 330.47 331.88 333.28 334.69 336.09 337.50 338.91 340.31 341.72 343.13 344.53 345.94 347.34 348.75 350.16 351.56 352.97 354.38 355.78 357.19 -0.9808 -0.9757 -0.9700 -0.9638 -0.9569 -0.9495 -0.9415 -0.9330 -0.9239 -0.9142 -0.9040 -0.8932 -0.8819 -0.8701 -0.8577 -0.8449 -0.8315 -0.8176 -0.8032 -0.7883 -0.7730 -0.7572 -0.7410 -0.7242 -0.7071 -0.6895 -0.6716 -0.6532 -0.6344 -0.6152 -0.5957 -0.5758 -0.5556 -0.5350 -0.5141 -0.4929 -0.4714 -0.4496 -0.4276 -0.4052 -0.3827 -0.3599 -0.3369 -0.3137 -0.2903 -0.2667 -0.2430 -0.2191 -0.1951 -0.1710 -0.1467 -0.1224 -0.0980 -0.0736 -0.0491 Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM SPRA418 SPRA418 .word .word 64731 65535 ; ; 255 256 358.59 360.00 -0.0245 0.0000 ;= ; I S R - PHANTOM ; ; Description: Dummy ISR, used to trap spurious interrupts. ;= PHANTOM: KICK_DOG B PHANTOM Controlling a Sine Wave Generator with the Serial Port Using the TMS320F240 TMS320F240 EVM 45