This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
大家好,本人初学DSP,对CCS操作了解的不多,现在遇到一点问题,希望大家帮助。非常感谢。
本人按照网络教程在matlab中生成一个波形,并按DSP可读取的格式存为.dat文件。
(教程网址:)
matlab程序:
clear all; close all clc; Fs = 150e3; %定义采样率 F1 = 10e3; %定义频率 F2 = 8e3; sample_num = 500; %定义数据点个数 m = 1:sample_num; x = sin(2*pi*F1*m/Fs)+sin(2*pi*F2*m/Fs); %生成原始数据 y = typecast(single(x),'uint32'); %首先将x强制转换成single型,然后再转换成具有相同二进制形式的uint32型 这样做是为了方便dat文件存储 figure; plot(x); title('Matlab生成的原始数据'); fid=fopen('2.dat','wt'); %以写文本的方式打开一个叫input_file的dat文件(如果没有会自行创建一个) fprintf(fid,'1651 1 180000 1 %x\n',length(m)); %输出文件头,文件头必须是dsp所能识别的, %属性分别是固定标识、数据类型(十六进制)、基地址(根据你要存储在DSP什么地址处决定)、数据长度 fprintf(fid,'0x%08x\n',y); %输出y数组,并写到与fid标示符相同的文件 fclose(fid); %关闭fid标示符的文件。
得到的.dat文件如下图:
之后打开CCS6.0,load memory,得到如下数据:
在graph中查看如图:
和最开始生成的数据相差甚远。
请问这个问题该如何解决?希望论坛各位朋友给予帮助。
谢谢。
这个是教程网址,我一步一步按照这个来的:
其中的正弦波公式我有试过不同的,但是读入时数据都不对。
在读入时我打开了一个扩展外部sram和外部flash的程序,点击debug之后在0x180000(外部sram)地址下读入.dat文件的内容,另外这个地址在cmd文件中也有声明。
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File #include "DSP2833x_Examples.h" // DSP2833x Examples Include File void main(void) { // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks // This example function is found in the DSP2833x_SysCtrl.c file. InitSysCtrl(); // Step 2. Initalize GPIO: // This example function is found in the DSP2833x_Gpio.c file and // illustrates how to set the GPIO to it's default state. // InitGpio(); // Skipped for this example InitXintf16Gpio(); //zq // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize the PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. // This function is found in the DSP2833x_PieCtrl.c file. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; ChipErase(); InitExRam(0x0); FlashWrite(0,0,0xFFFF); ClearExRam(0); FlashRead(0,0,0xFFFF); for( ; ;); }
#include "DSP2833X_Device.h" // Definitions for the SST 39VF400A part //#define SST_ID 0x00BF /* SST Manufacturer's ID code */ //#define SST_39VF800A 0x2780 /* SST39VF800/SST39VF800A device code */ #define TimeOutErr 1 #define VerifyErr 2 #define WriteOK 0 #define EraseErr 3 #define EraseOK 0 #define SectorSize 0x800 #define BlockSize 0x8000 unsigned int *FlashStart = (unsigned int *)0x100000;//flash的首地址 unsigned int *ExRamStart = (unsigned int *)0x180000;//sram的首地址 Uint16 ChipErase(void) { Uint16 Data; Uint32 TimeOut,i; *(FlashStart + 0x5555) = 0xAAAA; *(FlashStart + 0x2AAA) = 0x5555; *(FlashStart + 0x5555) = 0x8080; *(FlashStart + 0x5555) = 0xAAAA; *(FlashStart + 0x2AAA) = 0x5555; *(FlashStart + 0x5555) = 0x1010; i = 0; TimeOut = 0; while(i<5) { Data = *(FlashStart + 0x3FFFF); if (Data == 0xFFFF) i++; else i=0; if ( ++TimeOut>0x1000000) return (TimeOutErr); } for (i=0;i<0x40000;i++) { Data = *(FlashStart + i); if (Data !=0xFFFF) return (EraseErr); } return (EraseOK); } Uint16 FlashWrite(Uint32 RamStart, Uint32 RomStart, Uint16 Length) { Uint32 i,TimeOut; Uint16 Data1,Data2,j; for (i=0;i<Length;i++) { *(FlashStart + 0x5555) = 0x00AA; *(FlashStart + 0x2AAA) = 0x0055; *(FlashStart + 0x5555) = 0x00A0; *(FlashStart + RomStart + i) = *(ExRamStart + RamStart + i); TimeOut = 0; j=0; while(j<5) { Data1 = *(FlashStart + RomStart + i); Data2 = *(FlashStart + RomStart + i); if (Data1 == Data2) j++; else j=0; if ( ++TimeOut>0x1000000) return (TimeOutErr); } } for (i=0;i<Length;i++) { Data1 = *(FlashStart + RomStart +i); Data2 = *(ExRamStart + RamStart +i); if (Data1 != Data2) return (VerifyErr); } return (WriteOK); } void FlashRead(Uint32 RamStart, Uint32 RomStart, Uint16 Length) { Uint32 i; Uint16 Temp; for (i=0;i<Length;i++) { Temp = *(FlashStart + RomStart +i); *(ExRamStart + RamStart +i) = Temp; } } void InitExRam(Uint16 Start) { Uint16 i; for (i=0;i<0xFFFF;i++) *(ExRamStart + Start + i) = 0x1201; } void ClearExRam(Uint16 Start) { Uint16 i; for (i=0;i<0xFFFF;i++) *(ExRamStart + Start + i) = 0; } void RamRead(Uint16 Start) { Uint16 i; for (i=0;i<0xFFFF;i++) *(ExRamStart + Start + i) = *(ExRamStart +i); } //=========================================NO MORE==============================
不知道和程序有没有关系,但还是先放上来。
麻烦您帮忙看看。谢谢。