现在介绍CC3200的ADC功能,CC3200的ADC有8个通道,四个用于外部输入,4个用于内部,单次采样时间是16us,可以设置成8个通道的轮流采样,8个通道轮流采样花费的总时间16us,模拟输入的管脚是固定的,支持DMA和FIFO,目前我只了解FIFO,列出几张图
ADC总框架图:只有一个adc转化器:
采样过程:可以看出每个通道花2us,8个通道花16us.
通道介绍:
看一下pin58的配置寄存器:
注意:当PIN58作为模拟量输入口时,最大能承受电压的1.8V,一般最好不要超过1.467V。作为数字量IO口时,最大可承受电压为3.6V。
介绍一下CC3200的ADC比较特别的地方,第一:有FIFO,第二:有计数器(记录的应该是采样的时间)。
在datasheet有以下内容:
按照上面的来我们就能完成简单的采样。
参考电压:
在http://processors.wiki.ti.com/index.php/CC32xx_ADC_Appnote中有
The reference voltage however is specified as 1.4V in the example SDK. It has to be corrected to 1.467V. The corrected lines are given below。
File path : \\CC3200SDK_1.1.0\cc3200-sdk\example\adc
File : main.c
Lines 286 to 293 are modified as below
while(uiIndex < NO_OF_SAMPLES)
{
UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.467)/4096);
uiIndex++;
}
//UART_PRINT("\n\rVoltage is %f\n\r",((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.467/4096);
参考电压是1.467V。
程序:
if(!ReadFromUser(&uiAdcInputPin))
{
UART_PRINT("\n\rInvalid Input. Please try again. \n\r");
continue;
}
#ifdef CC3200_ES_1_2_1
//
// Enable ADC clocks.###IMPORTANT###Need to be removed for PG 1.32
//
HWREG(GPRCM_BASE + GPRCM_O_ADC_CLK_CONFIG) = 0x00000043;
HWREG(ADC_BASE + ADC_O_ADC_CTRL) = 0x00000004;
HWREG(ADC_BASE + ADC_O_ADC_SPARE0) = 0x00000100;
HWREG(ADC_BASE + ADC_O_ADC_SPARE1) = 0x0355AA00;
#endif
//
// Pinmux for the selected ADC input pin
//
MAP_PinTypeADC(uiAdcInputPin,PIN_MODE_255);
//
// Convert pin number to channel number
//
switch(uiAdcInputPin)
{
case PIN_58:
uiChannel = ADC_CH_1;
break;
case PIN_59:
uiChannel = ADC_CH_2;
break;
case PIN_60:
uiChannel = ADC_CH_3;
break;
default:
break;
}
//
// Configure ADC timer which is used to timestamp the ADC data samples
//
MAP_ADCTimerConfig(ADC_BASE,2^17);
//
// Enable ADC timer which is used to timestamp the ADC data samples
//
MAP_ADCTimerEnable(ADC_BASE);
//
// Enable ADC module
//
MAP_ADCEnable(ADC_BASE);
//
// Enable ADC channel
//
MAP_ADCChannelEnable(ADC_BASE, uiChannel);
while(uiIndex < NO_OF_SAMPLES + 4)
{
if(MAP_ADCFIFOLvlGet(ADC_BASE, uiChannel))
{
ulSample = MAP_ADCFIFORead(ADC_BASE, uiChannel);
pulAdcSamples[uiIndex++] = ulSample;
}
}
MAP_ADCChannelDisable(ADC_BASE, uiChannel);
uiIndex = 0;
//UART_PRINT("\n\rTotal no of 32 bit ADC data printed :4096 \n\r");
//UART_PRINT("\n\rADC data format:\n\r");
//UART_PRINT("\n\rbits[13:2] : ADC sample\n\r");
//UART_PRINT("\n\rbits[31:14]: Time stamp of ADC sample \n\r");
//
// Print out ADC samples
//
while(uiIndex < NO_OF_SAMPLES)
{
// UART_PRINT("\n\rVoltage is %f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*1.467)/4096);
UART_PRINT("\n\r%f\n\r",(((float)((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))*20000/(4096-((pulAdcSamples[4+uiIndex] >> 2 ) & 0x0FFF))));
uiIndex++;
}
//UART_PRINT("\n\rVoltage is %f\n\r",((pulAdcSamples[4] >> 2 ) & 0x0FFF)*1.4/4096);
// UART_PRINT("\n\r");
}
}
拿通道59,使用ADCFIFO一次采样的几组数据:
标准值 |
48.490K |
48.49K |
27.65K |
16.32K |
9.95K |
5K |
6.24K |
4.02K |
采样值 |
49130.8 |
49072.51 |
27766.76 |
16360.41 |
9996.338 |
5021.38 |
6264.829 |
4058.737 |
采样值 |
49130.8 |
48956.23 |
27766.76 |
16344.28 |
10018.32 |
5036.675 |
6256.41 |
4037.559 |
采样值 |
48956.23 |
49130.8 |
27711.13 |
16360.41 |
10007.33 |
5036.675 |
6256.41 |
4051.674 |
采样值 |
49014.32 |
48840.34 |
27711.13 |
16376.55 |
10007.33 |
5029.025 |
6273.252 |
4072.877 |
采样值 |
48956.23 |
48898.23 |
27738.93 |
16344.28 |
10007.33 |
5044.329 |
6273.252 |
4037.559 |
采样值 |
48782.54 |
48898.23 |
27655.61 |
16376.55 |
10018.32 |
5036.675 |
6256.41 |
4065.805 |
采样值 |
48724.83 |
48898.23 |
27683.35 |
16376.55 |
10018.32 |
5036.675 |
6290.116 |
4065.805 |
采样值 |
48782.54 |
48840.34 |
27655.61 |
16392.71 |
10029.33 |
5059.651 |
6290.116 |
4072.877 |
采样值 |
48724.83 |
48782.54 |
27711.13 |
16344.28 |
9996.338 |
5036.675 |
6273.252 |
4079.953 |
采样值 |
48782.54 |
48840.34 |
27738.93 |
16360.41 |
10007.33 |
5059.651 |
6290.116 |
4065.805 |
采样值 |
48724.83 |
48724.83 |
27655.61 |
16360.41 |
10018.32 |
5044.329 |
6273.252 |
4079.953 |
采样值 |
48609.71 |
48840.34 |
27600.23 |
16328.16 |
10040.34 |
5059.651 |
6281.681 |
4058.737 |
采样值 |
48667.23 |
48724.83 |
27627.91 |
16312.06 |
10007.33 |
5067.319 |
6307 |
4087.033 |
采样值 |
48552.3 |
48667.23 |
27627.91 |
16312.06 |
10018.32 |
5051.988 |
6298.555 |
4101.206 |
采样值 |
48609.71 |
48667.23 |
27572.59 |
16279.89 |
9996.338 |
5059.651 |
6298.555 |
4087.033 |
采样值 |
48552.3 |
48609.71 |
27627.91 |
16328.16 |
10040.34 |
5059.651 |
6290.116 |
4079.953 |
可以发现:随着时间的推移,采样值会逐渐减小。
减小这种趋势可以对电路图进行改进,会有很大的改观。
一般电路图
改进电路图
上面加一个电容,这样对多次采样会有很大的改,下面一组数据很能说明问题:
未加 |
未加 |
1pf |
1pf |
0.1uf |
0.1uf |
0.1uf |
0.1uf |
167.86 |
|||||||
172300.5 |
170511.6 |
177397.6 |
170955.7 |
176923.1 |
171401.9 |
170511.6 |
179804.9 |
172300.5 |
167889.9 |
175513.1 |
169629.6 |
177397.6 |
171850.1 |
171850.1 |
178835 |
171850.1 |
168321.8 |
174584.3 |
168755.8 |
177874.4 |
170511.6 |
170511.6 |
177874.4 |
170069.6 |
167889.9 |
174123.2 |
168755.8 |
177874.4 |
171401.9 |
170511.6 |
176923.1 |
169629.6 |
166605.9 |
173207.5 |
167889.9 |
176923.1 |
171401.9 |
170511.6 |
177397.6 |
168755.8 |
166605.9 |
172752.9 |
166605.9 |
177397.6 |
168755.8 |
170069.6 |
176923.1 |
168321.8 |
164921 |
171850.1 |
165759.6 |
175513.1 |
168321.8 |
169191.7 |
176923.1 |
168321.8 |
166181.8 |
169629.6 |
164921 |
175980.9 |
168755.8 |
169629.6 |
176923.1 |
167032 |
164089.9 |
169191.7 |
164089.9 |
175980.9 |
169629.6 |
170511.6 |
176923.1 |
166605.9 |
163677.1 |
168755.8 |
164089.9 |
175047.6 |
170511.6 |
169629.6 |
176450.8 |
166181.8 |
163266.2 |
167889.9 |
162857.1 |
175513.1 |
169629.6 |
171850.1 |
175047.6 |
165339.4 |
162044.4 |
167460 |
162449.9 |
176450.8 |
169191.7 |
169629.6 |
177397.6 |
164921 |
163266.2 |
167032 |
161640.8 |
175980.9 |
168755.8 |
168755.8 |
176450.8 |
164921 |
162857.1 |
166605.9 |
160838.9 |
175980.9 |
168321.8 |
168321.8 |
175980.9 |
164504.5 |
161640.8 |
165759.6 |
160440.5 |
175980.9 |
168321.8 |
167460 |
174123.2 |
163677.1 |
161640.8 |
164921 |
159649.1 |
174584.3 |
167889.9 |
168321.8 |
175047.6 |
结论:利用ADCFIFO采样时,上面加或不加电容,对采样的128个值总体表现是采样的值越来越小,加电容后,这种情况会有所减缓。电容大点会好很多。