DSP

TMS320F28335 ADC模块的学习

2019-07-13 15:24发布

      TMS320F28335内部包含12位AD转换器,其功能有:
具有内置(采样保持)S/H的12位ADC内核 模拟输入:0.0V至3.0V(高于3.0V的电压产生满刻度转换结果)。 快速转换率:在25MHzADC时钟12.5MSPS上时高达80ns 16个专用ADC通道。 每次采样/保持都有复用的8通道 自动定序功能在单次会话中可提供多达16次“自动转换”。可将每次转换编程为选择16个输入信道中的任何一个。 序列发生器可运行为2个独立的8态序列发生器,或作为1个较大的16态序列发生器(即2个级联的8态序列发生器)。 用于存储转换值的16个结果寄存器(可分别寻址) – 输入模拟电压的数值源自:
当input<0时:digital value =0;
当0
当input>3.0时:digital value =4095;

作为转换开始(SOC)序列源的多个触发器
– S/W-软件立即启动
– ePWMM转换开始
– XINT2ADC转换开始
灵活的中断控制允许每个序列结束(EOS) 或每个其它EOS上的中断请求。 序列发生器可运行于“启/停”模式,从而实现多个“时序触发器”同步转换。 SOCA和SOCB触发器可独立运行在双序列发生器模式中。 采样保持(S/H)采集时间窗口具有独立的预分频控制。

