TMS320F28335内部包含12位AD转换器,其功能有:( ^ J2 C+ N2 d0 l) n8 t
具有内置(采样保持)S/H的12位ADC内核
模拟输入:0.0V至3.0V(高于3.0V的电压产生满刻度转换结果)。
快速转换率:在25MHzADC时钟12.5MSPS上时高达80ns$ a: Q& Z! y3 ?( w7 W
16个专用ADC通道。 ^2 ]1 V6 X6 U: b% }* ?' }2 ^
每次采样/保持都有复用的8通道+ V, K; Z7 P x1 f3 ]( a. L) a
自动定序功能在单次会话中可提供多达16次“自动转换”。可将每次转换编程为选择16个输入信道中的任何一个。
序列发生器可运行为2个独立的8态序列发生器,或作为1个较大的16态序列发生器(即2个级联的8态序列发生器)。
用于存储转换值的16个结果寄存器(可分别寻址)0 Z* V2 M1 {5 w- Z: Z
– 输入模拟电压的数值源自:
当input<0时:digital value =0;- b0 {- y- H ~5 c/ e3 q; N
当0<input<3.0时:digital value =4096*(input analog voltage-ADCLO)/3;
当input>3.0时:digital value =4095;
! v# l+ `" [/ s
作为转换开始(SOC)序列源的多个触发器
– S/W-软件立即启动
– ePWMM转换开始
– XINT2ADC转换开始 \, d" S3 Q* t% A/ k& O
灵活的中断控制允许每个序列结束(EOS) 或每个其它EOS上的中断请求。; l& i* H/ u! k1 M/ R
序列发生器可运行于“启/停”模式,从而实现多个“时序触发器”同步转换。
SOCA和SOCB触发器可独立运行在双序列发生器模式中。. g& m, | `) l: L
采样保持(S/H)采集时间窗口具有独立的预分频控制。
要获得指定的ADC精度,正确的电路板布局非常关键。为尽可能达到最佳效果,引入ADCIN引脚的走线不应太靠近数字信号通道。这是为了最大程度地减少数字线路上因ADC输入耦合而产生的开关噪声。而且,适当的隔离技术必须被用来将数字电源从ADC模块电源引脚(VDD1A18,VDD2A18,VDDA2,VDDAIO)上隔离。
ADC未被使用,ADC连接! _9 }2 R: y* i% P- q
建议保持针对模拟电源引脚的连接,即便在ADC未被使用时也是如此。下面总结了如果ADC未在应用中使用,应该如何连接ADC引脚:
? VDD1A18/VDD2A18-连接至VDD2 v3 r0 R# y; J e8 ^
? VDDA2,VDDAIO-连接至VDDIO! F" {3 K( t0 N
? VSS1AGND/VSS2AGND,VSSA2,VSSAIO-连接至VSS
? ADCLO-连接至VSS/ e4 T7 i& V+ n) ^1 F- U& }
? ADCREFIN-连接至VSS5 i" N4 Q* m0 k
? ADCREFP/ADCREFM-连接一个100nF电容器至VSS
? ADCRESEXT-连接一个20k?电阻器(非常松散的耐受)至VSS。
? ADCINAn,ADCINBn-连接至VSS0 A* a8 q$ D' V2 T$ K5 e
当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 序列发生器覆盖 l% q. h) O+ m+ o
Uint16 CONT_RUN:1; // 6 Continuous run 连续运行模式; G8 d. a, a( s. K4 p5 A7 a# n% n
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 保留
};4 h& x0 } p9 y- Q" u6 l1 E0 N
下面的联合体主要是为了解决对这个寄存器的控制,可以是整体赋值液可以是一位一位的赋值。
union ADCTRL1_REG {' I) y1 _! q$ [1 h: d
Uint16 all;
struct ADCTRL1_BITS bit;, n9 w# R0 ^* W) f3 v
};
struct ADCTRL2_BITS { // bits description/ {4 ^5 z% }! o
Uint16 EPWM_SOCB_SEQ2:1; // 0 EPWM compare B SOC mask for SEQ2 增强PWM比较器B作为SEQ2的启动转换标志- I! o* s! J9 I% h
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转换5 l: k1 E0 I9 J( ~8 f# l
Uint16 RST_SEQ2:1; // 6 Reset SEQ2 SEQ2复位
Uint16 EXT_SOC_SEQ1:1; // 7 External start of conversion for SEQ1 序列1的外部转换启动- H. R0 r# K3 X8 U
Uint16 EPWM_SOCA_SEQ1:1; // 8 EPWM compare B SOC mask for SEQ1
Uint16 rsvd3:1; // 9 reserved4 T, k+ `0 g+ m6 W l: H
Uint16 INT_MOD_SEQ1:1; // 10 SEQ1 Interrupt mode# k. b- j$ L1 O, a6 @, [2 Y
Uint16 INT_ENA_SEQ1:1; // 11 SEQ1 Interrupt enable6 F# \: o V" h% D0 i) i' J6 o
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
};
; k5 }1 \% z- _
struct ADCASEQSR_BITS { // bits description
Uint16 SEQ1_STATE:4; // 3:0 SEQ1 state 序列1的状态
Uint16 SEQ2_STATE:3; // 6:4 SEQ2 state 序列2的状态2 v# i4 o3 V; r4 S4 O
Uint16 rsvd1:1; // 7 reserved% a: a9 j# w9 M: V$ h
Uint16 SEQ_CNTR:4; // 11:8 Sequencing counter status 序列计数器状态
Uint16 rsvd2:4; // 15:12 reserved
};
2 v$ O+ B- E, s. Z$ | \: h% B& \$ I5 {
ADC最大转换信道数寄存器
struct ADCMAXCONV_BITS { // bits description" G/ i" v% v$ a5 q' e
Uint16 MAX_CONV1:4; // 3:0 Max number of conversions 序列1最大转换通道数8 E/ _4 X! t& i0 I, V' u
Uint16 MAX_CONV2:3; // 6:4 Max number of conversions 序列2最大转换通道数5 r0 r/ Y+ P6 x3 S2 _- A2 |: O& |
Uint16 rsvd1:9; // 15:7 reserved
};
2 `- Z/ S" d! H) n/ x% `. _$ _
ADC信道选择排序控制寄存器5 U. S& n! h4 F( g8 A% d- c
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! Z6 e8 w0 M1 S6 q6 z [/ Q6 h0 x
Uint16 CONV04:4; // 3:0 Conversion selection 045 e* S" C) f) T* @& W6 g: h# I
Uint16 CONV05:4; // 7:4 Conversion selection 05
Uint16 CONV06:4; // 11:8 Conversion selection 06( W! \, y" A/ ?% s1 u$ D
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; T7 C1 d& E d1 o
Uint16 CONV10:4; // 11:8 Conversion selection 10
Uint16 CONV11:4; // 15:12 Conversion selection 11
};1 _; U- i1 W- Y G1 d
struct ADCCHSELSEQ4_BITS { // bits description. Z% Y- L; o- X( x
Uint16 CONV12:4; // 3:0 Conversion selection 121 t$ z8 K- B. R' p, ?% {. I
Uint16 CONV13:4; // 7:4 Conversion selection 13
Uint16 CONV14:4; // 11:8 Conversion selection 14- r" s9 q$ p1 V8 Z& w% l
Uint16 CONV15:4; // 15:12 Conversion selection 15+ L+ t+ M1 |. @' U
};
9 p r4 A1 Q- D+ c# t
控制寄存器32 }$ |& m7 I& L8 ?
struct ADCTRL3_BITS { // bits description5 c, M U8 D- f1 d. k/ Q' B
Uint16 SMODE_SEL:1; // 0 Sampling mode select 采样模式选择 i3 q W& k) D- ], H& F9 F; ^
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参考/带隙断电 ???7 g0 a- S7 u% p3 |& |
Uint16 rsvd1:8; // 15:8 reserved
};
# w/ s: Q, d) i0 Y% \
状态寄存器7 C5 z# t7 l+ e7 C
struct ADCST_BITS { // bits description7 g- p5 a+ P: g, q! Y+ X" k2 u# d6 j
Uint16 INT_SEQ1:1; // 0 SEQ1 Interrupt flag 序列1中断标志7 \9 v; W6 v1 i9 A" p4 q7 x
Uint16 INT_SEQ2:1; // 1 SEQ2 Interrupt flag 序列2中断标志4 w* |0 d, G1 K! [: N5 Z/ Y6 L
Uint16 SEQ1_BSY:1; // 2 SEQ1 busy status 序列1忙标志, T/ y& w$ h) ]: x
Uint16 SEQ2_BSY:1; // 3 SEQ2 busy status 序列2忙标志
Uint16 INT_SEQ1_CLR:1; // 4 SEQ1 Interrupt clear 清除序列1中断标志7 I9 Q1 s. j$ E7 p8 H" e* K
Uint16 INT_SEQ2_CLR:1; // 5 SEQ2 Interrupt clear 清除序列2中断标志' b! p5 d6 j% ]8 @
Uint16 EOS_BUF1:1; // 6 End of sequence buffer1 序列缓冲器1结束0 z2 {! @% _2 {9 }; T: u
Uint16 EOS_BUF2:1; // 7 End of sequence buffer28 Y1 O8 S! v/ V
Uint16 rsvd1:8; // 15:8 reserved
};
" {% ]6 }+ W, h
struct ADCREFSEL_BITS { // bits description4 I4 f9 F& e8 ?* Z' m3 s
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* u9 ^4 |9 n1 T% A5 B' w
};
ADC寄存器
struct ADC_REGS {8 f, Z+ B" |; [$ s' `$ |
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! E7 E0 K2 U) D8 [7 G
union ADCCHSELSEQ2_REG ADCCHSELSEQ2; // Channel select sequencing control 2
union ADCCHSELSEQ3_REG ADCCHSELSEQ3; // Channel select sequencing control 34 g1 R7 t& {! ^
union ADCCHSELSEQ4_REG ADCCHSELSEQ4; // Channel select sequencing control 4
union ADCASEQSR_REG ADCASEQSR; // Autosequence status register0 C+ j& i1 l$ A- t% M5 m
Uint16 ADCRESULT0; // Conversion Result Buffer 0
Uint16 ADCRESULT1; // Conversion Result Buffer 1
Uint16 ADCRESULT2; // Conversion Result Buffer 24 N. J0 Z2 Y/ @. P. f; i
Uint16 ADCRESULT3; // Conversion Result Buffer 32 @( E$ b6 R+ y* g3 N; {
Uint16 ADCRESULT4; // Conversion Result Buffer 4
Uint16 ADCRESULT5; // Conversion Result Buffer 5
Uint16 ADCRESULT6; // Conversion Result Buffer 6- e# X: |6 D+ U
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 d; E8 w$ s4 D+ u$ ]$ W
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;1 s& `6 h, o. x' ^! \
union ADCREFSEL_REG ADCREFSEL; // Reference Select Register
union ADCOFFTRIM_REG ADCOFFTRIM; // Offset Trim Register
};% C! p3 X% x7 p
struct ADC_RESULT_MIRROR_REGS2 Y5 u$ E! S* c, \: \% C9 S( |" K+ H
{
Uint16 ADCRESULT0; // Conversion Result Buffer 0
Uint16 ADCRESULT1; // Conversion Result Buffer 1
Uint16 ADCRESULT2; // Conversion Result Buffer 23 k5 d, b0 N0 ~& Q- J1 o/ K
Uint16 ADCRESULT3; // Conversion Result Buffer 3
Uint16 ADCRESULT4; // Conversion Result Buffer 4( N& p# f8 H5 z E7 P% Y" }" S# Z
Uint16 ADCRESULT5; // Conversion Result Buffer 57 k! y' H9 H/ y0 e7 p
Uint16 ADCRESULT6; // Conversion Result Buffer 6
Uint16 ADCRESULT7; // Conversion Result Buffer 7$ K. a! ^! R/ A, C- ^3 V% Y
Uint16 ADCRESULT8; // Conversion Result Buffer 8& C- ]. j5 h9 y5 Z6 ^, A6 e
Uint16 ADCRESULT9; // Conversion Result Buffer 9
Uint16 ADCRESULT10; // Conversion Result Buffer 10, l C( ]. ]! ?) {- Q; f' p* y$ k
Uint16 ADCRESULT11; // Conversion Result Buffer 11
Uint16 ADCRESULT12; // Conversion Result Buffer 127 u% }3 F- W# C! M8 s
Uint16 ADCRESULT13; // Conversion Result Buffer 138 j( }" I$ j4 L v
Uint16 ADCRESULT14; // Conversion Result Buffer 141 m( q0 x2 d( \/ d$ q- |. `- @
Uint16 ADCRESULT15; // Conversion Result Buffer 15' T- N/ p! R0 ~" n1 S0 X1 I
};
ADC_Cal()常规步骤:
第一步:这个是TI公司提供的文件* u4 m3 C% b5 a4 i
.def _ADC_cal ;定义代码段名称7 A' E: n2 r. q
.asg "0x711C", ADCREFSEL_LOC ;ADCREFSEL_LOC 是 ADC Reference Select Register, 地址0x711C
.sect".adc_cal"
_ADC_cal6 W% b8 L9 l! N# f# Y; ^
MOVW DP, #ADCREFSEL_LOC >> 6 ;此时 DP = 0x7100
MOV @28, #0xAAAA ;地址 : 0x7100 + 28
MOV @29, #0xBBBB ;地址 : 0x7100 + 29* c, a; ]+ u R' L* _8 a8 K
LRETR
第二步:为 ADC_Cal() 添加命令文件 : r; `5 _1 u1 H: P P, J4 I& p
MEMORY( m4 B5 Y, L+ |3 |4 C# `
{( q+ x5 F# N) x/ |7 ]% D9 X
PAGE 0 :8 s" {% k/ P* g* }' A
...
ADC_CAL : origin = 0x380080, length = 0x000009; A$ r0 K/ u+ h8 L9 e' Y( L, X
...5 {5 @% J' t) D% D0 T8 K3 A. \
}# ?2 y% b9 m' R( ?( ], {) W% k
SECTIONS. i5 X1 O5 y5 _* l. `) f! ~
{1 E9 o! p) c5 L, `
...( {8 u+ }6 }; J' m" D
.adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD% i" o0 \) T9 I: @: h+ i9 m
...* V+ ?) q! y+ I0 E' }
}- ?, g( c. V9 N( D
第三步:在使用ADC前要声明ADC_Cal(),并且在使用ADC_Cal()之前要使能ADC高速时钟。; t) h; e4 K0 ~0 M2 J* L& n+ y
extern void ADC_cal(void);
…5 X- h$ k' P; s* Q
EALLOW; //允许对受保护的寄存器进行操作* \; J" \0 ~& d, s# K# O
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; //使能时钟
ADC_cal();
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0; //关闭时钟9 S8 g& T, c& @9 h2 G: C
EDIS; //禁止对受保护的寄存器进行操作
ADC转换软件步骤:6 h2 L# m% \5 w \ Y# T
初始化DSP系统;
设置PIE 中断矢量表,
初始化ADC模块; x' C( H& |9 T2 D% A) R
将ADC中断的入口地址装入PIE 中断矢量表中,开中断;
软件启动ADC转换; B" S1 D6 q# L" g
等待ADC中断; 1 V3 X3 g# X. B3 Q7 W
在ADC中断中读取ADC转换结果,软件启动下一次ADC中断。
| 欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/) | Powered by Discuz! X3.2 |