打印
[DSP编程]

28335用ADC的时候进不了中断是为什么?

[复制链接]
2087|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jiaoyun15|  楼主 | 2017-2-21 20:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ADC, se, BLE, pi, TE
在while(1)循环里面进行采样可以,为什么到了中断里面就不行了,没有用EPWM.


程序#######


#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

// Determine when the shift to right justify the data takes place
// Only one of these should be defined as 1.
// The other two should be defined as 0.
#define POST_SHIFT   0  // Shift results after the entire sample table is full
#define INLINE_SHIFT 1  // Shift results as the data is taken from the results regsiter
#define NO_SHIFT     0  // Do not shift the results

// ADC start parameters
#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
#define ADC_CKPS   0x0   // ADC module clock = HSPCLK/1      = 25.5MHz/(1)   = 25.0 MHz
#define ADC_SHCLK  0x1   // S/H width in ADC module periods                  = 2 ADC cycle
#define AVG        1000  // Average sample limit
#define ZOFFSET    0x00  // Average Zero offset
#define BUF_SIZE   512  // Sample buffer size

// Global variable for this example
double SampleTable[BUF_SIZE];
Uint16 voltage=0xff;
Uint16  array_index=0;
interrupt void ADCcaiyang(void);
void indexover();

main()
{
   Uint16 i;
  // Uint16 voltage;
   

   InitSysCtrl();

   EALLOW;
   SysCtrlRegs.HISPCP.all = ADC_MODCLK;        // HSPCLK = SYSCLKOUT/ADC_MODCLK
   EDIS;

   /*
   EALLOW;
   GpioCtrlRegs.GPBMUX1.bit.GPIO34 = 0;    // GPIO pin
   GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1;     // Output pin
   EDIS;
   */

   DINT;

   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

   InitPieVectTable();

   InitAdc();         // For this example, init the ADC

    EALLOW;               //定时器0的中断入口地址为中断向量表的INT0
          PieVectTable.ADCINT = & ADCcaiyang;
        //PieVectTable.TINT0 = &ISRTimer0;
    EDIS;   
   

     IER |= M_INT1;
         PieCtrlRegs.PIEIER1.bit.INTx6 = 1;               //开启ADC中断通道

     EINT;   // Enable Global interrupt INTM
     ERTM;   // Enable Global realtime interrupt DBGM\

// Specific ADC setup for this example:
   AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;  // 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 = ADC_CKPS;
   AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;        // 1  Cascaded mode
   //AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x1;   //select ADCINA1
   AdcRegs.ADCTRL1.bit.CONT_RUN = 1;       // Setup continuous run

   AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1;       // Enable Sequencer override feature
   AdcRegs.ADCCHSELSEQ1.all = 0x0;         // Initialize all ADC channel selects to A0
   AdcRegs.ADCCHSELSEQ2.all = 0x0;
   AdcRegs.ADCCHSELSEQ3.all = 0x0;
   AdcRegs.ADCCHSELSEQ4.all = 0x0;
   AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x1;  // convert and store in 8 results registers
   AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;    //enable interrupt
   AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1 = 0;    //interrupt mode 0
   AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;




// Clear SampleTable
   for (i=0; i<BUF_SIZE; i++)
   {
     SampleTable[i] = 0;

   }


// Start SEQ1
   AdcRegs.ADCTRL2.all = 0x2000;

        while(1)
        {
                //array_index = 0;
                //while(AdcRegs.ADCST.bit.INT_SEQ1 == 0);  //=0 no interrupt event happenes
                //GpioDataRegs.GPBSET.bit.GPIO34 = 1;  // Set GPIO34 for monitoring  -optional
        //        AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
               
                //voltage = ((AdcRegs.ADCRESULT0)>>4);
                //SampleTable[array_index++]= voltage*3.3/4095;
                //if(array_index>(BUF_SIZE-1)) array_index=0;
                indexover();
                DELAY_US(100);
        }
}               


void indexover()
{
  if(array_index>(BUF_SIZE-1))
  {
    array_index=0;
  }
}


interrupt void ADCcaiyang(void)
{
                voltage = ((AdcRegs.ADCRESULT0)>>4);
                SampleTable[array_index++]= voltage*3/4095;
                AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;   
                AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
                PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

4

帖子

0

粉丝