直入主题,学习记之~~~
1,需求分析
根据YY0709 国家医疗器械中优先级报警声音波形要求,如下
2.matlab生成波形
本次使用matlab生成波形,五个正弦波叠加,基频为780HZ,分别取一倍,二倍,三倍,四倍,五倍频叠加,由于使用的是KL26的DAC模块生成波形,则对波形赋值进行了量化,直接附上代码
Fs=200000; %采样率 fc=780; %载波频率 N=0.01; t=0:1/Fs:1/780; carrier=1*sin(2*pi*fc*t); signal = 1*sin(4*pi*fc*t); wo = 1*sin(6*pi*fc*t); woo=1*sin(8*pi*fc*t); ta=1*sin(10*pi*fc*t); DSBmodout= 2^12*(signal+carrier+wo+woo+ta+4)/8; figure(3) plot(t, DSBmodout); fid=fopen(‘D:\2017a\abc.txt‘,‘W‘);%把数据写入sin_data.txt文件中,如果没有就创建该文件 fprintf(fid,‘%d,‘,DSBmodout); fclose(fid);
波形为
直接对其采样结果为
2048,2.235912e+03,2.422133e+03,2.604995e+03,2.782865e+03,2.954173e+03,3.117424e+03,3.271218e+03,3.414264e+03,3.545400e+03,3.663598e+03,3.767984e+03,3.857838e+03,3.932611e+03,3.991923e+03,4.035568e+03,4.063514e+03,4.075906e+03,4.073054e+03,4.055435e+03,4.023681e+03,3.978569e+03,3.921012e+03,3.852043e+03,3.772802e+03,3.684519e+03,3.588500e+03,3.486106e+03,3.378735e+03,3.267808e+03,3.154746e+03,3.040953e+03,2.927800e+03,2.816606e+03,2.708624e+03,2.605026e+03,2.506886e+03,2.415173e+03,2.330738e+03,2.254306e+03,2.186468e+03,2.127680e+03,2.078254e+03,2.038364e+03,2.008042e+03,1.987186e+03,1.975559e+03,1.972800e+03,1.978432e+03,1.991871e+03,2.012437e+03,2.039367e+03,2.071827e+03,2.108930e+03,2.149744e+03,2.193314e+03,2.238672e+03,2.284854e+03,2.330914e+03,2.375940e+03,2.419061e+03,2.459470e+03,2.496423e+03,2.529257e+03,2.557399e+03,2.580366e+03,2.597778e+03,2.609357e+03,2.614932e+03,2.614437e+03,2.607912e+03,2.595499e+03,2.577439e+03,2.554064e+03,2.525790e+03,2.493110e+03,2.456585e+03,2.416832e+03,2.374513e+03,2.330323e+03,2.284979e+03,2.239209e+03,2.193735e+03,2.149267e+03,2.106486e+03,2.066037e+03,2.028516e+03,1.994464e+03,1.964354e+03,1.938588e+03,1.917488e+03,1.901295e+03,1.890163e+03,1.884158e+03,1.883258e+03,1.887356e+03,1.896259e+03,1.909695e+03,1.927317e+03,1.948712e+03,1.973403e+03,2.000863e+03,2.030524e+03,2.061782e+03,2.094013e+03,2.126581e+03,2.158850e+03,2.190191e+03,2.220000e+03,2.247700e+03,2.272757e+03,2.294686e+03,2.313056e+03,2.327505e+03,2.337736e+03,2.343531e+03,2.344748e+03,2.341325e+03,2.333281e+03,2.320716e+03,2.303808e+03,2.282809e+03,2.258045e+03,2.229902e+03,2.198827e+03,2.165318e+03,2.129912e+03,2.093182e+03,2.055720e+03,2.018133e+03,1.981030e+03,1.945010e+03,1.910655e+03,1.878519e+03,1.849117e+03,1.822916e+03,1.800329e+03,1.781708e+03,1.767336e+03,1.757420e+03,1.752094e+03,1.751410e+03,1.755340e+03,1.763773e+03,1.776523e+03,1.793325e+03,1.813842e+03,1.837671e+03,1.864350e+03,1.893361e+03,1.924145e+03,1.956108e+03,1.988630e+03,2.021076e+03,2.052810e+03,2.083201e+03,2.111635e+03,2.137529e+03,2.160336e+03,2.179560e+03,2.194759e+03,2.205559e+03,2.211656e+03,2.212825e+03,2.208922e+03,2.199890e+03,2.185760e+03,2.166649e+03,2.142762e+03,2.114390e+03,2.081902e+03,2.045742e+03,2.006426e+03,1.964526e+03,1.920669e+03,1.875524e+03,1.829788e+03,1.784181e+03,1.739431e+03,1.696258e+03,1.655370e+03,1.617443e+03,1.583115e+03,1.552970e+03,1.527529e+03,1.507243e+03,1.492480e+03,1.483517e+03,1.480537e+03,1.483624e+03,1.492754e+03,1.507800e+03,1.528529e+03,1.554600e+03,1.585574e+03,1.620913e+03,1.659989e+03,1.702092e+03,1.746438e+03,1.792182e+03,1.838427e+03,1.884239e+03,1.928660e+03,1.970721e+03,2.009461e+03,2.043936e+03,2.073239e+03,2.096512e+03,2.112962e+03,2.121873e+03,2.122621e+03,2.114683e+03,2.097649e+03,2.071230e+03,2.035270e+03,1.989743e+03,1.934766e+03,1.870594e+03,1.797624e+03,1.716392e+03,1.627569e+03,1.531955e+03,1.430471e+03,1.324152e+03,1.214128e+03,1.101623e+03,9.879290e+02,8.743984e+02,7.624240e+02,6.534223e+02,5.488155e+02,4.500137e+02,3.583957e+02,2.752918e+02,2.019650e+02,1.395945e+02,8.925940e+01,5.192321e+01,2.842034e+01,1.944376e+01,2.553438e+01,4.707240e+01,8.427057e+01,1.371696e+02,2.056356e+02,2.893600e+02,3.878615e+02,5.004902e+02,6.264340e+02,7.647273e+02,9.142610e+02,1.073795e+03,1.241974e+03,1.417338e+03,1.598346e+03,1.783390e+03,1.970812e+03,
一共257个值
二 单片机调试
我用的是codewarrior10.6.4,直接附上部分主要代码
DA1_Enable();//180725 unsigned short DacData[]={0x8000, 0xa1d0, 0xc110, 0xdb80, 0xef40, 0xfb20, 0xfec0,0xfff0, 0xfa70, 0xef40, 0xde90, 0xcb40, 0xb690, 0xa300, 0x9240, 0x85b0, 0x7df0, 0x7b40, 0x7d20, 0x8270, 0x8a10, 0x9270, 0x9a20, 0xa000, 0xa310, 0xa300, 0x9fd0, 0x9a10, 0x9280, 0x8a40, 0x8250, 0x7bd0, 0x7770, 0x75b0, 0x76a0, 0x79e0, 0x7ee0, 0x84b0, 0x8a60, 0x8f10, 0x91e0, 0x9270, 0x9090, 0x8c70, 0x86b0, 0x7ff0, 0x7940, 0x7380, 0x6f60, 0x6d80, 0x6e10, 0x70f0, 0x7590, 0x7b40, 0x8120, 0x8610, 0x8960, 0x8a40, 0x8880, 0x8420, 0x7d90, 0x75b0, 0x6d60, 0x65e0, 0x6010, 0x5cf0, 0x5ce0, 0x6000, 0x65d0, 0x6d80, 0x75e0, 0x7d80, 0x82e0, 0x84b0, 0x81f0, 0x7a40, 0x6da0, 0x5ce0, 0x4950, 0x34a0, 0x20c0, 0x1090, 0x580, 0x130,0, 0x4d0, 0x10c0, 0x2480, 0x3ef0,0x5e30}; unsigned short DacData2[]={0x8000, 0x8bb0, 0x9760, 0xa2c0, 0xade0, 0xb8a0, 0xc2d0, 0xcc70, 0xd560, 0xdd90, 0xe4f0, 0xeb70, 0xf110, 0xf5c0, 0xf970, 0xfc30, 0xfdf0, 0xfeb0, 0xfff0, 0xfe90, 0xfd70, 0xfb70, 0xf8a0, 0xf510, 0xf0c0, 0xebc0, 0xe640, 0xe040, 0xd9e0, 0xd320, 0xcc30, 0xc520, 0xbe00, 0xb6f0, 0xb000, 0xa940, 0xa2d0, 0x9ca0, 0x96f0, 0x91a0, 0x8ce0, 0x88a0, 0x84f0, 0x81e0, 0x7f60, 0x7d80, 0x7c30, 0x7b70, 0x7b40, 0x7ba0, 0x7c70, 0x7dc0, 0x7f70, 0x81a0, 0x83c0, 0x8650, 0x8910, 0x8be0, 0x8ec0, 0x91a0, 0x9470, 0x9730, 0x99b0, 0x9c00, 0x9e10, 0x9fd0, 0xa140, 0xa250, 0xa310, 0xa360, 0xa360, 0xa2f0, 0xa230, 0xa110, 0x9fa0, 0x9dd0, 0x9bd0, 0x9980, 0x9700, 0x9460, 0x91a0, 0x8ec0, 0x8bf0, 0x8910, 0x8650, 0x83a0, 0x8120, 0x7ec0, 0x7ca0, 0x7ac0, 0x7920, 0x77d0, 0x76d0, 0x7620, 0x75c0, 0x75b0, 0x75f0, 0x7680, 0x7750, 0x7870, 0x79c0, 0x7b50, 0x7d00, 0x7ee0, 0x80d0, 0x82e0, 0x84e0, 0x86e0, 0x88e0, 0x8ac0, 0x8c70, 0x8e00, 0x8f60, 0x9090, 0x9170, 0x9210, 0x9270, 0x9280, 0x9250, 0x91d0, 0x9100, 0x8ff0, 0x8ea0, 0x8d20, 0x8b50, 0x8960, 0x8750, 0x8510, 0x82d0, 0x8070, 0x7e20, 0x7bd0, 0x7990, 0x7760, 0x7560, 0x7390, 0x71e0, 0x7080, 0x6f50, 0x6e70, 0x6dd0, 0x6d80, 0x6d70, 0x6db0, 0x6e30, 0x6f00, 0x7010, 0x7150, 0x72d0, 0x7480, 0x7650, 0x7840, 0x7a40, 0x7c40, 0x7e50, 0x8040, 0x8230, 0x83f0, 0x8590, 0x8700, 0x8830, 0x8920, 0x89d0, 0x8a30, 0x8a40, 0x8a00, 0x8970, 0x8890, 0x8760, 0x85e0, 0x8420, 0x8210, 0x7fd0, 0x7d60, 0x7ac0, 0x7800, 0x7530, 0x7250, 0x6f80, 0x6cb0, 0x6a00, 0x6770, 0x6510, 0x62f0, 0x6100, 0x5f70, 0x5e30, 0x5d40, 0x5cb0, 0x5c80, 0x5cb0, 0x5d40, 0x5e30, 0x5f80, 0x6120, 0x6310, 0x6540, 0x67b0, 0x6a60, 0x6d20, 0x7000, 0x72e0, 0x75c0, 0x7880, 0x7b20, 0x7d90, 0x7fb0, 0x8190, 0x8300, 0x8400, 0x8490, 0x84a0, 0x8420, 0x8310, 0x8170, 0x7f30, 0x7c50, 0x78e0, 0x74e0, 0x7050, 0x6b40, 0x65b0, 0x5fb0, 0x5960, 0x52c0, 0x4be0, 0x44d0, 0x3db0, 0x36a0, 0x2fd0, 0x28d0, 0x2240, 0x1c20, 0x1660, 0x1130, 0xc90, 0x8b0, 0x590, 0x330, 0x1c0, 0x130, 0, 0x190, 0x2f0, 0x540, 0x890, 0xcd0, 0x1210, 0x1830, 0x1f40, 0x2720, 0x2fc0, 0x3920, 0x4310, 0x7c0, 0x5890, 0x63e0, 0x6f70, 0x7b20}; int i; int j; int k=0; for(j=0;j<23;j++) { k=k+1; unsigned short DacData_up[90]={0};//上升沿数组 for(i=0;i<90 ;i++) { DacData_up[i]=(unsigned short)(k*DacData[i]/23); DA1_SetValue16(&DacData_up[i]);//180726 // user_delay_1ms(1); } } for(j=0;j<152;j++) { // Work_Choice(); //TestApp_Task(); for(i=0;i<259;i++) { DA1_SetValue16(&DacData2[i]);//180726 //user_delay_1ms(1); } } for(j=46;j>0;j--) { unsigned short DacData_up[90]={0};//上升沿数组 for(i=0;i<90;i++) { DacData_up[i]=(unsigned short)(j*DacData[i]/46); DA1_SetValue16(&DacData_up[i]);//180726 } } user_delay_1ms(200);
示波器显示波形
单个周期波形
组合后波形
上升沿大约30ms,高电平持续时间200ms,下降沿60ms,波形间隔200ms,频谱也符合要求,暂未上图,符合YY0709要求,大功告成,
注,不过在调试过程中通过采集蜂鸣器发出的声音波形,通过示波器观察蜂鸣器发出的波形,频谱的一倍频消失,暂未想到什么原因,后续更新~
原文地址:https://www.cnblogs.com/cat-final/p/9512710.html
时间: 2024-10-11 07:35:30