TI中文支持网
TI专业的中文技术问题搜集分享网站

调用函数出现问题求解决

因为需要做实验在DA例程的基础上改的一个AD-DA程序,但是在调用自己编写的MA函数时发现错误,编译说MA未定义,求解决

#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include <stdint.h>
#define DA_CHA *(Uint16 *)0x4040
#define DA_CHB *(Uint16 *)0x4041
#define DA_CHC *(Uint16 *)0x4042
#define DA_CHD *(Uint16 *)0x4043
#define DA_TRANS *(Uint16 *)0x40E0

// Determine when the shift to right justify the data takes place
// Only one of these should be defined as 1.
// The other two should be defined as 0.
#define POST_SHIFT 0 // Shift results after the entire sample table is full
#define INLINE_SHIFT 1 // Shift results as the data is taken from the results regsiter
#define NO_SHIFT 0 // Do not shift the results

// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default – 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x8 // ADC module clock = HSPCLK/1 = 25.5MHz/(1) = 25.0 MHz
#define ADC_SHCLK 0x7 // S/H width in ADC module periods = 2 ADC cycle
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 512 // Sample buffer size

// Global variable for this example

void main(void)

{
InitSysCtrl();

EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;

DINT;

InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();
InitXintf();

InitAdc(); // For this example, init the ADC

// Specific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL1.bit.CPS = 1; // = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
// = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run

AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; // Enable Sequencer override feature
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;// Initialize all ADC channel selects to A0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3;

AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x3; // convert and store in 8 results registers

// Clear SampleTable

SampleTable[0] = 0;
SampleTable[1] = 0;
SampleTable[2] = 0;
SampleTable[3] = 0;

// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;

while(1)
{
// array_index = 0;
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0);
// GpioDataRegs.GPBSET.bit.GPIO34 = 1; // Set GPIO34 for monitoring -optional
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[0] = ( (AdcRegs.ADCRESULT0)>>4);
SampleTable[1] = ( (AdcRegs.ADCRESULT1)>>4);
SampleTable[2] = ( (AdcRegs.ADCRESULT2)>>4);
SampleTable[3] = ( (AdcRegs.ADCRESULT3)>>4);

for(i=0;i<K;i++)
{error[i]=SampleTable[i];}
error[0]=SampleTable[0];

for (i=L-1; i>0; i–)
{ref[i] = ref[i-1];}
ref[0]=SampleTable[K];

for (j=0; j<J; j++)
{
for (k=0; k<K; k++)
{
for (i=L-1; i>0; i–)
ref_f[j][k][i] = ref_f[j][k][i-1];
//参考信号乘以次级通道模型
ref_f[j][k][0] = MA(ref, &secondary[j][k][0], L);
}
}

for (j=0; j<J; j++)
{for (k=0; k<K; k++)
ref_ff[j][k] = MA(&ref_f[j][k][0], &ref_f[j][k][0], L);
}
for (j=0; j<J; j++)
{
for (k=0; k<K; k++)
{
/*
if (error[k]>step) error_f = 1.0;
else if (error[k]<step*(-1)) error_f = -1.0;
else error_f = error[k]/step;*/
for (i=0; i<L-1; i++)
{
weight[j][i] -= step*ref_f[j][k][i]*error[k]/(ref_ff[j][k]+0.0001);//*error[k]/(ref_ff[j][k]);//*e[k]/(ref_ff[j][k]);

}
}
}

for (j=0; j<J; j++)
{

output[j] = MA(&weight[j][0], ref, L);
}

DA_CHB = output[0];
DA_TRANS = 1;
DELAY_US(100);
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; // Clear GPIO34 for monitoring -optional
}

}

double MA(double *a, double *b, int len)
{
double result=0;
int i;
for (i=0; i<len; i++)
{
result+=a[i]*b[i];
}
return result;

}

Yu Feng Dai:

好吧,问题自己解决了…把MA放在main函数前面就行了,就是不是很懂为什么按照C的习惯为什么不能放在后面

