[求助] 关于dma的ad采集

了无痕迹01   2015-8-21 15:52 楼主
使用epwm触发adc转换后开启DMA传输,因为我只采集A0的数据,所以一次传输就传1个数据,再等epwm信号,来一个epwm信号就传输一次,共传输1024个数据后进DMA中断,也就是说epwm是采样频率。。。。但是结果发现数据是都正确,但是调试的时候没有进中断。。。。哪位大神能解答一下,,,谢谢了
#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File
#define ADC_SHCLK  0xf   // S/H width in ADC module periods
#define ADC_CKPS   0x1   // ADC module clock = HSPCLK/1
// Prototype statements for functions found within this file.
interrupt void local_DINTCH1_ISR(void);
#pragma DATA_SECTION(DMABuf1,"DMARAML4");

// Global variables used in this example:
volatile Uint16 *DMADest;
volatile Uint16 *DMASource;
volatile Uint16 DMABuf1[1024];
Uint16 flag=0;
main()
{
  
   Uint16 i=0;
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();

   EALLOW;
   #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
   
   SysCtrlRegs.HISPCP.all = ADC_MODCLK;// HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3)   = 25.0 MHz
   EDIS;

   DINT;
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();
    // Clear Table
  for (i=0; i<1024; i++)
   {
     DMABuf1[i] = 1;
   }
// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;
   InitPieVectTable();
// 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.DINTCH1= &local_DINTCH1_ISR;
   EDIS;    // This is needed to disable write to EALLOW protected registers

   IER = M_INT7 ;                              //Enable INT7 (7.1 DMA Ch1)
   EnableInterrupts();



//  Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   InitAdc();  // For this example, init the ADC


// Configure ADC
   AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;  //采样窗设置,尽量大点
   AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; //分频
   AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;        //级联模式   1  Cascaded mode
   AdcRegs.ADCMAXCONV.all = 0x0000;         // 通道数为1个    Setup 1 conv's on SEQ1
   AdcRegs.ADCTRL2.bit.RST_SEQ1 = 0x1;      //初始化SEQ1
   AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;   // 设置ADCINA0为第一采集通道   Setup ADCINA0 as 1st SEQ1 conv.
   AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;  // 允许epwm为触发SEQ1         Enable SOCA from ePWM to start SEQ1
   AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;    //允许INT_SEQ1向CPU发出中断申请      Enable SEQ1 interrupt (every EOS)

// Configure ePWM1 设置1k的采样频率
  
   EPwm1Regs.ETSEL.bit.SOCAEN = 1;        // Enable SOC on A group
   EPwm1Regs.ETSEL.bit.SOCASEL = 2;       // 当TBCTR=TBPRD时产生epwm1soca信号
   EPwm1Regs.ETPS.bit.SOCAPRD = 1;        //在第一个事件时,产生SOC信号   Generate pulse on 1st event

   EPwm1Regs.TBCTR=0;                     //对时基计数器清0
   EPwm1Regs.TBPRD = 0x61A7;              // Set period for ePWM1
   EPwm1Regs.TBCTL.bit.HSPCLKDIV=3;       //TBCLK=25Mhz
   EPwm1Regs.TBCTL.bit.CTRMODE = 0;                  // count up and start

// Initialize DMA
   DMAInitialize();
// Configure DMA Channel
   DMADest   = &DMABuf1[0];              //Point DMA destination to the beginning of the array
   DMASource = &AdcMirror.ADCRESULT0;    //Point DMA source to ADC result register base
   DMACH1AddrConfig(DMADest,DMASource);
   DMACH1BurstConfig(0,0,1);                 
   DMACH1TransferConfig(1023,0,1);              
   DMACH1WrapConfig(0,0,0xFFFF,0);            
   DMACH1ModeConfig(DMA_SEQ1INT,PERINT_ENABLE,ONESHOT_DISABLE,CONT_ENABLE,SYNC_DISABLE,SYNC_SRC,
                  OVRFLOW_DISABLE,SIXTEEN_BIT,CHINT_END,CHINT_ENABLE);

   StartDMACH1();

   for(;;)
   {
   
   }

}


interrupt void  local_DINTCH1_ISR(void)
{
   // Acknowledge this interrupt to receive more interrupts from group 7
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP7;
  //  asm ("      ESTOP0");
        flag++;
}

回复评论 (2)

哎  都没人回答吗,就是通过epwm来设置采样频率
点赞  2015-8-21 21:33
不会,,,帮顶。。。。
分享铸就美好未来。。。
点赞  2015-8-22 12:28
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复