本帖最后由 毛毛只爱宝宝 于 2017-9-15 10:23 编辑
采集的是一个正弦波,通过数组Voltage1来观察数据和波形。但是采样值基本无变化,这是为什么呢?下面附上程序:
主函数:
void main(void)
{
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/2*ADC_MODCLK
EDIS;
int i;
InitSysCtrl();//初始化系统函数
IER = 0x0000;//禁止CPU中断
IFR = 0x0000;//清除CPU中断标志
InitPieCtrl();//初始化PIE控制寄存器
InitPieVectTable();//初始化PIE中断向量表
InitCpuTimers();
InitEPwm1Gpio();
InitEPwm2Gpio();
InitEPwm3Gpio();
DINT;
InitAdc();//ADC初始化
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//禁止PWM时钟
EDIS;
InitEPwm1Example();
InitEPwm2Example();
InitEPwm3Example();
ConfigCpuTimer(&CpuTimer0,30,1000);
StartCpuTimer0();//启动定时器0
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;//使能PIE模块的总中断
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//使能PWM时钟
EDIS;
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.TINT0 = &TINT0_ISR;//使能Timer0中断
PieVectTable.ADCINT = &ADCINT_ISR;//使能ADC中断
EDIS; // This is needed to disable write to EALLOW protected registers
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //使能PIE中断的CPU定时器0
PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //使能PIE中断中的ADC中断
IER |= (M_INT1); // Enable CPU Interrupt 1
EINT; //使能全局中断
ERTM; //使能实时中断
for (i=0; i<BUF_SIZE; i++)
{
Voltage1[i] = 0;
Voltage2[i] = 0;
Voltage3[i] = 0;
}
定时器中断函数:Uint16 q=0;
interrupt void TINT0_ISR(void) // CPU-Timer 0
{
// Insert ISR Code here
q++;//判断是否进入中断
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;//软件触发启动SEQ1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
ADC中断函数:
Uint16 qa=0;
interrupt void ADCINT_ISR(void) // ADC
{
// Insert ISR Code here
qa++;//判断是否进入中断
// To receive more interrupts from this PIE group, acknowledge this interrupt
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
Uint16 a[10],b[10],c[10];
Uint16 i,j,r,s,t;
Voltage1[ConversionCount1++] = AdcRegs.ADCRESULT0 >>4;
Voltage2[ConversionCount2++] = AdcRegs.ADCRESULT1 >>4;
Voltage3[ConversionCount3++] = AdcRegs.ADCRESULT2 >>4;
if(ConversionCount1>(511))
ConversionCount1=0;
DELAY_US(100);
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
ADC初始化函数:
extern void DSP28x_usDelay(Uint32 Count);
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;//使能ADC时钟
ADC_cal();
EDIS;
AdcRegs.ADCTRL1.bit.RESET = 1; //Reset ADC module
asm(" RPT #20||NOP");
AdcRegs.ADCTRL3.all = 0x00E0; // 给ADC内部上电
DELAY_US(ADC_usDELAY); // 在ADC转换前要延时一段时间
AdcRegs.ADCTRL1.bit.ACQ_PS = 0xff; // Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
// = 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 = 0;//不分频
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.ADCMAXCONV.bit.MAX_CONV1 = 0x2; // convert and store in 8 results registers
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2;// Setup ADCINA2 as 2nd SEQ1 conv.
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // 向CPU发出中断申请
|