打印
[DSP编程]

有关TMS320F28027 EPWM、比较器、模拟输入输出(AIOn)的问题

[复制链接]
2492|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
JKM99|  楼主 | 2014-11-28 15:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 JKM99 于 2014-11-28 15:38 编辑

使用Proteus仿真TMS320F28027遇到如下几个问题,希望大家指导,谢谢!

void main1(void)
{
/****************************************************************************
  *模拟引脚输出测试:
  * Proteus仿真,AIO6引脚接2K上拉电阻时:
  *   执行GpioDataRegs.AIODAT.bit.AIO6 = 1;输出只有100~200mv,
  *   没接上拉电阻时输出更小22mV左右,执行上述语句为什么输出不是3.3V左右呢 ?
  ****************************************************************************/
InitSysCtrl();
EALLOW;
GpioCtrlRegs.AIOMUX1.bit.AIO6 = 0;//AIO6 enable
GpioCtrlRegs.AIODIR.all = 0x1<<6;//output
EDIS;
for(;;)
{
  //GpioDataRegs.AIOSET.bit.AIO6 = 1;
  GpioDataRegs.AIODAT.bit.AIO6 = 1;
  DELAY_US(200);
  //GpioDataRegs.AIOCLEAR.bit.AIO6 = 0;
  GpioDataRegs.AIODAT.bit.AIO6 = 0;
  DELAY_US(200);
}
}

//===============================================
void main2(void)
{
/*******************************************************
  * 模拟引脚输入测试:
  * AIO14引脚接一个接入电位器,从0V调到3.3V调整输入电压,
  * 为什么GPIO38引脚输出没变化?
  ******************************************************/
InitSysCtrl();
EALLOW;
GpioCtrlRegs.AIOMUX1.bit.AIO14 = 0;//AIO14 enable
GpioCtrlRegs.AIODIR.bit.AIO14 = 0; //input
//Configure the GPIO38 as general purpose I/O and enable the internal pullup
GpioCtrlRegs.GPBMUX1.bit.GPIO38 = 0; //I/O
GpioCtrlRegs.GPBDIR.bit.GPIO38 = 1; //output
GpioCtrlRegs.GPBPUD.bit.GPIO38 = 0; //enable the internal pullup
EDIS;
for(;;)
{
  if(GpioDataRegs.AIODAT.bit.AIO14==1)
  {
   GpioDataRegs.GPBDAT.bit.GPIO38 = 1;
  }
  else
  {
   GpioDataRegs.GPBDAT.bit.GPIO38 = 0;
  }
}
}

//================================================================================
void main3(void)
{
/**************************************************************************
  * 比较器测试:
  * AIO2、AIO10配置为比较器的输入引脚,分别接一个接入电位器,分别调整两个引脚的
  * 输入电压,在COMP1A > COMP1B 和 COMP1A<COMP1B情况下 GPIO38与COMP1OUT引脚输出没有变化
  * 程序如下,问题在哪里呢?
  **************************************************************************/
InitSysCtrl();
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO38 = 0; //enable the internal pullup
GpioCtrlRegs.GPBMUX1.bit.GPIO38 = 0; //I/O
GpioCtrlRegs.GPBDIR.bit.GPIO38 = 1; //output
//GpioCtrlRegs.GPAPUD.bit.GPIO1 = 1;     // Disable pull-up for GPIO1 (CMP1OUT)
//GpioCtrlRegs.GPADIR.bit.GPIO1 = 1;   //output
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 3;    // Configure GPIO1 for CMP1OUT operation
GpioCtrlRegs.AIOMUX1.bit.AIO2 = 3;    //AIO2 disabled --- COMP1A
GpioCtrlRegs.AIOMUX1.bit.AIO10 = 3;   //AIO10 disabled --- COMP1B

SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; //the ADC module is clocked
AdcRegs.ADCCTL1.bit.ADCPWDN = 1;   //The analog circuitry inside the core is powered up
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1;   //Bandgap buffer's curcuitry inside core is powered up
SysCtrlRegs.PCLKCR3.bit.COMP1ENCLK = 1;
SysCtrlRegs.PCLKCR3.bit.COMP2ENCLK = 1;
Comp1Regs.COMPCTL.bit.COMPDACEN  = 1;  //comparator/DAC logic is powered up
Comp1Regs.COMPCTL.bit.COMPSOURCE = 1;  //inverting input connected to exteranl pin
Comp1Regs.COMPCTL.bit.SYNCSEL = 0;    //asynchronous
Comp1Regs.COMPCTL.bit.QUALSEL = 0;   //Synchronized value of comparator is passed through
Comp1Regs.COMPCTL.bit.CMPINV = 1;   //Output of comparator is passed
EDIS;
for(;;)
{
  if(Comp1Regs.COMPSTS.bit.COMPSTS==1)
  {
   GpioDataRegs.GPBDAT.bit.GPIO38 = 1;
  }
  else
  {
   GpioDataRegs.GPBDAT.bit.GPIO38 = 0;
  }
}
}


