#include "DSP28_Device.h"
#include"DSP281x_Examples.h"
#include"DSP28_PieVect.h"
interrupt void ad(void);
void init_eva(void);
void InitAdc(void);
void InitSci(void);
void main(void) {
InitSysCtrl();
DINT; //关CPU总中断
IER = 0x0000;//中断使能寄存器
IFR = 0x0000;//中断标志寄存器
InitPieCtrl(); //初始化PIE控制寄存器
InitPieVectTable(); //初始化PIE中断向量表
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &ad;
GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6 pins
EDIS; // This is needed to disable write to EALLOW protected registers
InitAdc();
init_eva(); //初始化EV-A
InitSci();
IER |= M_INT1;
EINT; // 使能INTM(全局中断)
ERTM; // Enable Global realtime interrupt DBGM
while(1) {
}
}
//EV-A初始化
void init_eva(void) {
EvaRegs.T1PR = 32768;//37500; 29296 //周期值--连续增减时,PWM频率=TCLK/(2*T1PR)---频率设为1K, PWM=75M/(2*37500)
EvaRegs.T1CMPR = 0x3C00; // Compare Reg--比较值
EvaRegs.T1CNT = 0x0000; //计数器初值
//连续增/减模式,x/64分频,内部时钟,使能比较,使用自己的周期,禁止定时器启动(等初始化全部完成后手工启动)
EvaRegs.T1CON.all = 0X0806;//0x0862;
EvaRegs.GPTCONA.bit.TCOMPOE = 1; //通过逻辑产生T1 PWM
EvaRegs.GPTCONA.bit.T1PIN = 1; //GP定时器1比较时低有效
//使能比较产生1--6 PWM波 1个比较单元控制2路互补的PWM输出,控制PWM占空比
//连续增减--低有效时:PWM占空比=CMPR1/T1PR,高有效时:PWM占空比=(T1PR-CMPR1)/T1PR
EvaRegs.CMPR1 = 16384;//937500; //第一路PWM占空比设为0.4,0.4=15000/37500
// output pin 1 CMPR1 - 高有效,output pin 2 CMPR1 - 低有效
EvaRegs.ACTR.all = 0x0666; //比较方式控制寄存器,控制PWM引脚的 高/低 有效
EvaRegs.DBTCONA.all = 0x0000; //静止死区
EvaRegs.COMCONA.all = 0xA600; //比较控制寄存器--禁止空间矢量PWM模式
EvaRegs.T1CON.bit.TENABLE=1; //手工启动定时器
}
interrupt void ad(void) {
int RESULTA0,RESULTB0,RESULTA2,RESULTB2;
IFR=0x0000;
PieCtrl.PIEACK.all=0xffff;
RESULTA0 = AdcRegs.RESULT0>>4;
RESULTB0 = AdcRegs.RESULT1>>4;
RESULTA0 += AdcRegs.RESULT2>>4;
RESULTB0 += AdcRegs.RESULT3>>4;
RESULTA0 += AdcRegs.RESULT4>>4;
RESULTB0 += AdcRegs.RESULT5>>4;
RESULTA0 += AdcRegs.RESULT6>>4;
RESULTB0 += AdcRegs.RESULT7>>4;
RESULTA0 = RESULTA0/4;
RESULTB0 = RESULTB0/4;
RESULTA2 = AdcRegs.RESULT8>>4;
RESULTB2 = AdcRegs.RESULT9>>4;
RESULTA2 += AdcRegs.RESULT10>>4;
RESULTB2 += AdcRegs.RESULT11>>4;
RESULTA2 += AdcRegs.RESULT12>>4;
RESULTB2 += AdcRegs.RESULT13>>4;
RESULTA2 += AdcRegs.RESULT14>>4;
RESULTB2 += AdcRegs.RESULT15>>4;
RESULTA2 = RESULTA2/4;
RESULTB2 = RESULTB2/4;
SciaRegs.SCITXBUF =RESULTA0;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
return;
}
void InitAdc(void) {
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3;//带隙合参考电路电源开
DELAY_US(5000L);
AdcRegs.ADCTRL3.bit.ADCPWDN = 1;//adc上电复位
DELAY_US(20L);
AdcRegs.ADCTRL3.bit.SMODE_SEL = 1;//同时采样模式
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;//级联
AdcRegs.MAX_CONV.all = 0x07;//8对通道
AdcRegs.CHSELSEQ1.bit.CONV00 = 0x0;
AdcRegs.CHSELSEQ1.bit.CONV01 = 0x0;
AdcRegs.CHSELSEQ1.bit.CONV02 = 0x0;
AdcRegs.CHSELSEQ1.bit.CONV03 = 0x0;
AdcRegs.CHSELSEQ2.bit.CONV04 = 0x2;
AdcRegs.CHSELSEQ2.bit.CONV05 = 0x2;
AdcRegs.CHSELSEQ2.bit.CONV06 = 0x2;
AdcRegs.CHSELSEQ2.bit.CONV07 = 0x2;
EvaRegs.GPTCONA.bit.T1TOADC = 1;
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1;//SEQ1被EVA的触发源启动
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;//使能中断
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
/*unsigned int i;
AdcRegs.ADCTRL1.bit.RESET=1;
AdcRegs.ADCTRL1.bit.RESET=0;
AdcRegs.ADCTRL1.bit.SUSMOD=3;
AdcRegs.ADCTRL1.bit.ACQ_PS=0;
AdcRegs.ADCTRL1.bit.CPS=0;
AdcRegs.ADCTRL1.bit.CONT_RUN=0;
AdcRegs.ADCTRL1.bit.SEQ_CASC=1;
AdcRegs.ADCTRL3.bit.ADCBGRFDN=3;
for(i=0; i<10000; i++);
AdcRegs.ADCTRL3.bit.ADCPWDN=1;
for(i=0; i<5000; i++);
AdcRegs.ADCTRL3.bit.ADCCLKPS=10;
AdcRegs.ADCTRL3.bit.SMODE_SEL=1;
AdcRegs.MAX_CONV.bit.MAX_CONV=7;//15;
AdcRegs.CHSELSEQ1.bit.CONV00 = 0x0;
AdcRegs.CHSELSEQ1.bit.CONV01 = 0x0;
AdcRegs.CHSELSEQ1.bit.CONV02 = 0x0;
AdcRegs.CHSELSEQ1.bit.CONV03 = 0x0;
AdcRegs.CHSELSEQ2.bit.CONV04 = 0x2;
AdcRegs.CHSELSEQ2.bit.CONV05 = 0x2;
AdcRegs.CHSELSEQ2.bit.CONV06 = 0x2;
AdcRegs.CHSELSEQ2.bit.CONV07 = 0x2;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ2_CLR=1;
AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ=0;
AdcRegs.ADCTRL2.bit.RST_SEQ1=0;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1=1;
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1=0;
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1=1;
AdcRegs.ADCTRL2.bit.EXT_SOC_SEQ1=0;
AdcRegs.ADCTRL2.bit.RST_SEQ2=0;
AdcRegs.ADCTRL2.bit.SOC_SEQ2=0;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ2=0;
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ2=0;
AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ2=0;
AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
EvaRegs.GPTCONA.bit.T1TOADC = 1;*/
}
void InitSci(void) {
// Initialize SCI-A:
EALLOW;
GpioMuxRegs.GPFMUX.all = 0x0030;
EDIS;
/* loopback 8 bit data */
SciaRegs.SCICCR.all = 0x07; // 1 bit stop, disable parity, idle mode, 8 bits data
SciaRegs.SCICTL1.all = 0x03; // enable TX
SciaRegs.SCICTL2.all = 0x03; //
////////////////////9600///19200/////
SciaRegs.SCIHBAUD = 0x00;//0x01;//0x00;
SciaRegs.SCILBAUD = 0xF3;//0x44;//0xa2;
SciaRegs.SCICTL1.all = 0x23;
SciaRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}
|