要获得指定的ADC精度,正确的电路板布局非常关键。为尽可能达到最佳效果,引入ADCIN引脚的走线不应太靠近数字信号通道。这是为了最大程度地减少数字线路上因ADC输入耦合而产生的开关噪声。而且,适当的隔离技术必须被用来将数字电源从ADC模块电源引脚(VDD1A18,VDD2A18,VDDA2,VDDAIO)上隔离。
ADC未被使用,ADC连接 建议保持针对模拟电源引脚的连接,即便在ADC未被使用时也是如此。下面总结了如果ADC未在应用中使用,应该如何连接ADC引脚:
• VDD1A18/VDD2A18-连接至VDD • VDDA2,VDDAIO-连接至VDDIO • VSS1AGND/VSS2AGND,VSSA2,VSSAIO-连接至VSS • ADCLO-连接至VSS • ADCREFIN-连接至VSS • ADCREFP/ADCREFM-连接一个100nF电容器至VSS • ADCRESEXT-连接一个20kΩ电阻器(非常松散的耐受)至VSS。 • ADCINAn,ADCINBn-连接至VSS
当ADC未被使用时,为了达到节能的目的,请确保到ADC模块的时钟未被打开。 当在一个应用中使用ADC模块时,未使用的ADC输入引脚应被连接至模拟接地(VSS1AGND/VSS2AGND)
ADC头文件与寄存器对应解读:
struct ADCTRL1_BITS {      // bits  description     Uint16  rsvd1:4;               // 3:0   reserved     Uint16  SEQ_CASC:1;      // 4     Cascaded sequencer mode 级联序列模式     Uint16  SEQ_OVRD:1;     // 5     Sequencer override  序列发生器覆盖     Uint16  CONT_RUN:1;    // 6     Continuous run 连续运行模式     Uint16  CPS:1;                // 7     ADC core clock pre-scalar ADC核心时钟分频     Uint16  ACQ_PS:4;         // 11:8  Acquisition window size采集窗口大小     Uint16  SUSMOD:2;       // 13:12 Emulation suspend mode仿真挂起模式     Uint16  RESET:1;          // 14    ADC reset ADC复位     Uint16  rsvd2:1;            // 15    reserved 保留 }; 下面的联合体主要是为了解决对这个寄存器的控制,可以是整体赋值液可以是一位一位的赋值。 union ADCTRL1_REG {    Uint16                all;    struct ADCTRL1_BITS   bit; };
struct ADCTRL2_BITS {                     // bits  description     Uint16  EPWM_SOCB_SEQ2:1;        // 0     EPWM compare B SOC mask for SEQ2  增强PWM比较器B作为SEQ2的启动转换标志     Uint16  rsvd1:1;                               // 1     reserved     Uint16  INT_MOD_SEQ2:1;             // 2     SEQ2 Interrupt mode  SEQ2终端模式                      Uint16  INT_ENA_SEQ2:1;               // 3     SEQ2 Interrupt enable  SEQ2中断使能     Uint16  rsvd2:1;                               // 4     reserved     Uint16  SOC_SEQ2:1;                      // 5     Start of conversion for SEQ2 启动SEQ2转换     Uint16  RST_SEQ2:1;                      // 6     Reset SEQ2     SEQ2复位     Uint16  EXT_SOC_SEQ1:1;             // 7     External start of conversion for SEQ1        序列1的外部转换启动     Uint16  EPWM_SOCA_SEQ1:1;       // 8     EPWM compare B SOC mask for SEQ1     Uint16  rsvd3:1;                              // 9     reserved     Uint16  INT_MOD_SEQ1:1;            // 10    SEQ1 Interrupt mode     Uint16  INT_ENA_SEQ1:1;             // 11    SEQ1 Interrupt enable     Uint16  rsvd4:1;                             // 12    reserved     Uint16  SOC_SEQ1:1;                    // 13    Start of conversion trigger for SEQ1     Uint16  RST_SEQ1:1;                    // 14    Restart sequencer 1        Uint16  EPWM_SOCB_SEQ:1;       // 15    EPWM compare B SOC enable };

struct ADCASEQSR_BITS {       // bits   description     Uint16  SEQ1_STATE:4;     // 3:0    SEQ1 state   序列1的状态     Uint16  SEQ2_STATE:3;     // 6:4    SEQ2 state   序列2的状态     Uint16  rsvd1:1;          // 7      reserved     Uint16  SEQ_CNTR:4;       // 11:8   Sequencing counter status   序列计数器状态     Uint16  rsvd2:4;          // 15:12  reserved   };

ADC最大转换信道数寄存器 struct ADCMAXCONV_BITS {      // bits  description     Uint16  MAX_CONV1:4;      // 3:0   Max number of conversions   序列1最大转换通道数     Uint16  MAX_CONV2:3;      // 6:4   Max number of conversions    序列2最大转换通道数     Uint16  rsvd1:9;          // 15:7  reserved  };
ADC信道选择排序控制寄存器 SEQ1只能使用ADCCHSELSEQ1和ADCCHSELSEQ2;AEQ2只能使用ADCCHSELSEQ3和ADCCHSELSEQ4 struct ADCCHSELSEQ1_BITS {    // bits   description     Uint16  CONV00:4;         // 3:0    Conversion selection 00     Uint16  CONV01:4;         // 7:4    Conversion selection 01     Uint16  CONV02:4;         // 11:8   Conversion selection 02     Uint16  CONV03:4;         // 15:12  Conversion selection 03 }; struct ADCCHSELSEQ2_BITS {    // bits   description     Uint16  CONV04:4;         // 3:0    Conversion selection 04     Uint16  CONV05:4;         // 7:4    Conversion selection 05     Uint16  CONV06:4;         // 11:8   Conversion selection 06     Uint16  CONV07:4;         // 15:12  Conversion selection 07 }; struct ADCCHSELSEQ3_BITS {    // bits   description     Uint16  CONV08:4;         // 3:0    Conversion selection 08     Uint16  CONV09:4;         // 7:4    Conversion selection 09     Uint16  CONV10:4;         // 11:8   Conversion selection 10     Uint16  CONV11:4;         // 15:12  Conversion selection 11 }; struct ADCCHSELSEQ4_BITS {    // bits   description     Uint16  CONV12:4;         // 3:0    Conversion selection 12     Uint16  CONV13:4;         // 7:4    Conversion selection 13     Uint16  CONV14:4;         // 11:8   Conversion selection 14     Uint16  CONV15:4;         // 15:12  Conversion selection 15 }; 控制寄存器3 struct ADCTRL3_BITS {         // bits   description     Uint16   SMODE_SEL:1;     // 0      Sampling mode select  采样模式选择     Uint16   ADCCLKPS:4;      // 4:1    ADC core clock divider  ADC时钟分频器     Uint16   ADCPWDN:1;       // 5      ADC powerdown    ADC断电???     Uint16   ADCBGRFDN:2;     // 7:6    ADC bandgap/ref power down  ADC参考/带隙断电  ???     Uint16   rsvd1:8;         // 15:8   reserved };
状态寄存器 struct ADCST_BITS {           // bits   description     Uint16   INT_SEQ1:1;      // 0      SEQ1 Interrupt flag   序列1中断标志     Uint16   INT_SEQ2:1;      // 1      SEQ2 Interrupt flag   序列2中断标志     Uint16   SEQ1_BSY:1;      // 2      SEQ1 busy status      序列1忙标志     Uint16   SEQ2_BSY:1;      // 3      SEQ2 busy status     序列2忙标志     Uint16   INT_SEQ1_CLR:1;  // 4      SEQ1 Interrupt clear  清除序列1中断标志     Uint16   INT_SEQ2_CLR:1;  // 5      SEQ2 Interrupt clear  清除序列2中断标志     Uint16   EOS_BUF1:1;      // 6      End of sequence buffer1   序列缓冲器1结束     Uint16   EOS_BUF2:1;      // 7      End of sequence buffer2     Uint16   rsvd1:8;         // 15:8   reserved };

struct ADCREFSEL_BITS {       // bits   description Uint16   rsvd1:14;        // 13:0   reserved   Uint16   REF_SEL:2;       // 15:14  Reference select   参考选择??? };
struct ADCOFFTRIM_BITS{       // bits   description int16 OFFSET_TRIM:9;    // 8:0    Offset Trim   偏移微调??? Uint16 rsvd1:7;          // 15:9   reserved };
ADC寄存器 struct ADC_REGS {     union  ADCTRL1_REG       ADCTRL1;                   // ADC Control 1     union  ADCTRL2_REG       ADCTRL2;                   // ADC Control 2     union  ADCMAXCONV_REG    ADCMAXCONV;    // Max conversions     union  ADCCHSELSEQ1_REG  ADCCHSELSEQ1;  // Channel select sequencing control 1     union  ADCCHSELSEQ2_REG  ADCCHSELSEQ2;  // Channel select sequencing control 2     union  ADCCHSELSEQ3_REG  ADCCHSELSEQ3;  // Channel select sequencing control 3     union  ADCCHSELSEQ4_REG  ADCCHSELSEQ4;  // Channel select sequencing control 4     union  ADCASEQSR_REG       ADCASEQSR;        // Autosequence status register     Uint16                 ADCRESULT0;    // Conversion Result Buffer 0     Uint16                 ADCRESULT1;    // Conversion Result Buffer 1     Uint16                 ADCRESULT2;    // Conversion Result Buffer 2     Uint16                 ADCRESULT3;    // Conversion Result Buffer 3     Uint16                 ADCRESULT4;    // Conversion Result Buffer 4     Uint16                 ADCRESULT5;    // Conversion Result Buffer 5     Uint16                 ADCRESULT6;    // Conversion Result Buffer 6     Uint16                 ADCRESULT7;    // Conversion Result Buffer 7     Uint16                 ADCRESULT8;    // Conversion Result Buffer 8     Uint16                 ADCRESULT9;    // Conversion Result Buffer 9     Uint16                 ADCRESULT10;   // Conversion Result Buffer 10     Uint16                 ADCRESULT11;   // Conversion Result Buffer 11     Uint16                 ADCRESULT12;   // Conversion Result Buffer 12     Uint16                 ADCRESULT13;   // Conversion Result Buffer 13     Uint16                 ADCRESULT14;   // Conversion Result Buffer 14     Uint16                 ADCRESULT15;   // Conversion Result Buffer 15     union  ADCTRL3_REG      ADCTRL3;       // ADC Control 3       union  ADCST_REG          ADCST;         // ADC Status Register     Uint16                 rsvd1;     Uint16                 rsvd2;     union  ADCREFSEL_REG      ADCREFSEL;      // Reference Select Register     union  ADCOFFTRIM_REG   ADCOFFTRIM;    // Offset Trim Register }; struct ADC_RESULT_MIRROR_REGS {     Uint16                 ADCRESULT0;    // Conversion Result Buffer 0     Uint16                 ADCRESULT1;    // Conversion Result Buffer 1     Uint16                 ADCRESULT2;    // Conversion Result Buffer 2     Uint16                 ADCRESULT3;    // Conversion Result Buffer 3     Uint16                 ADCRESULT4;    // Conversion Result Buffer 4     Uint16                 ADCRESULT5;    // Conversion Result Buffer 5     Uint16                 ADCRESULT6;    // Conversion Result Buffer 6     Uint16                 ADCRESULT7;    // Conversion Result Buffer 7     Uint16                 ADCRESULT8;    // Conversion Result Buffer 8     Uint16                 ADCRESULT9;    // Conversion Result Buffer 9     Uint16                 ADCRESULT10;   // Conversion Result Buffer 10     Uint16                 ADCRESULT11;   // Conversion Result Buffer 11     Uint16                 ADCRESULT12;   // Conversion Result Buffer 12     Uint16                 ADCRESULT13;   // Conversion Result Buffer 13     Uint16                 ADCRESULT14;   // Conversion Result Buffer 14     Uint16                 ADCRESULT15;   // Conversion Result Buffer 15 };

ADC_Cal()常规步骤: 第一步:这个是TI公司提供的文件 .def _ADC_cal                                                      ;定义代码段名称 .asg "0x711C", ADCREFSEL_LOC                         ;ADCREFSEL_LOC 是 ADC Reference Select Register, 地址0x711C  .sect".adc_cal" _ADC_cal
MOVW DP, #ADCREFSEL_LOC >> 6        ;此时 DP = 0x7100  MOV @28, #0xAAAA                                ;地址 : 0x7100 + 28 MOV @29, #0xBBBB                                 ;地址 : 0x7100 + 29 LRETR
第二步:为 ADC_Cal() 添加命令文件 MEMORY {
PAGE 0 :
...
ADC_CAL : origin = 0x380080, length = 0x000009
...
} SECTIONS {
... .adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD ...
} 第三步:在使用ADC前要声明ADC_Cal(),并且在使用ADC_Cal()之前要使能ADC高速时钟。
extern void ADC_cal(void); … EALLOW;                                                      //允许对受保护的寄存器进行操作 SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;  //使能时钟 ADC_cal();                                                     SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0;  //关闭时钟 EDIS;                                                            //禁止对受保护的寄存器进行操作


ADC转换软件步骤:
初始化DSP系统;   设置PIE 中断矢量表,  初始化ADC模块;  将ADC中断的入口地址装入PIE 中断矢量表中,开中断;  软件启动ADC转换;  等待ADC中断;  在ADC中断中读取ADC转换结果,软件启动下一次ADC中断。