//=============================================================
unsigned int Duty=500;
interrupt void EPwm1TimerIsr(void)
{
EPwm1Regs.CMPA.half.CMPA = Duty;
EPwm1Regs.CMPB = Duty;
if(++Duty==600){Duty = 1;}
EPwm1Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void main(void)
{
/*************************************************************************
  *  PWM互补输出测试程序:
  *  试验输出了两路互补的信号,但是...
  *  执行EPwm1Regs.ETFRC.bit.INT = 1;可以进入中断服务程序 ,这说明中断使能位设置正确,
  *  为什么注释掉该条语句后无法进入中断服务程序,程序如下,导致此问题的原因是什么呢?
  ***********************************************************************/
InitSysCtrl();
EALLOW;
GpioCtrlRegs.GPBPUD.bit.GPIO38 = 0; //enable the internal pullup
GpioCtrlRegs.GPBMUX1.bit.GPIO38 = 0; //I/O
GpioCtrlRegs.GPBDIR.bit.GPIO38 = 1; //output
EDIS;
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; //Congigure the GPIO1 pin as EPWM1B
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; //Congigure the GPIO0 pin AS EPWM1A
EDIS;
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
//InitPieVectTable();
EALLOW;
PieVectTable.EPWM1_INT = &EPwm1TimerIsr;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
EDIS;
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;      // Stop all the TB clocks
EDIS;

EALLOW;
EPwm1Regs.TBPRD = 600; //Period TBCLK counts;  SYSCLKOUT=60MHZ
EPwm1Regs.TBCTR = 0; //clear TB counter
EPwm1Regs.TBCTL.bit.CTRMODE = 2;  //UP-DOWM-COUNTE MODE
EPwm1Regs.TBCTL.bit.PHSEN = 0;   //phase loading disabled
EPwm1Regs.TBCTL.bit.PRDLD = 0;   //loaded from its shadow register
EPwm1Regs.TBCTL.bit.SYNCOSEL = 3;  //disable EPWMxSYNCO signal
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;  //TBCLK = SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = 0; //1
EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0;  //Shadow mode
EPwm1Regs.CMPCTL.bit.SHDWBMODE = 0;
EPwm1Regs.CMPCTL.bit.LOADAMODE = 0;  //load on CTR =ZERO
EPwm1Regs.CMPCTL.bit.LOADBMODE = 0;
EPwm1Regs.AQCTLA.bit.CAU = 2;  //force EPWMxA output high
EPwm1Regs.AQCTLA.bit.CAD = 1;  //force EPWMxA output low
EPwm1Regs.AQCTLB.bit.CBU = 1;  //force EPWMxB output low
EPwm1Regs.AQCTLB.bit.CBD = 2;  //force EPWMxB output high
EPwm1Regs.ETPS.bit.INTPRD = 1;  //generate an interrupt on the first event INTCNT =01(first event)
EPwm1Regs.CMPA.half.CMPA = Duty;
EPwm1Regs.CMPB = Duty;
EPwm1Regs.ETCLR.bit.INT = 1; //clear EPWM1_INT flag
EPwm1Regs.ETSEL.bit.INTSEL = 1; //Enable event time-base counter equal to zero
EPwm1Regs.ETSEL.bit.INTEN = 1;  //Enable EPWM1_INT generation
EDIS;
IER |= M_INT3;
EALLOW;
PieCtrlRegs.PIEIER3.bit.INTx1 = 1;
EDIS;
EINT;
ERTM;
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;  //Start all the timers synced
EDIS;
for(;;)
{
  DELAY_US(10);
  //EPwm1Regs.ETFRC.bit.INT = 1;//can genarate a interrupt
}
}

相关帖子

沙发
wangch_sh| | 2014-11-28 16:34 | 只看该作者
protesu都可以仿真28027了?不错
不过那玩意不靠谱。

使用特权

评论回复
板凳
zhangmangui| | 2014-11-28 21:51 | 只看该作者
看来我错了   有人问   我说不能用proteus

使用特权

评论回复
地板
JKM99|  楼主 | 2014-11-29 00:07 | 只看该作者
wangch_sh 发表于 2014-11-28 16:34
protesu都可以仿真28027了?不错
不过那玩意不靠谱。

我也怀疑它了...所以打算做一个实物调试

使用特权

评论回复
5
JKM99|  楼主 | 2014-11-29 00:09 | 只看该作者
zhangmangui 发表于 2014-11-28 21:51
看来我错了   有人问   我说不能用proteus

7.10版本前面版本没有TMS320F2802x

使用特权

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

本版积分规则

4

主题

31

帖子

0

粉丝