最近使用Tms320F28335采样程序,将容易误解的地方分享个人看法。方便后来小朋友们少走弯路,也提醒自己。(如有错误,请大家多多指导。)
----------------------------------------------------------------------------------------------------------------------------
首先:各位使用DSP的朋友们,应该看过官方数据手册的参考代码吧。这段代码的意思是:将ADCINA0或者ADCINB0采样的数据存放在ADCRESULT0。CONVxx占用4个位,可以配置为0~15的范围。其实也是采样后的数据存储地址。
1 AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0 & ADCINB0 2 AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1 & ADCINB1 3 AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2; // Setup conv from ADCINA2 & ADCINB2 4 AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3; // Setup conv from ADCINA3 & ADCINB3 5 AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x4; // Setup conv from ADCINA4 & ADCINB4 6 AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x5; // Setup conv from ADCINA5 & ADCINB5 7 AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x6; // Setup conv from ADCINA6 & ADCINB6 8 AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x7; // Setup conv from ADCINA7 & ADCINB
1 AdcRegs.ADCTRL3.bit.SMODE_SEL = 0x1; // Setup simultaneous sampling mode 2 AdcRegs.ADCMAXCONV.all = 0x0033; // 4 double conv's each sequencer (8 total) 3 AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0 & ADCINB0 4 AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup conv from ADCINA1 & ADCINB1 5 AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x2; // Setup conv from ADCINA2 & ADCINB2 6 AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x3; // Setup conv from ADCINA3 & ADCINB3 7 AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x4; // Setup conv from ADCINA4 & ADCINB4 8 AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x5; // Setup conv from ADCINA5 & ADCINB5 9 AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x6; // Setup conv from ADCINA6 & ADCINB6 10 AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x7; // Setup conv from ADCINA7 & ADCINB7
也就是说:ADCINA0或者ADCINB0采样的数据存在AdcRegs.ADCRESULT0的寄存器里面。寻找采样结果时到指定的CONxx地址去找。
ADCINA[0] = ((AdcRegs.ADCRESULT0)>>4); ADCINA[1] = ((AdcRegs.ADCRESULT1)>>4); ADCINA[2] = ((AdcRegs.ADCRESULT2)>>4); ADCINA[3] = ((AdcRegs.ADCRESULT3)>>4); ADCINA[4] = ((AdcRegs.ADCRESULT4)>>4); ADCINA[5] = ((AdcRegs.ADCRESULT5)>>4); ADCINA[6] = ((AdcRegs.ADCRESULT6)>>4); ADCINA[7] = ((AdcRegs.ADCRESULT7)>>4);
------------------------------------------------------------------------------------------------------------------------------------------------------
容易误解的地方是:官方数据手册里面写了下面的内容。好像是默认指定了采样数据的存储地址。但实际上采样的地址是可以指定的。
1 If the cascaded SEQ was executed, the results would go to the following ADCRESULT registers: 2 ADCINA0 -> ADCRESULT0 3 ADCINB0 -> ADCRESULT1 4 ADCINA1 -> ADCRESULT2 5 ADCINB1 -> ADCRESULT3 6 ADCINA2 -> ADCRESULT4 7 ADCINB2 -> ADCRESULT5 8 ADCINA3 -> ADCRESULT6 9 ADCINB3 -> ADCRESULT7 10 ADCINA4 -> ADCRESULT8 11 ADCINB4 -> ADCRESULT9 12 ADCINA5 -> ADCRESULT10 13 ADCINB5 -> ADCRESULT11 14 ADCINA6 -> ADCRESULT12 15 ADCINB6 -> ADCRESULT13 16 ADCINA7 -> ADCRESULT14 17 ADCINB7 -> ADCRESULT15
1 If SEQ1 and SEQ2 were both executed, the results would go to the following RESULT registers: 2 ADCINA0 -> ADCRESULT0 3 ADCINB0 -> ADCRESULT1 4 ADCINA1 -> ADCRESULT2 5 ADCINB1 -> ADCRESULT3 6 ADCINA2 -> ADCRESULT4 7 ADCINB2 -> ADCRESULT5 8 ADCINA3 -> ADCRESULT6 9 ADCINB3 -> ADCRESULT7 10 ADCINA4 -> ADCRESULT8 11 ADCINB4 -> ADCRESULT9 12 ADCINA5 -> ADCRESULT10 13 ADCINB5 -> ADCRESULT11 14 ADCINA6 -> ADCRESULT12 15 ADCINB6 -> ADCRESULT13 16 ADCINA7 -> ADCRESULT14 17 ADCINB7 -> ADCRESULT15
--------------------------------------------------------------------------------------------
以官方寄存器手册为例,每一个CONVxx位占据了四个字节。也就是说0~15的范围。CONVxx的值代表着ADC输入口,对于的采样数据存在AdcRegs.ADCRESULTxx.
---------------------------------------------------------------------------------------
小结:
1、Tms320F28335中ADC采样数据的地址是可以人为指定的,不是固定到某个地址。也请不要被参考手册里面的内容误导了。
2、尴尬,我还信誓旦旦给别人说。我没写错,打脸了~~