基于tms320f28027做信号采集,通过定时器触发adc采样。为fft变换提供数据。预采样信号为10kHz,幅度为2Vpp。但是采样结果有些不明白,具体看图。
首先主要函数如下:
//ADC采样
#include "DSP28x_Project.h"
interrupt void cpu_timer0_isr(void);
interrupt void adc_isr(void);
void Adc_Config(void);
void InitAdc(void);
Uint16 LoopCount=0;
Uint16 ConversionCount=0;
Uint16 Voltage1[64];
void main(void)
{
InitSysCtrl();//系统初始化
// InitGpio();
DINT;//禁止可屏蔽中端
InitPieCtrl();//初始化PIE控制器
IER = 0x0000;//禁止cpu中断并清除cpu所有中断标志
IFR = 0x0000;
InitPieVectTable();//为PIE向量表中的所有中断向量配置对应入口地址
EALLOW; //将入口地址赋给中断向量
PieVectTable.TINT0 = &cpu_timer0_isr;
PieVectTable.ADCINT1 = &adc_isr;
EDIS;
InitCpuTimers(); //初始化定时器
InitAdc();//初始化ADC模块
ConfigCpuTimer(&CpuTimer0, 60, 50);//采样速率
CpuTimer0Regs.TCR.all = 0x4001;
IER |= M_INT1;//使cpu第一组中断
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;//使能PIE中等的ADCINT,1组第8个中断
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;//使能PIE中等的ADCINT,1组的第2个中断
EINT;//允许可屏蔽中断(清楚INTM位)
ERTM; //使能全局实时中断
// 配置ADC
EALLOW;
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //结果存入寄存器产生中断
AdcRegs.INTSEL1N2.bit.INT1E = 1; //中断使能
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //非连续采样模式
AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //中断线1选择soc1
AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; //soc通道选择
AdcRegs.ADCSOC1CTL.bit.CHSEL = 2;
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //soc触发选择
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 5;
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //采样时间
AdcRegs.ADCSOC1CTL.bit.ACQPS = 6;
EDIS;
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start
// 循环
for(;;)
{
LoopCount++;
}
}
interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;
AdcRegs.ADCINT标志寄存器CLR.bit.ADCINT1 = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
interrupt void adc_isr(void)
{
Voltage1[ConversionCount] = AdcResult.ADCRESULT0;
if(ConversionCount == 631)
{
ConversionCount = 0;
}
else ConversionCount++;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
void InitAdc(void)
{
extern void DSP28x_usDelay(Uint32 Count);
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
(*Device_cal)();
EDIS;
EALLOW;
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1; // Power ADC BG
AdcRegs.ADCCTL1.bit.ADCREFPWD = 1; // Power reference
AdcRegs.ADCCTL1.bit.ADCPWDN = 1; // Power ADC
AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC
AdcRegs.ADCCTL1.bit.ADCREFSEL = 0; // Select interal BG
EDIS;
DELAY_US(5000L); // Delay before converting ADC channels
}
void InitAdcAio()
{
EALLOW;
}
用信号发生器输出了10khz 2vpp的信号的正弦信号,为什么失真那么厉害。。
|