您好,F280XILEG_VDC.C中有几处不明白的,望您解答!下面是TI例程:
void F280X_ileg2_dcbus_drv_init(ILEG2DCBUSMEAS *p)
{
DELAY_US(ADC_usDELAY);
AdcRegs.ADCTRL1.all = ADC_RESET_FLAG; // Reset the ADC Module
asm(" NOP ");
asm(" NOP ");
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3; // Power up bandgap/reference circuitry
DELAY_US(ADC_usDELAY); // Delay before powering up rest of ADC
AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // Power up rest of ADC
DELAY_US(ADC_usDELAY);
AdcRegs.ADCTRL3.bit.ADCCLKPS = 16; // Set up ADCTRL3 register
AdcRegs.ADCTRL1.all = ADCTRL1_INIT_STATE; // Set up ADCTRL1 register
AdcRegs.ADCTRL2.all = ADCTRL2_INIT_STATE; // Set up ADCTRL2 register
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 2; // Specify three conversions
AdcRegs.ADCCHSELSEQ1.all = p->ChSelect; // Configure channel selection
AdcRegs.ADCREFSEL.all = 39; // Set up the ADC reference select register
AdcRegs.ADCOFFTRIM.all = 65534; // Set up the ADC offset trim register
// Set up Event Trigger with CNT_zero enable for Time-base of EPWM1
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOCA
EPwm1Regs.ETSEL.bit.SOCASEL = 1; // Enable CNT_zero event for SOCA
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate SOCA on the 1st event
EPwm1Regs.ETCLR.bit.SOCA = 1; // Clear SOCA flag
}
void F280X_ileg2_dcbus_drv_read(ILEG2DCBUSMEAS *p)
{
int16 DatQ15;
int32 Tmp;
// Wait until ADC conversion is completed
while (AdcRegs.ADCST.bit.SEQ1_BSY == 1)
{};
DatQ15 = AdcRegs.ADCRESULT0^0x8000; // Convert raw result to Q15 (bipolar signal)
Tmp = (int32)p->ImeasAGain*(int32)DatQ15; // Tmp = gain*dat => Q28 = Q13*Q15
p->ImeasA = (int16)(Tmp>>13); // Convert Q28 to Q15
p->ImeasA += p->ImeasAOffset; // Add offset
p->ImeasA *= -1; // Positive direction, current flows to motor
DatQ15 = AdcRegs.ADCRESULT1^0x8000; // Convert raw result to Q15 (bipolar signal)
Tmp = (int32)p->ImeasBGain*(int32)DatQ15; // Tmp = gain*dat => Q28 = Q13*Q15
p->ImeasB = (int16)(Tmp>>13); // Convert Q28 to Q15
p->ImeasB += p->ImeasBOffset; // Add offset
p->ImeasB *= -1; // Positive direction, current flows to motor
DatQ15 = (AdcRegs.ADCRESULT2>>1)&0x7FFF; // Convert raw result to Q15 (unipolar signal)
Tmp = (int32)p->VdcMeasGain*(int32)DatQ15; // Tmp = gain*dat => Q28 = Q13*Q15
if (Tmp > 0x0FFFFFFF) // Limit Tmp to 1.0 in Q28
Tmp = 0x0FFFFFFF;
p->VdcMeas = (int16)(Tmp>>13); // Convert Q28 to Q15
p->VdcMeas += p->VdcMeasOffset; // Add offset
p->ImeasC = -(p->ImeasA + p->ImeasB); // Compute phase-c current
AdcRegs.ADCTRL2.all |= 0x4040; // Reset the sequence
}
我的问题如下:
1,寄存器:(1)AdcRegs.ADCTRL1.all = ADCTRL1_INIT_STATE; // Set up ADCTRL1 register
AdcRegs.ADCTRL2.all = ADCTRL2_INIT_STATE; // Set up ADCTRL2 register
请问这两个控制寄存器ADCTRL1_INIT_STATE,ADCTRL2_INIT_STATE,具体代表的怎样设置呢,没找到相关的说明。
(2)AdcRegs.ADCREFSEL.all = 39; // Set up the ADC reference select register
AdcRegs.ADCOFFTRIM.all = 65534; // Set up the ADC offset trim register
这两个ADC寄存器麻烦您解释下,设置的39和65534分别怎么样得来的呢?代表什么意思呢 ?谢谢,我看了下寄存器资料,但还是有疑问,谢谢!
2.,第二个read函数中ImeasBGain怎么样得到的?为什么设置成Q格式为Q13呢?
3, p->ImeasA *= -1; // Positive direction, current flows to motor这条指令的意思?
4,关于将ADC结果异或的,双极性电流与0x8000异或,单极性电压与0x7FFF异或,虽然!知道这样处理简单有效,呵呵,大概能懂意思,但还是希望您解释下,呵呵,再次感谢



