|
技术交流 | 电路欣赏 | 工控天地 | 数字广电 | 通信技术 | 电源技术 | 测控之家 | EMC技术 | ARM技术 | EDA技术 | PCB技术 | 嵌入式系统 驱动编程 | 集成电路 | 器件替换 | 模拟技术 | 新手园地 | 单 片 机 | DSP技术 | MCU技术 | IC 设计 | IC 产业 | CAN-bus/DeviceNe |
谐波计算程序请教 |
作者:hadison 栏目:测控之家 |
请教各位,有谁写过谐波计算的程序。看过美信的片文章,程序如下: 需要怎么修改才能用,我现在采样64点16位补码的数组,需要计算到21次谐波。希望有高人指点一下! /* ******************************************************************** * maxqfft.c * * July 01, 2005 * * Paul Holden (Paul_Holden@maximhq.com) * MAXIM Integrated Products * * SOFTWARE COMPILES USING IAR EMBEDDED WORKBENCH FOR MAXQ * * NOTE: All fft input/outputs are signed and in Q8.7 notation * * COPYRIGHT (C) 2005 MAXIM/Dallas SEMICONDUCTOR.html">SEMICONDUCTOR CORPORATION, * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this SOFTWARE and associated documentation files (the "SOFTWARE"), * to deal in the SOFTWARE without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the SOFTWARE, and to permit persons to whom the * SOFTWARE is furnished to do so, subject to the following conditions: * * The above COPYRIGHT notice and this permission notice shall be included * in all copies or substantial portions of the SOFTWARE. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL MAXIM/DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the NAME of MAXIM/Dallas SEMICONDUCTOR.html">SEMICONDUCTOR * shall not be used except as stated in the MAXIM/Dallas SEMICONDUCTOR.html">SEMICONDUCTOR * Branding Policy. * ******************************************************************** */ // INCLUDE STATEMENTS --------------------------- #include "iomaxq200x.h" #include "maxqfft.h" #include <intrinsics.h> // DEFINE STATEMENTS ---------------------------- #define NOP __no_operation() /* * Windowing: Uncomment one of the following define * statements to enable the corresponding windowing * function on input SAMPLEs.html">SAMPLEs. Comment all to disable * windowing. */ //#define WINDOWING_HAMMING //#define WINDOWING_HANN /* * x_n_re * * This array will store the FFT input SAMPLEs.html">SAMPLEs, x(n), * and the real PART of the spectrum, X(n). */ __no_init int x_n_re[N]; /* * tmp_32 * * a union that allows accessing the individual 16-bit * words of a 32-bit double word as well as the entire * double word. This union is used by the multiplication * macros that make use of the HARDWARE multiplier and * convert the multiplication result to Q8.7 notation. */ __no_init union { LONG tmp_32; struct { int LSW; // Least Significant 16-bit Word int MSW; // Most Significant 16-bit Word } tmp_16; }; /* * HARDWARE Multiplier Macros * * These macros are used to access the HARDWARE multiplier. For * the MAXQ, registers MA and MB are the HARDWARE multiplier * operands while MC1:MC0 store the HARDWARE multiplier result. * * (1) MUL_1(A,B,C) : C=A*B (result converted to Q8.7 notation) * (2) MUL_2(A,C) : C=A*MB (result converted to Q8.7 notation) * (3) MUL_INIT(B) : MB=B * (4) MUL_NC(A,C) : C=A*MB (result not converted to Q8.7 notation) */ #define MUL_1(A,B,C) MA=A;MB=B; NOP; tmp_16.LSW=MC0; tmp_16.MSW=MC1; C=tmp_32>>7 #define MUL_2(A,C) MA=A; NOP; tmp_16.LSW=MC0; tmp_16.MSW=MC1; C=tmp_32>>7 #define MUL_INIT(B) MB=B #define MUL_NC(A,C) MA=A; NOP; C=MC0 /* * initADC() * * Initializes the ADC to send SINGLE channel 8-bit data to the * MAXQ. REFER to the included CIRCUIT schematic for connection * information. */ void initADC() { __no_init unsigned int i; // Configure the MAXQ GPIO pins for a write to the ADC // configuration register. PD0 = 0xFF; PD1 = 0xFF; PD2 = 0x3F; PO0 = 0x04; PO1 = 0x00; PO2 = 0xDF; // Waste time to allow ADC to exit shutdown mode for(i=0; i<2048; i++) __no_operation(); // Enable the ADC Channel 0 PO2_bit.bit2 = 0; NOP; // ADC /CS pin low PO2_bit.bit1 = 0; NOP; // ADC /WR pin low PO2_bit.bit1 = 1; NOP; // ADC /WR pin high // Configure the MAXQ GPIO pins to read SAMPLEs.html">SAMPLEs // from the ADC PD0 = 0x00; PD1 = 0x00; PO0 = 0x00; // Send DUMMY byte to ADC PO2_bit.bit3 = 0; NOP; // ADC CONVST pin low PO2_bit.bit3 = 1; NOP; // ADC CONVST pin high while(!PO2_bit.bit7); // Wait for End-Of-Last-Conversion flag PO2_bit.bit0 = 0; NOP; // ADC /RD pin low PO2_bit.bit0 = 1; NOP; // ADC /RD pin high PO2_bit.bit2 = 1; // ADC /CS pin high } /* * getSamplesFromADC() * * Captures N 8-bit SAMPLEs.html">SAMPLEs (in 2's complement format) from * the ADC and stores them in the array x_n_re. If windowing * is enabled, the data will be multiplied by the * appropriate function. */ void getSamplesFromADC() { /* 1. Init variables */ __no_init unsigned int i; int *ptr_x_n_re = x_n_re; /* 2. Set ADC /CS pin low to enable interface */ PO2_bit.bit2 = 0; /* 3. Capture 256 SAMPLEs.html">SAMPLEs from the ADC. This loop does not include any decision structure to ensure that the sampling rate is consistent. Delays are also introduced to force a sampling rate of 200ksps. */ for(i=0; i<256; i++) { /* 3.1. Acquire SAMPLE */ PO2_bit.bit3 = 0; // ADC CONVST pin low NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP; // Wait tacq PO2_bit.bit3 = 1; // ADC CONVST pin high /* 3.2. Wait for SAMPLE to convert */ NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP;NOP; NOP;NOP; // Wait for t |
2楼: | >>参与讨论 |
作者: simplelive 于 2006/11/26 14:37:00 发布:
用的什么芯片?? |
|
|
免费注册为维库电子开发网会员,参与电子工程师社区讨论,点此进入 |
Copyright © 1998-2006 www.dzsc.com 浙ICP证030469号 |