⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ad.c

📁 2812的经典示例程序
💻 C
字号:

#include "DSP28_Device.h"

float	a1[16];
float   sample[1000];
unsigned int a2=0,count=0,isss;
float	adclo=0.0;

// Prototype statements for functions found within this file.
interrupt void ad(void);
void init_eva();

void main(void)
{

	InitSysCtrl();

	DINT;
	IER = 0x0000;
	IFR = 0x0000;

	InitPieCtrl();


	InitPieVectTable();	
	
	EALLOW;
   // Enable PWM pins
     GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6  pins
     GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
    EDIS;
	EALLOW;	// This is needed to write to EALLOW protected registers
	PieVectTable.ADCINT=&ad;
	EDIS;   // This is needed to disable write to EALLOW protected registers
    
    InitAdc();
    init_eva();
    for(isss=0;isss<2000;isss++)
    {sample[isss]=0;}

    // Enable INT14 which is connected to CPU-Timer 2:
	IER |= M_INT1;
	//KickDog();
    // Enable global Interrupts and higher priority real-time debug events:
	
	EINT;   // Enable Global interrupt INTM
	ERTM;	// Enable Global realtime interrupt DBGM
	while(AdcRegs.ADC_ST_FLAG.bit.SEQ1_BSY==0)
		{			

			AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;

		}

	for(;;)
	{
			KickDog();
	}
} 	


interrupt void ad(void)
{
	IFR=0x0000;
//	PieCtrl.PIEIFR1.all = 0;
	PieCtrl.PIEACK.all=0xffff;
	a2++;
	a1[0]=((float)AdcRegs.RESULT0)*3.0/65520.0+adclo;
/*	a1[1]=((float)AdcRegs.RESULT1)*3.0/65520.0+adclo;
	a1[2]=((float)AdcRegs.RESULT2)*3.0/65520.0+adclo;
	a1[3]=((float)AdcRegs.RESULT3)*3.0/65520.0+adclo;
	a1[4]=((float)AdcRegs.RESULT4)*3.0/65520.0+adclo;
	a1[5]=((float)AdcRegs.RESULT5)*3.0/65520.0+adclo;
	a1[6]=((float)AdcRegs.RESULT6)*3.0/65520.0+adclo;
	a1[7]=((float)AdcRegs.RESULT7)*3.0/65520.0+adclo;
	a1[8]=((float)AdcRegs.RESULT8)*3.0/65520.0+adclo;
	a1[9]=((float)AdcRegs.RESULT9)*3.0/65520.0+adclo;
	a1[10]=((float)AdcRegs.RESULT10)*3.0/65520.0+adclo;
	a1[11]=((float)AdcRegs.RESULT11)*3.0/65520.0+adclo;
	a1[12]=((float)AdcRegs.RESULT12)*3.0/65520.0+adclo;
	a1[13]=((float)AdcRegs.RESULT13)*3.0/65520.0+adclo;
	a1[14]=((float)AdcRegs.RESULT14)*3.0/65520.0+adclo;
	a1[15]=((float)AdcRegs.RESULT15)*3.0/65520.0+adclo;*/
	AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
	AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
	if (count<2000)
	{	sample[count++]=a1[0];}
	else
	{count=0;} 
	EINT;
	
	
}

void init_eva()
{

// EVA Configure T1PWM, T2PWM, PWM1-PWM6 
// Initalize the timers
   // Initalize EVA Timer1 
   EvaRegs.T1PR = 0xFFFF;       // Timer1 period
   EvaRegs.T1CMPR = 0x3C00;     // Timer1 compare
   EvaRegs.T1CNT = 0x0000;      // Timer1 counter
   // TMODE = continuous up/down
   // Timer enable
   // Timer compare enable
   EvaRegs.T1CON.all = 0x1042;   


  // Initalize EVA Timer2 
  EvaRegs.T2PR = 0x0FFF;       // Timer2 period
  EvaRegs.T2CMPR = 0x03C0;     // Timer2 compare
  EvaRegs.T2CNT = 0x0000;      // Timer2 counter
  // TMODE = continuous up/down
  // Timer enable
  // Timer compare enable
  EvaRegs.T2CON.all = 0x1042;   


  // Setup T1PWM and T2PWM
  // Drive T1/T2 PWM by compare logic
  EvaRegs.GPTCONA.bit.TCOMPOE =1;
  // Polarity of GP Timer 1 Compare = Active low
  EvaRegs.GPTCONA.bit.T1PIN = 1;
  // Polarity of GP Timer 2 Compare = Active high
  EvaRegs.GPTCONA.bit.T2PIN = 2;

  // Enable compare for PWM1-PWM6
  EvaRegs.CMPR1 = 0x8000;//PWM2
  //EvaRegs.CMPR2 = 0x3C00;
  //EvaRegs.CMPR3 = 0xFC00;
    
  // Compare action control.  Action that takes place
  // on a cmpare event
  // output pin 1 CMPR1 - active high
  // output pin 2 CMPR1 - active low
  // output pin 3 CMPR2 - active high
  // output pin 4 CMPR2 - active low
  // output pin 5 CMPR3 - active high
  // output pin 6 CMPR3 - active low
  EvaRegs.ACTR.all  = 0x0666;
  EvaRegs.DBTCONA.all = 0x0000; // Disable deadband
  EvaRegs.COMCONA.all = 0xA600;
  

} 


//===========================================================================
// No more.
//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -