TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F28035: F28035ADC采样问题

Part Number:TMS320F28035Other Parts Discussed in Thread:C2000WARE, CONTROLSUITE

新手一枚,想请大神看一下我的adc采样配置有没有问题。代码已上传:

#include "DSP28x_Project.h"// Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
__interrupt void adc_isr(void);
void Adc_Config(void);


// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Voltage1[10];
Uint16 Voltage2[10];
Uint16 Voltage3[10];
Uint16 Voltage4[10];


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 interruptsDINT;

// 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 registerPieVectTable.ADCINT1 = &adc_isr;EDIS;// This is needed to disable write to EALLOW protected registers

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2803x_InitPeripherals.c
// InitPeripherals(); // Not required for this exampleInitAdc();  // For this example, init the ADC

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

// Enable ADCINT1 in PIEPieCtrlRegs.PIEIER1.bit.INTx1 = 1;// Enable INT 1.1 in the PIEIER |= M_INT1;// Enable CPU Interrupt 1EINT;// Enable Global interrupt INTMERTM;// Enable Global realtime interrupt DBGMLoopCount = 0;ConversionCount = 0;

// Configure ADC
// Note: Channel ADCINA4  will be double sampled to workaround the ADC 1st sample issue for rev0 silicon errataEALLOW;AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;//ADCINT1 trips after AdcResults latchAdcRegs.INTSEL1N2.bit.INT1E= 1;//Enabled ADCINT1AdcRegs.INTSEL1N2.bit.INT1CONT  = 0;//Disable ADCINT1 Continuous modeAdcRegs.INTSEL1N2.bit.INT1SEL= 2;//setup EOC2 to trigger ADCINT1 to fireAdcRegs.ADCSOC0CTL.bit.CHSEL= 1;//set SOC0 channel select to ADCINA1(dummy sample for rev0 errata workaround)AdcRegs.ADCSOC1CTL.bit.CHSEL= 1;//set SOC1 channel select to ADCINA1AdcRegs.ADCSOC2CTL.bit.CHSEL= 2;//set SOC2 channel select to ADCINA2AdcRegs.ADCSOC3CTL.bit.CHSEL= 4;//set SOC3 channel select to ADCINA4AdcRegs.ADCSOC4CTL.bit.CHSEL= 6;//set SOC4 channel select to ADCINA6AdcRegs.ADCSOC0CTL.bit.TRIGSEL  = 9;//set SOC0 start trigger on EPwm3A, due to round-robin SOC0 converts first then SOC1, then SOC2AdcRegs.ADCSOC1CTL.bit.TRIGSEL  = 9;//set SOC1 start trigger on EPwm3A, due to round-robin SOC0 converts first then SOC1, then SOC2AdcRegs.ADCSOC2CTL.bit.TRIGSEL  = 9;//set SOC2 start trigger on EPwm3A, due to round-robin SOC0 converts first then SOC1, then SOC2AdcRegs.ADCSOC3CTL.bit.TRIGSEL  = 9;//set SOC1 start trigger on EPwm3A, due to round-robin SOC0 converts first then SOC1, then SOC2AdcRegs.ADCSOC4CTL.bit.TRIGSEL  = 9;//set SOC2 start trigger on EPwm3A, due to round-robin SOC0 converts first then SOC1, then SOC2AdcRegs.ADCSOC0CTL.bit.ACQPS= 9;//set SOC0 S/H Window to 7 ADC Clock Cycles, (9 ACQPS plus 1)AdcRegs.ADCSOC1CTL.bit.ACQPS= 9;//set SOC1 S/H Window to 7 ADC Clock Cycles, (9 ACQPS plus 1)AdcRegs.ADCSOC2CTL.bit.ACQPS= 9;//set SOC2 S/H Window to 7 ADC Clock Cycles, (9 ACQPS plus 1)AdcRegs.ADCSOC3CTL.bit.ACQPS= 9;//set SOC1 S/H Window to 7 ADC Clock Cycles, (9 ACQPS plus 1)AdcRegs.ADCSOC4CTL.bit.ACQPS= 9;//set SOC2 S/H Window to 7 ADC Clock Cycles, (9 ACQPS plus 1)EDIS;

// Assumes EPwm3 clock is already enabled in InitSysCtrl();EPwm3Regs.ETSEL.bit.SOCAEN= 1;// Enable SOC on A groupEPwm3Regs.ETSEL.bit.SOCASEL  = 4;// Select SOC from from CPMA on upcountEPwm3Regs.ETPS.bit.SOCAPRD= 1;// Generate pulse on 1st eventEPwm3Regs.CMPA.half.CMPA= 0x0080;// Set compare A valueEPwm3Regs.TBPRD= 0xFFFF;// Set period for EPwm3EPwm3Regs.TBCTL.bit.CTRMODE  = 0;// count up and start

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

}

__interrupt void  adc_isr(void)
{Voltage1[ConversionCount] = AdcResult.ADCRESULT1; //discard ADCRESULT0 as part of the workaround to the 1st sample errata for rev0Voltage2[ConversionCount] = AdcResult.ADCRESULT2;Voltage3[ConversionCount] = AdcResult.ADCRESULT3;Voltage4[ConversionCount] = AdcResult.ADCRESULT4;// If 20 conversions have been logged, start overif(ConversionCount == 9){ConversionCount = 0;}else ConversionCount++;AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;//Clear ADCINT1 flag reinitialize for next SOCPieCtrlRegs.PIEACK.all = PIEACK_GROUP1;// Acknowledge interrupt to PIEreturn;
}

其中关于adc的设置有疑问的点在于:

