2812 AD模块如何能求得一正弦信号的峰值啊

caisofs   2010-5-3 10:44 楼主
RT,我想用2812做一个扫频仪,所以需要用DSP采正弦信号的峰值(得知道峰值是多少V),可是具体怎么实现呢?求高人指点指点


以下是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;
}

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复