如题,我把ADC采样的A0~A7通道设置为EVA的周期下溢中断触发,中断周期20K;B0~A7通道设置为EVB的cap6捕获上升沿触发,中断周期10K; 电机控制所需的电流采样在A通道完成,想把计算角度的旋变采样电路放在B通道,现在的问题是,在程序初始化阶段,我想采样100次,先计算出每一个通道的初始偏置,然后再进行计算,可是发现现在只有A通道计算出的初始偏置是正确的,而B通道的偏置是不正确的。是因为我的设置有问题么?
如何才能在程序初始阶段,将两个触发源分别控制的SEQ1序列(A通道)和SEQ2序列(B通道)的初始偏置正确的读出来呢?求解答。
我的ADC采样部分设置如下:
void F2812_OCSMEAS_drv_init(OCSMEAS *p)
{
Uint32 u32i;
AdcRegs.ADCTRL1.all = ADC_RESET_FLAG; // Reset the ADC Module
asm(" NOP ");
asm(" NOP ");
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3; // ADC间隙和参考电路上电Power up bandgap/reference circuitry
for(u32i=0;u32i<0x80000;u32i++);
AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // ADC模拟电路加电Power up rest of ADC
AdcRegs.ADCTRL3.bit.ADCCLKPS = 2; // 时钟定标Set up ADCTRL3 register
for(u32i=0;u32i<0x80000;u32i++);
AdcRegs.ADCTRL1.all |= 0x0400; // 0x0400双序列、开始停止模式、Set up ADCTRL1 register //cascade mode
AdcRegs.ADCTRL3.bit.SMODE_SEL=0;//设置顺序采样模式
AdcRegs.ADCMAXCONV.bit.MAX_CONV1=7;//每个序列发生器最大采样通道数为8,总共可采样16通道
AdcRegs.ADCMAXCONV.bit.MAX_CONV2=7;//每个序列发生器最大采样通道数为8,总共可采样16通道
AdcRegs.ADCTRL2.all |= 0x0101; //允许EVA触发 SEQ1, EVB触发 SEQ2
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x01;//SIN Result0
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x00;//COS Result1
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x02;//ShuntA Result2 U相电流
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x03;//ShuntB Result3 V相电流//W相电流
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x04;//ShuntC Result4 母线电流
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x08;//AD TsPower Result5
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x09;//VBAT Result6 母线电压蓄电池
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x05;// AD ResolverA Result7
AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x06;//AD ResolverB Result8
AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x00;//COS
AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x01;//SIN
AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x02;//11
AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0x03;//12
AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0x03;//13
AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0x03;//14
AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0x03;//15
EvaRegs.GPTCONA.bit.T1TOADC = 1; //允许EVA定时器1下溢中断启动ADC
EvbRegs.CAPCONB.bit.CAP6TOADC=1;//cap6INT标志位置1时启动ADC
}
//===================================================================================
//ADC calculation
//===================================================================================
void F2812_OCSMEAS_drv_read(OCSMEAS * p)
{
int16 DatQ15;
Uint16 Dat1 ;
int32 Tmp;
int32 ImeasGain = _IQ10(1);//_IQ10(7.5)
int16 RevmeasGain = _IQ13(0.9999);//(修改成iq格式)
int32 VBATmeasGain=_IQ13(1);//0.002923
// Wait until ADC conversion is completed
while (AdcRegs.ADCST.bit.SEQ1_BSY == 1||AdcRegs.ADCST.bit.SEQ2_BSY == 1)
{};
if(p->Count < 100 )
{
p->Count++;
p->T1Offset =p->T1Offset + AdcRegs.ADCRESULT0 * 0.01;//计算主转矩传感器零点偏移量
p->T2Offset =p->T2Offset + AdcRegs.ADCRESULT1 * 0.01;//计算从转矩传感器零点偏移量
Dat1 = AdcRegs.ADCRESULT2;
p->IaOffset = p->IaOffset + 0.01 * Dat1;//上电后计算A电流采样电压零点值.
Dat1 = AdcRegs.ADCRESULT3;
p->IcOffset = p->IcOffset + 0.01 * Dat1;//上电后计算C电流采样电压零点值.
Dat1 = AdcRegs.ADCRESULT9;
p->SbOffset = p->SbOffset + 0.01 * Dat1;//sin信号采样电压零点值.
Dat1 = AdcRegs.ADCRESULT10;
p->SaOffset = p->SaOffset + 0.01 * Dat1;//cos信号采样电压零点值.
AdcRegs.ADCTRL2.all |= 0x4040; // Reset the sequence
}
if(p->Count == 100)
{
DatQ15 = p->IaOffset – 32768;//
p->intIaOffset = (int16)DatQ15*1;//
DatQ15 = p->IcOffset – 32768;
p->intIcOffset = (int16)DatQ15*1;//
p->T1Offset = p->T1Offset>>5;
p->T2Offset = p->T2Offset>>5;
DatQ15 = p->SaOffset – 32768;//
p->intSaOffset = (int16)DatQ15;// Q15
DatQ15 = p->SbOffset – 32768;//
p->intSbOffset = (int16)DatQ15;// Q15
p->Count++;
}
if(p->Count>100)
{
p->Count = 200;
p->Tmeas1 = (AdcRegs.ADCRESULT0>>5) – p->T1Offset;// – _IQ10(0.48);
p->Tmeas2 = (AdcRegs.ADCRESULT1>>5) – p->T2Offset;
p->Tmeas = p->Tmeas1 – p->Tmeas2;
DatQ15 = (Dat1-p->intIaOffset)^0x8000;// Convert raw result to Q15 (bipolar signal)
Tmp = (int32)ImeasGain* (int32)DatQ15; // Tmp = gain*dat => Q25 = Q10*Q15
DatQ15 = (int16)(Tmp>>15); // Convert Q25 to Q10
p->Ia = DatQ15;
if(p->Ia > _IQ10(7.5)) p->Ia = _IQ10(7.5);
if(p->Ia < _IQ10(-7.5)) p->Ia = _IQ10(-7.5);
DatQ15 = (Dat1-p->intIcOffset)^0x8000;// Convert raw result to Q15 (bipolar signal)
Tmp = (int32)ImeasGain* (int32)DatQ15; // Tmp = gain*dat => Q25 = Q10*Q15
DatQ15 = (int16)(Tmp>>15); // Convert Q25 to Q10
p->Ib = DatQ15;
DatQ15 = (AdcRegs.ADCRESULT6>>1)&0x7FFF; // Convert raw result to Q15 (unipolar signal)
Tmp = (int32)DatQ15* (int32)VBATmeasGain; //Tmp = gain*dat => Q28 = Q13*Q15
if (Tmp > 0x0FFFFFFF) // Limit Tmp to 1.0 in Q28
Tmp = 0x0FFFFFFF;
p->Vbat = (int16)(Tmp>>13); // Convert Q28 to Q15
DatQ15 = (AdcRegs.ADCRESULT9-p->intSbOffset)^0x8000;// Convert raw result to Q15 (bipolar signal)
Tmp = (int32)RevmeasGain* (int32)DatQ15; // Tmp = gain*dat => Q28 = Q13*Q15
p->SINBMeas = (int16)(Tmp>>13); // Convert Q28 to Q15
DatQ15 = (AdcRegs.ADCRESULT10-p->intSaOffset)^0x8000;// Convert raw result to Q15 (bipolar signal)
Tmp = (int32)RevmeasGain* (int32)DatQ15; // Tmp = gain*dat => Q28 = Q13*Q15
p->SINAMeas = (int16)(Tmp>>13); // Convert Q28 to Q15
AdcRegs.ADCTRL2.all |= 0x4040; // Reset the sequence
}
}
mangui zhang:
ADC的A、B通道在并行模式下是否能解决你的问题?