首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

[下载]AD转换实例

[下载]AD转换实例

#include "DSP281x_Device.h" // DSP281x Headerfile Include File

#include "DSP281x_Examples.h" // DSP281x Examples Include File

// Prototype statements for functions found within this file.

interrupt void adc_isr(void);

// Global variables used in this example:

Uint16 LoopCount;

Uint16 ConversionCount;

Uint16 Voltage1[1024];

Uint16 Voltage2[1024];

main()

{

InitSysCtrl(); //初始化cpu

DINT; //关中断

InitPieCtrl(); //初始化pie寄存器

IER = 0x0000; //禁止所有的中断

IFR = 0x0000;

InitPieVectTable();//初始化pie中断向量表

// Interrupts that are used in this example are re-mapped to

// ISR functions found within this file.

EALLOW; // This is needed to write to EALLOW protected register

PieVectTable.ADCINT = &adc_isr;

EDIS; // This is needed to disable write to EALLOW protected registers

AdcRegs.ADCTRL1.bit.RESET = 1; // Reset the ADC module

asm(" RPT #10 || NOP"); // Must wait 12-cycles (worst-case) for ADC reset to take effect

AdcRegs.ADCTRL3.all = 0x00C8; // first power-up ref and bandgap circuits

AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3; // Power up bandgap/reference circuitry

AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // Power up rest of ADC

// Enable ADCINT in PIE

PieCtrlRegs.PIEIER1.bit.INTx6 = 1;

IER |= M_INT1; // Enable CPU Interrupt 1

EINT; // Enable Global interrupt INTM

ERTM; // Enable Global realtime interrupt DBGM

LoopCount = 0;

ConversionCount = 0;

// Configure ADC

AdcRegs.ADCMAXCONV.all = 0x0001; // Setup 2 conv's on SEQ1

AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.

AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup ADCINA2 as 2nd SEQ1 conv.

AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1

AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)

// Configure EVA

// Assumes EVA Clock is already enabled in InitSysCtrl();

EvaRegs.T1CMPR = 0x0080; // Setup T1 compare value

EvaRegs.T1PR = 0x10; // Setup period register

EvaRegs.GPTCONA.bit.T1TOADC = 1; // Enable EVASOC in EVA

EvaRegs.T1CON.all = 0x1042; // Enable timer 1 compare (upcount mode)

// Wait for ADC interrupt

while(1)

{

LoopCount++;

}

}

interrupt void adc_isr(void)

{

Voltage1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;

Voltage2[ConversionCount] = AdcRegs.ADCRESULT1 >>4;

// If 40 conversions have been logged, start over

if(ConversionCount == 1023)

{

ConversionCount = 0;

}

else ConversionCount++;

// Reinitialize for next ADC sequence

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

return;

}

返回列表