This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具与软件:
您好!
我正在尝试使用28379D 控制卡读取 ADC 值。 输入电流通过传感器传输到 ADC 引脚、并且我已将代码配置为相应地读取值。
在调试窗口中、 ADCBRESULT5 和 ADCBRESULT4 固定在大约15xx (未施加电流时)。 但是、有时会计算出的值 ADCBRESULT5 - ADCBRESULT4 尖峰达到65000、从而导致依赖于电流测量的控制器不稳定。
随附的屏幕截图是在控制器关闭时从调试窗口中获取的。 该屏幕截图所示 ADCRESULT5 、 ADCRESULT4 和两个值之间的差异。
下面是 ADC 设置。
我正在使用中 ADCA1至 ADCA5 和 ADCB1至 ADCB5 、当前问题发生在上 ADCB5 和 ADCB4 .
void setupADCSOC(void) { EALLOW; //ADCA AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; // SOC0(=ADCA0) AdcaRegs.ADCSOC0CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; // SOC1(=ADCA1) AdcaRegs.ADCSOC1CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 // AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; // SOC2(=ADCA2) AdcaRegs.ADCSOC2CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC2CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC3CTL.bit.CHSEL = 3; // SOC3(=ADCA3) AdcaRegs.ADCSOC3CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC3CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC4CTL.bit.CHSEL = 4; // SOC4(=ADCA4) AdcaRegs.ADCSOC4CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC4CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC5CTL.bit.CHSEL = 5; // SOC5(=ADCA5) AdcaRegs.ADCSOC5CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC5CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 5; // End of SOC5 will set INT1 flag AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared //ADCB AdcbRegs.ADCSOC0CTL.bit.CHSEL = 0; // SOC0(=ADCB0) AdcbRegs.ADCSOC0CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC0CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC1CTL.bit.CHSEL = 1; // SOC1(=ADCB1) AdcbRegs.ADCSOC1CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC1CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC2CTL.bit.CHSEL = 2; // SOC2(=ADCB2) AdcbRegs.ADCSOC2CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC2CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC3CTL.bit.CHSEL = 3; // SOC3(=ADCB3) AdcbRegs.ADCSOC3CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC3CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC4CTL.bit.CHSEL = 4; // SOC4(=ADCB4) AdcbRegs.ADCSOC4CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC4CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC5CTL.bit.CHSEL = 5; // SOC5(=ADCB5) AdcbRegs.ADCSOC5CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC5CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 //AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // End of SOC5 will set INT1 flag // AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag //AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared EDIS; }
伊恩津、
要解决该问题、我需要完整的代码。 您是否向 ADC 引脚施加直流电压以进行测试和验证? 您如何为主控件中的 ADC 设置 SoC?
我建议使用 SysConfig 工具自动生成所需的图形初始化。 稍后您可以直接将其复制到您的代码中。
此致!
Masoud。
void setupADC(void) { //single ended AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); AdcSetMode(ADC_ADCB, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE); EALLOW; //ADCA AdcaRegs.ADCCTL2.bit.PRESCALE = 1; AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; //EOC --> 인터럽트 신호 발생 AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; //ADC모듈 활성화 //ADCB AdcbRegs.ADCCTL2.bit.PRESCALE = 1; AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1; //EOC --> 인터럽트 신호 발생 AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; //ADC모듈 활성화 EDIS; DELAY_US(1000); } void setupADCSOC(void) { EALLOW; //ADCA AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0; // SOC0(=ADCA0) AdcaRegs.ADCSOC0CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC1CTL.bit.CHSEL = 1; // SOC1(=ADCA1) AdcaRegs.ADCSOC1CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 // AdcaRegs.ADCSOC2CTL.bit.CHSEL = 2; // SOC2(=ADCA2) AdcaRegs.ADCSOC2CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC2CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC3CTL.bit.CHSEL = 3; // SOC3(=ADCA3) AdcaRegs.ADCSOC3CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC3CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC4CTL.bit.CHSEL = 4; // SOC4(=ADCA4) AdcaRegs.ADCSOC4CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC4CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCSOC5CTL.bit.CHSEL = 5; // SOC5(=ADCA5) AdcaRegs.ADCSOC5CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcaRegs.ADCSOC5CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 5; // End of SOC5 will set INT1 flag AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared //ADCB AdcbRegs.ADCSOC0CTL.bit.CHSEL = 0; // SOC0(=ADCB0) AdcbRegs.ADCSOC0CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC0CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC1CTL.bit.CHSEL = 1; // SOC1(=ADCB1) AdcbRegs.ADCSOC1CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC1CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC2CTL.bit.CHSEL = 2; // SOC2(=ADCB2) AdcbRegs.ADCSOC2CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC2CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC3CTL.bit.CHSEL = 3; // SOC3(=ADCB3) AdcbRegs.ADCSOC3CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC3CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC4CTL.bit.CHSEL = 4; // SOC4(=ADCB4) AdcbRegs.ADCSOC4CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC4CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 AdcbRegs.ADCSOC5CTL.bit.CHSEL = 5; // SOC5(=ADCB5) AdcbRegs.ADCSOC5CTL.bit.ACQPS = 9; // Sample window is 10 SYSCLK cycles AdcbRegs.ADCSOC5CTL.bit.TRIGSEL = 1; // Trigger on CPUTIMER0 //AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // End of SOC5 will set INT1 flag // AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag //AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared EDIS; }
在操作转换器时观察 ADC 值时、读数会波动、如上图所示。