28035的例程解析--adc_temp_sensor

hlx3012   2012-3-30 11:42 楼主

void main()
{

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2803x_SysCtrl.c file.
   InitSysCtrl();


// Step 2. Initialize GPIO:
// This example function is found in the DSP2803x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   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 DSP2803x_PieCtrl.c file.
   InitPieCtrl();

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

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2803x_DefaultIsr.c.
// This function is found in DSP2803x_PieVect.c.
   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.ADCINT1 = &adc_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize the ADC:
// This function is found in DSP2803x_Adc.c
   InitAdc();  // For this example, init the ADC

// Step 5. Configure ADC to sample the temperature sensor on ADCIN5:
// The output of Piccolo temperature sensor can be internally connected to the ADC through ADCINA5
// via the TEMPCONV bit in the ADCCTL1 register. When this bit is set, any voltage applied to the external
// ADCIN5 pin is ignored.
 EALLOW;
 AdcRegs.ADCCTL1.bit.TEMPCONV  = 1; //Connect internal temp sensor to channel ADCINA5.
 EDIS;

// Step 6. Continue configuring ADC to sample the temperature sensor on ADCIN5:
// Since the temperature sensor is connected to ADCIN5, configure the ADC to sample channel ADCIN5
// as well as the ADC SOC trigger and ADCINTs preferred. This example uses EPWM1A to trigger the ADC
// to start a conversion and trips ADCINT1 at the end of the conversion.
 EALLOW;
 AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch
 //ADCCTL1:ADC控制寄存器1
//(15)RESET:写1复位ADC模块
//(14)ADCENABLE:ADC模块允许(写0禁止但不断电ADC,写1允许ADC转换)
//(13)ADCBSY:为1说明ADC忙
//(12~8)ADCBSYCHN:用来确定ADC当前正在转换的通道
//(7)ADCPWDN:为0时ADC时钟除bandgap&referencce全部断电
//(6)ADCBGPWD:为0:bandgap断电
//(5)ADCREFPWD,为0:Reference buffers断电
//(3)ADCREFSEL:内外部参考选择,为0为内部参考
//(2)INTPULSEPOS:中断何时产生(为0 :ADC开始转换时产生,为1:ADC转换完之前1个时钟周期产生)
//(1)VREFLOCONV:为1内部VREFLO连接到ADCINB5
//(0)TEMPCONV:为1内部温度传感器接到ADCINA5
 AdcRegs.INTSEL1N2.bit.INT1E     = 1; //Enabled ADCINT1
 AdcRegs.INTSEL1N2.bit.INT1CONT  = 0; //Disable ADCINT1 Continuous mode
 AdcRegs.INTSEL1N2.bit.INT1SEL = 0; //setup EOC0 to trigger ADCINT1 to fire
 //INTSELxNy:ADC中断来源选择寄存器
//(14)INTyCONT:中断脉冲产生设置(为0:除非ADCINTy flag清零ADCINTy产生中断;为1:只要有EOC信号就中断)
//(13)INTyE:INTy中断允许(为1允许)
//(12~8)INTySEL:ADCINTy的EOC信号来源
//(6)INTxCONT:中断脉冲产生设置(为0:除非ADCINTx flag清零ADCINTx产生中断;为1:只要有EOC信号就中断)
//(5)INTxE:INTx中断允许(为1允许)
//(4~0)INTxSEL:ADCINTx的EOC信号来源
 AdcRegs.ADCSOC0CTL.bit.CHSEL  = 5; //set SOC0 channel select to ADCINA5 (which is internally connected to the temperature sensor)
 AdcRegs.ADCSOC0CTL.bit.TRIGSEL  = 5; //set SOC0 start trigger on EPWM1A
 AdcRegs.ADCSOC0CTL.bit.ACQPS  = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
 //ADCSOCxCTL:ADCSOC0 - SOC15控制寄存器
//(15~11)TRIGSEL:SOC产生来源(软件,CPUtimer中断,PWM,XINT)
//(9~6)CHSEL:当SOCx产生的时候ADC转换通道选择(SIMULENx=0时单通道选择,SIMULENx = 1时,两对通道选择)
//(5~0)ACQPS:SOCx的采样保持窗口大小。(06h Sample window is 7 cycles long (6 + 1 clock cycles).)

 EDIS;


// Step 7. User specific code, enable interrupts:

// Enable ADCINT1 in PIE
   PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE
   IER |= M_INT1;       // Enable CPU Interrupt 1
   EINT;                // Enable Global interrupt INTM
   ERTM;                // Enable Global realtime interrupt DBGM

   LoopCount = 0;
   ConversionCount = 0;


// Assumes ePWM1 clock is already enabled in InitSysCtrl();
   EPwm1Regs.ETSEL.bit.SOCAEN = 1;  // Enable SOC on A group
   EPwm1Regs.ETSEL.bit.SOCASEL = 4;  // Select SOC from from CPMA on upcount
   //ETSEL:事件触发选择寄存器
//(15)SOCBEN:SOCB允许(为1:允许ADC在SOC脉冲来临时转换)
//(14~12)SOCBSEL:EPWMxSOCB来源选择(DCBEVT1,TBCTR = 0x0000,TBCTR = TBPRD,equal to CMPA,equal to CMPB)
//(11)SOCAEN:SOCA允许(为1:允许ADC在SOC脉冲来临时转换)
//(10-8)SOCASEL:EPWMxSOCA来源选择(DCBEVT1,TBCTR = 0x0000,TBCTR = TBPRD,equal to CMPA,equal to CMPB)
//(3)INTEN:EPWMx_INT中断产生允许(为1:允许)
//(2~0)INTSEL:EPWMx_INT中断来源选择(TBCTR = 0x0000,TBCTR = TBPRD,equal to CMPA,equal to CMPB)
   EPwm1Regs.ETPS.bit.SOCAPRD  = 1;  // Generate pulse on 1st event
   //ETPS:时间产生预分频寄存器
//(15~14)SOCBCNT:计数有多少次SOCB事件(一到3次)
//(13~12)SOCBPRD:设定多少次SOCB事件产生一个SOCB的脉冲
//(11~10)SOCACNT:计数有多少次SOCA事件(一到3次)
//(9~8)SOCAPRD:设定多少次SOCA事件产生一个SOCB的脉冲
//(3~2)INTCNT:计数有多少次EPWMx_INT中断事件(一到3次)
//(1~0)INTPRD:设定多少次EPWMx_INT事件产生中断
   EPwm1Regs.CMPA.half.CMPA  = 0x0080; // Set compare A value
   EPwm1Regs.TBPRD     = 0xFFFF; // Set period for ePWM1
   EPwm1Regs.TBCTL.bit.CTRMODE  = 0;  // count up and start
   //TBCTL:时间基准控制寄存器
//(15~14)FREE, SOFT:00仿真时立即停止,01完成当前周期时停止,10Free Run
//(13)PHSDIR:方向选址寄存器(为1,同步后上升计数,为0,同步后下降计数)
//(12~10)CLKDIV:分频寄存器TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)(000 /1,001 /2,010 /4,011 /8,100 /16,101 /32,110 /64,111 /128)
//(9~7)HSPCLKDIV:分频寄存器TBCLK = SYSCLKOUT / (HSPCLKDIV × CLKDIV)(000 /1,001 /2,010 /4,011 /8,100 /16,101 /32,110 /64,111 /128)
//(6)SWFSYNC:软件写1同步(写一同步,仅在SYNCOSEL = 00时有效)
//(5~4)SYNCOSEL:同步输出信号产生来源(00 EPWMxSYNC,01 CTR = zero,10 CTR = CMPB ,11 Disable EPWMxSYNCO signal)
//(3)PRDLD:周期寄存器何时从shadow读取(为0:TBCTR=0时,为1:不使用shadow即立即读取)
//(2)PHSEN:是否允许同步时TBCTR=TBPHS(0不允许,1允许)
//(1~0)CTRMODE:计数方向(00上升,01下降,10上升下降,11冻结)

// Wait for ADC interrupt
   for(;;)
   {
      LoopCount++;
   }

}


interrupt void  adc_isr(void)
{

  TempSensorVoltage[ConversionCount] = AdcResult.ADCRESULT0;

  // If 20 conversions have been logged, start over
  if(ConversionCount == 9)
  {
     ConversionCount = 0;
  }
  else ConversionCount++;

  AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;  //Clear ADCINT1 flag reinitialize for next SOC
  PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;   // Acknowledge interrupt to PIE

  return;
}


 

回复评论 (2)

我建议阿胶啊,把它的英文去掉,TI没有注释到的再加一些注释,这样是不是会更好一些呢?

我刚开始时,什么SOCA、A的,什么触发的,他的灵活性倒是增加了好多麻烦,现在算是理清了它们的关系。

我建议啊,你把它们关系及设置要点总结一下,肯定是最好的经验。
点赞  2012-4-1 15:55
请问为什么要同时时能cpu中断1与ADC INT1.1中断?两者有什么关系?
本人刚开始学28035,希望楼主帮忙解答一下
点赞  2012-8-10 16:53
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复