• 易迪拓培训,专注于微波、射频、天线设计工程师的培养
首页 > 电子设计 > 电源技术 > DCDC开关电源 > 利用电位计替代旋转开关设计方案

利用电位计替代旋转开关设计方案

录入:edatop.com    点击:
<[p] >  有时,基于微控制器的产品需要使用旋转开关。由于很多微控制器都内置了ADC,在找不到旋转开关或旋转开关价格过高时,可以使用低成本电位计来替代旋转开关(图1)。<[p] >  尽管仅需执行少量指令即可将电位计设定值数字化,使其表现得像开关一样,但一个急需解决的问题是,在电气噪声或机械噪声的影响下,在某一个值和下一个值之间的切换阈值处,数值会不稳定。该问题的解决方法是为每次转换引入上、下两个迟滞阈值,这样一来,电位计就需要在另一个开关状态有效前越过阈值。针对每次更新的开关状态,都会有新的一对阈值替换之前的阈值。如此,迟滞效应可以实现各状态间的完全切换。<[p] >  
<[p] >&nbs[p] ;<[p] >  图1:替代多掷开关<[p] >  这一方法具有下述诸多优势:单端口引脚对旋转开关的多端口引脚、成本低、更易获得且可实现去抖动切换。该方法的不足之处在于会失去制动感。设定点的另一特性是其可设置在任一位置,例如用以补偿电位计在响应过程中出现的非线性变化。<[p] >  迟滞通常稍高于会导致不期望切换的任何噪声。建议在电位计触点与地之间设置一个电容器,以滤除触点噪声(图1)。<[p] >  图2列出了算法。一旦用ADC对电位计设定值进行了数字化操作,该数值就将与下阈值比较,若低于下阈值,开关状态会逐渐降低并限制至零。若电位计设定值高于上阈值,开关状态会逐渐增大并限制至最大值。若开关状态发生变化,则上、下阈值会进行更新,并终止子程序。<[p] >  
<[p] >&nbs[p] ;<[p] >  图2:流程图<[p] >  为确保该迟滞算法起作用,必须定期读取电位计设定值,并与上一次开关状态进行比较。这样做旨在将从不同状态跨过阈值或处于相同值的电位计设定值与相同状态区分开。<[p] >  此处还需要计算出采样率的最小值,可由电位计旋转率最大值除以开关状态数得到。例如,假设单匝电位计旋钮在0.25s内完整旋转一圈,同时假定有七种状态,那么最低扫描率为28Hz.若电位计数值采样周期低于最小值,即使切换方向正确,计算得出的开关状态也可能不正确。倘若未以较快的速率持续改变电位计设定值,则随后的采样会对切换状态进行校正。<[p] >  以七种开关状态为例创建一个阈值列表。假设有一个8位ADC。首先,ADC的256步范围被分割为七种开关状态。各开关状态的宽度为ADC范围除以状态数,即:256/7=36.6.对其四舍五入,将各状态的宽度定为36,但是两个外端状态需增加至38,以使总宽度为256。<[p] >  下一步是确定各开关状态的边界。对于状态0,边界为0~37(包含两端)。状态1从38开始到73结束,其余开关状态依此类推。根据增加或降低至边界的迟滞数值确定阈值。此处使用4这一迟滞值。迟滞量既不得大于宽度,也不得低于预期的噪声。因此,上边界加4即可得出上阈值,下边界减4即可得出下阈值,如表1所示。从该例可发现,从状态2切换为状态1需要使电位计数值下降至比切换点数值74小4,因此下阈值为70。相反,从状态1切换为状态2需要使电位计数值上升至比切换点数值73高4,因此上限阈值为77。用于程序代码的表格仅需标明上、下阈值,在此例中仅需14个字节。<[p] >  表1 阈值<[p] >  
<[p] >&nbs[p] ;<[p] >  代码示例(见下)支持Silicon Labs的C8051F310(8051架构),但也可以很容易地改编用于其他微控制器。<[p] >  ;[p] OT2SW INITIALIZATION<[p] >  MOV U[p] RVAL, #00H;set u[p] [p] er value to o[p] [p] osite end to force the code to run<[p] >  MOV LWRVAL, #0FFH;set lower value to o[p] [p] osite end to force the code to run<[p] >  MOV SW[p] OS, #03H;initialize switch [p] osition to middle<[p] >  MOV [p] OSMAX, #06H;set maximum SWITCH [p] osition value<[p] >  ;SUBROUTINES<[p] >  [p] OT2SW:;CALCULATE SWITCH [p] OSITION VALUE FROM [p] OTENTIOMETER VALUE IN ACC<[p] >  ;check if [p] ot setting is below lower threshold<[p] >  CLR C<[p] >  MOV B, A ;save [p] ot setting to register B<[p] >  SUBB A, LWRVAL;[p] otval - lwrval<[p] >  JNC [p] 2S1 ;no carry means [p] otval >= lwrval<[p] >  DEC SW[p] OS ;carry means [p] otval < lwrval, so decrement switch [p] osition value [[p] ] <[p] >  ;check if switch [p] osition is < zero<[p] >  MOV A, [p] OSMAX;load maximum switch [p] osition value<[p] >  CLR C<[p] >  SUBB A, SW[p] OS;max switch value - switch [p] osition<[p] >  JNC [p] 2S2<[p] >  MOV SW[p] OS, #00H;reset switch [p] osition value to zero since underflow<[p] >  SJM[p] [p] 2S2<[p] >  [p] 2S1: ;check if [p] ot setting is above u[p] [p] er theshold<[p] >  CLR C<[p] >  MOV A, U[p] RVAL<[p] >  SUBB A, B ;u[p] rval - [p] otval<[p] >  JNC [p] 2S2 ;no carry means [p] otval <= u[p] rval<[p] >  INC SW[p] OS ;carry means [p] otval >u[p] rval, so increment switch [p] osition value<[p] >  ;check if switch [p] osition is > max<[p] >  MOV A, [p] OSMAX;load maximum xwitch [p] osition value<[p] >  CLR C<[p] >  SUBB A, SW[p] OS<[p] >  JNC [p] 2S2<[p] >  MOV SW[p] OS, [p] OSMAX;reset curve number to max curve value since overflow<[p] >  [p] 2S2: ;read lower and u[p] [p] er thresholds using switch [p] osition value<[p] >  MOV A, SW[p] OS ;multi[p] ly switch [p] osition value by 2<[p] >  MOV B, #02H<[p] >  MUL AB<[p] >  MOV B, A ;save multi[p] lied value as table offset<[p] >  MOV D[p] TR, #HYSTBL;load base address of table [p] ointer<[p] >  MOVC A, @A+D[p] TR;look u[p] table value from base address + offset<[p] >  MOV LWRVAL, A;read lower threshold value<[p] >  MOV A, B<[p] >  INC D[p] TR ;increment base address<[p] >  MOVC A, @A+D[p] TR<[p] >  MOV U[p] RVAL, A;read u[p] [p] er threshold value<[p] >  RET<[p] >  HYSTBL:;TABLE OF LOWER &am[p] ; U[p] [p] ER THRESHOLDS FOR SEVEN [p] OSITION SWITCH<[p] >  DB00D,41D;Switch state 0<[p] >  DB34D,77D;Switch state 1<[p] >  DB70D,113D;Switch state 2<[p] >  DB106D,149D;Switch state 3<[p] >  DB142D,185D;Switch state 4<[p] >  DB178D,221D;Switch state 5<[p] >  DB214D,255D;Switch state 6

射频工程师养成培训教程套装,助您快速成为一名优秀射频工程师...

天线设计工程师培训课程套装,资深专家授课,让天线设计不再难...

上一篇:以移相全桥为主电路的软开关电源设计全解
下一篇:选择低EMI电源需要清楚的几大要素

射频和天线工程师培训课程详情>>

  网站地图