Hi guys, I need to generate a sine wave on the C31. This is how I am approaching it, I am writing a C program to generate the sine wave using phasor multiplication. This program returns a range of floating point values which correspond to a sine wave. How do I carry on from here to implement this wave on the C31 or have I gone completely off track already. I was thinking that maybe its possible to create .asm file from the output of the C program so that it can be run on the C31. I'm sorry if this seems rather vague but I have only really just started it. Any help would be greatly appreciated rgds Phil 

Simple Sine Wave on the C31
Started by ●December 4, 2002
Posted by ●December 4, 2002
Hi Phil You should find the following functions in SIGGEN.C and SIGGEN2.ASM (in the C_APPS subdirectory) helpful. Hope this helps, Keith Larson #include <math.h> #include "siggen.h" //======================================================== // InitSiggen() initializes the signal structure based on // the desired frequency and sample rate. //======================================================== void InitSiggen(SIGGEN *S, float Fgen, float Ts) { float angle; angle = 2*pi*Fgen*Ts; S>TR = cos(angle); S>TI = sin(angle); S>DI = 0.0; S>DR = 1.0; } //======================================================== // siggen() generates REAL (cos) and IMAG (sin) complex // signals using complex multiplication to perform phasor // rotation. Error feedback is enabled //======================================================== void siggen(SIGGEN *S) { float f; // complex multiply f = (S>DR * S>TR)  (S>DI * S>TI); S>DI = (S>DR * S>TI) + (S>DI * S>TR); S>DR = f; // Now fix any (small) amplitude errors f = 1.5  0.5*((S>DI*S>DI) + (S>DR*S>DR)); S>DI *= f; S>DR *= f; } //======================================================== void siggen2(SIGGEN *S); // prototype for ASM version ; ; SIGGEN2.ASM ; Keith Larson ; TMS320 Applications ; (c) Texas Instruments Inc, 1999 ; ; Prototype: void siggen2(&SIGGEN); ; ; Computes a rotating phasor whose value and ; rotational frequency is defined in a SIGGEN ; structure. ; ; typedef struct SIGGEN ; { ; float DR; // R/I phasor (signal) ; float DI; ; float TR; // R/I phase rate (twiddle) ; float TI; ; } ; ; This function uses only registers R0,R1,R2 ; and R3 which do not require context save ; ; On entry the stack holds the return address ; and address of the SIGGEN structure ; ; Execution: 16 Cycles: ; Using internal SRAM when data and program ; are not in the same same block ; ; Size: 19 program, 0 data (structure is external) ; .globl _siggen2 _siggen2: ; LDI SP,AR2 ; Load local frame pointer LDI *AR2(1),AR2 ; Addr of SIGGEN structure ;====Compute phase rotation === ldf *+AR2(1) ,R0 ; DI  ldf *AR2++(1),R1 ; DR MPYF3 *++AR2(1),R1,R2 ; TR*DR MPYF3 *+AR2(1) ,R0,R3 ; TI*DI MPYF *+AR2(1) ,R1 ; TI*DR MPYF *AR2(2),R0 ; TR*DI SUBF R3,R2,R2 ; R2=TR*DRTI*DI ADDF R0,R1,R1 ; R1=TI*DR+TR*DI ;= FEEDBACK: compute mag^2 === MPYF R1,R1,R3 ; R3=I^2 MPYF R2,R2,R0 ; R0=R^2 ADDF R3,R0,R0 ; R0=R^2+I^2 ;= FEEDBACK: 1/sqrt(x) apprx == MPYF 0.5,R0 ; SUBRF 1.5,R0 ; R0=1.50.5*(R^2+I^2) ;=t return using free reg== pop R3 ; BD R3 ; ;==Scale results and save====== MPYF R0,R1 ; MPYF R0,R2 ; STF R2,*+AR2(0) ; Update REAL  STF R1,*+AR2(1) ; Update IMAG At 07:23 PM 12/3/02 +0000, you wrote: >Hi guys, > >I need to generate a sine wave on the C31. >This is how I am approaching it, I am writing a C program to generate the >sine wave using phasor multiplication. This program returns a range of floating >point values which correspond to a sine wave. How do I carry on from here >to implement this wave on the C31 or have I gone completely off track already. > >I was thinking that maybe its possible to create .asm file from the output >of the C program so that it can be run on the C31. I'm sorry if this seems >rather vague but I have only really just started it. > >Any help would be greatly appreciated >rgds >Phil > ++ Keith Larson  Member Group Technical Staff  Texas Instruments Incorporated     2812743288     www.micro.ti.com/~klarson  +  TMS320C3x/C4x/VC33 Applications     TMS320VC33   The lowest cost and lowest power 500 w/Mflop   floating point DSP on the planet!  ++ 