因为需要做实验在DA例程的基础上改的一个AD-DA程序,但是在调用自己编写的MA函数时发现错误,编译说MA未定义,求解决

#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include <stdint.h>
#define DA_CHA *(Uint16 *)0x4040
#define DA_CHB *(Uint16 *)0x4041
#define DA_CHC *(Uint16 *)0x4042
#define DA_CHD *(Uint16 *)0x4043
#define DA_TRANS *(Uint16 *)0x40E0

// Determine when the shift to right justify the data takes place
// Only one of these should be defined as 1.
// The other two should be defined as 0.
#define POST_SHIFT 0 // Shift results after the entire sample table is full
#define INLINE_SHIFT 1 // Shift results as the data is taken from the results regsiter
#define NO_SHIFT 0 // Do not shift the results

// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default – 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x8 // ADC module clock = HSPCLK/1 = 25.5MHz/(1) = 25.0 MHz
#define ADC_SHCLK 0x7 // S/H width in ADC module periods = 2 ADC cycle
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 512 // Sample buffer size

// Global variable for this example

void main(void)

{
InitSysCtrl();

EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;

DINT;

InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();
InitXintf();

InitAdc(); // For this example, init the ADC

// Specific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL1.bit.CPS = 1; // = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
// = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run

AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; // Enable Sequencer override feature
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;// Initialize all ADC channel selects to A0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3;

AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x3; // convert and store in 8 results registers

// Clear SampleTable

SampleTable[0] = 0;
SampleTable[1] = 0;
SampleTable[2] = 0;
SampleTable[3] = 0;

// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;

while(1)
{
// array_index = 0;
while(AdcRegs.ADCST.bit.INT_SEQ1 == 0);
// GpioDataRegs.GPBSET.bit.GPIO34 = 1; // Set GPIO34 for monitoring -optional
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[0] = ( (AdcRegs.ADCRESULT0)>>4);
SampleTable[1] = ( (AdcRegs.ADCRESULT1)>>4);
SampleTable[2] = ( (AdcRegs.ADCRESULT2)>>4);
SampleTable[3] = ( (AdcRegs.ADCRESULT3)>>4);

for(i=0;i<K;i++)
{error[i]=SampleTable[i];}
error[0]=SampleTable[0];

for (i=L-1; i>0; i–)
{ref[i] = ref[i-1];}
ref[0]=SampleTable[K];

for (j=0; j<J; j++)
{
for (k=0; k<K; k++)
{
for (i=L-1; i>0; i–)
ref_f[j][k][i] = ref_f[j][k][i-1];
//参考信号乘以次级通道模型
ref_f[j][k][0] = MA(ref, &secondary[j][k][0], L);
}
}

for (j=0; j<J; j++)
{for (k=0; k<K; k++)
ref_ff[j][k] = MA(&ref_f[j][k][0], &ref_f[j][k][0], L);
}
for (j=0; j<J; j++)
{
for (k=0; k<K; k++)
{
/*
if (error[k]>step) error_f = 1.0;
else if (error[k]<step*(-1)) error_f = -1.0;
else error_f = error[k]/step;*/
for (i=0; i<L-1; i++)
{
weight[j][i] -= step*ref_f[j][k][i]*error[k]/(ref_ff[j][k]+0.0001);//*error[k]/(ref_ff[j][k]);//*e[k]/(ref_ff[j][k]);

}
}
}

for (j=0; j<J; j++)
{

output[j] = MA(&weight[j][0], ref, L);
}

DA_CHB = output[0];
DA_TRANS = 1;
DELAY_US(100);
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; // Clear GPIO34 for monitoring -optional
}

}

double MA(double *a, double *b, int len)
{
double result=0;
int i;
for (i=0; i<len; i++)
{
result+=a[i]*b[i];
}
return result;

}

Seven Han:

回复 Yu Feng Dai:

不好意思呢,自己编写的函数需要先声明后使用,如果函数写在main函数前,就不需要声明了。

赞(0)
未经允许不得转载:TI中文支持网 » 调用函数出现问题求解决
分享到: 更多 (0)