Voltage1[ConversionCount] = AdcResult.ADCRESULT1; 
Voltage2[ConversionCount] = AdcResult.ADCRESULT2;
Voltage3[ConversionCount] = AdcResult.ADCRESULT3;
Voltage4[ConversionCount] = AdcResult.ADCRESULT4;
这几行代码里的ADCRESULT1至ADCRESULT4的数字1至4是怎么来的。
//***************************************************************************************************

下面附上程序刷进F28035后,调试时voltage1至voltag4的采样截图和Expressions截图:

voltage1:

voltage2:

voltage3:

voltage4:

Expressions:

问题是:

1.我的adc配置是否有问题。

2.为什么voltage1和voltage2的数值分别在25和17上下浮动,而voltage3和voltage4的数值分别在1255和1830上下浮动。

3.为什么每组adc采样的voltage数值浮动范围都不一样,到底voltage的数值应该是多少。

chenzheng:

程序是官方例程改的,只是我模仿voltage1和voltage2的配置加了voltage3和voltage4。另外还想问一下触发源的选择,代码是:

AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 9;  AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 9;  AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 9; AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 9;  AdcRegs.ADCSOC4CTL.bit.TRIGSEL = 9;

9是代表epwm3,是所有的soc都可以集中到epwm3的trigger上吗,还是说epwm3的trigger接收数量是有一个上限的呢,求解答,谢谢。

,

Ben Qin:

你好,我查看下相关资料,稍后回复您。

,

chenzheng:

好嘟,拴Q

,

Ben Qin:

chenzheng said:这几行代码里的ADCRESULT1至ADCRESULT4的数字1至4是怎么来的

参照下图:

chenzheng said:程序是官方例程改的,只是我模仿voltage1和voltage2的配置加了voltage3和voltage4

使用的哪个例程以及改动的位置具体是哪里?

,

Ben Qin:

建议参考下user guide ADC相关章节,你的大部分疑问可以在其中找到答案。

,

chenzheng:

使用的例程叫Example_2803xAdcSoc。改动的地方就是模仿voltage1和voltage2的配置加了voltage3和voltage4,具体来说就是:

Uint16 Voltage3[10];Uint16 Voltage4[10];

AdcRegs.ADCSOC3CTL.bit.CHSEL = 4; //set SOC3 channel select to ADCINA4 AdcRegs.ADCSOC4CTL.bit.CHSEL = 6; //set SOC4 channel select to ADCINA6

AdcRegs.ADCSOC3CTL.bit.TRIGSEL = 9; AdcRegs.ADCSOC4CTL.bit.TRIGSEL = 9;

AdcRegs.ADCSOC3CTL.bit.ACQPS = 9;  AdcRegs.ADCSOC4CTL.bit.ACQPS = 9;

Voltage3[ConversionCount] = AdcResult.ADCRESULT3; Voltage4[ConversionCount] = AdcResult.ADCRESULT4;

就这几行,别的没有了。

,

chenzheng:

我就想知道调试的时候为什么voltage1和voltage2的数值分别在25和17上下浮动,而voltage3和voltage4的数值分别在1255和1830上下浮动。

还有就是为什么每组adc采样的voltage数值浮动范围都不一样,到底voltage的数值应该是多少。

,

Ben Qin:

你输入的是怎样的波形?

,

chenzheng:

是在开发板上调试的,引脚没有输入,只有单片机供电,应该是直流3.3v

,

Ben Qin:

也就是说你的输入引脚是悬空的。当引脚悬空时,ADC采集到的电压时未知随机的。

请将输入引脚接地或者给其一个输入波形。

,

chenzheng:

好的,我试试,后面会给你反馈,谢谢

,

Ben Qin:

好的

,

chenzheng:

你好我试了一下,发现voltage2的值基本准确,voltage3和voltage5的值跟真实电压值差很多。

真实电压值调大,voltage3和voltage5会变大;真实电压值调小,voltage3和voltage5也会变小,但是数值上差很多。

这是为啥,我感觉我的配置没问题呀,麻烦您看一下,谢谢。

,

Ben Qin:

你是如何进行接线的?你使用的是自制板还是官方板?

,

chenzheng:

接线和PCB板子都是硬件工程师自己设计生产的,您觉得是硬件的问题吗,我的代码配置有没有问题呢,如果代码没问题的话我去跟硬件工程师沟通

,

Ben Qin:

建议您先检查一下输入IO口以及对应的输出IO口是否正确,都正确的话那么可能是硬件上的问题。

建议先使用未修改的官方例程测试一下(有TI官方板更好),一般情况下例程是不会出错的。

,

DSP入门学习:

我遇到了和您一样的问题,请问您解决了吗?另外您的例程Example_2803xAdcSoc是在哪里找到的?如果您方便的话可以加我个微信:ZGNOONE

,

chenzheng:

device_support/f2803x/v126/DSP2803x_examples_ccsv4/adc_soc,按照这个路径就能找到soc的官方例程,这个文件夹有很多官方例程,都可以学习看看,我也是这样过来的

,

Ben Qin:

您可以在C2000ware中找到:

C:\ti\c2000\C2000Ware_5_00_00_00\device_support\f2803x\examples\c28\adc_soc

chenzheng said:device_support/f2803x/v126/DSP2803x_examples_ccsv4/adc_soc,按照这个路径就能找到soc的官方例程,

这个是在controlsuite中的路径。

赞(0)
未经允许不得转载:TI中文支持网 » TMS320F28035: F28035ADC采样问题
分享到: 更多 (0)

© 2024 TI中文支持网   网站地图 鲁ICP备2022002796号-1