使用DS1050可编程PWMs控制直流电动机和LED背光液晶

abstract: the ds1050 is a 5-bit pulse-width modulator (pwm) controlled by a 2-wire bus. this allows a single master device to control up to 8 slave (ds1050 and other 2-wire devices) on a single 2-wire bus. in this application note, an interface to a 2-wire bus via a pc serial interface is demonstrated. the hardware and software requirements are given and available for download from the dallas semiconductor ftp site.
introductionthe ds1050 is a 5-bit programmable pulse width modulator (pwm) that allows you to vary the duty cycle on-the-fly from 0 to 100% in 3.125% increments. it is controlled by a 2-wire serial interface that can address up to eight ds1050s on a single 2-wire bus. it is available in both an 8-pin soic and an 8-pin µsop package in the following frequencies: 1khz, 5khz, 10khz, and 25khz. a ds1052 is also available, which is a 100khz version of the ds1050.
this application note shows examples using a ds1050 as a dc fan controller and as a backlight brightness controller for an led backlit lcd. in addition, this application note will show how to interface multiple ds1050s on a single 2-wire bus. firmware for an 8051 based system is included in appendix a.
system overviewthe reference schematic in figure 1 is divided into two subsystems, the dc fan motor controller block and the lcd led backlight controller block. in addition, it shows a microcontroller as the 2-wire master and how it interfaces to the 2-wire slaves, the ds1050s.
figure 1. reference schematic.
2-wire interfacethe 2-wire master is implemented using open-drain outputs (one of which must be input and output) along with pull-up resistors r1 and r2 to generate the sda (serial data) and scl (serial clock) signals. the values given for r1 and r2 in the reference schematic will work fine for most applications, but these may need to be recalculated depending on the bus capacitance and the desired communication speed. additional 2-wire devices can be added to the bus by connecting its sda and scl to the master's sda and scl pins. address pins a0, a1, and a2 need to be tied high or low in order to give each device on the bus a unique address. the ds1050 (u1) in the schematic has all three address pins tied to ground, giving it a slave address of '000'. the ds1050 (u2) is set to a slave address of '001', however, any address other than u1's address will work. these address pins, along with the ds1050 family code, or device identifier of '0101' are then used by the master to communicate with each slave individually.
figure 2 shows how these bits are used in a typical 2-wire transaction. after the 2-wire master generates a start condition, the control byte is sent (msbit first) to select a particular device on the 2-wire bus. all devices on the bus listen to the control byte and check to see if it matches its own device identifier and slave address. the device that matches will respond by pulling sda low to ack. the lsbit of the control byte contains the r/w bit. this bit determines who will transmit the next byte, the data byte. if the r/w bit is set to a '1', then the master will read from the slave. so the master would then clock in the data byte from the slave. if the r/w bit was a '0', then the master will transmit the data byte to the slave. the 3 msbits of the data byte can be thought of as opcodes, or instructions. for example, if these were '110', the master is instructing the ds1050 to enter shutdown mode. if these 3 bits are '000', then the next 5-bits, the pwm data, will set a new pwm duty cycle to output. after the data byte is transmitted (or received), an ack (following a write) or a nack (following a read) must be performed. an ack (from slave) indicates that that it received the data during the write. a nack (generated by the master) informs the slave that the master received the byte and does not want any more data. if the ds1050 had more registers, the master can also ack (instead of nack), indicating that he [the master] received the byte and wants to continue reading. communication ends when the master issues a stop condition.
figure 2. typical 2-wire transaction.
figure 3 shows several examples of specific 2-wire instructions. a complete list of instructions can be found in the ds1050 datasheet
figure 3. example 2-wire transactions.
while only eight ds1050s can be on a single 2-wire bus, other 2-wire devices can be added to the bus as long as its device identifier is not identical to the ds1050's. this is very useful to control additional 2-wire devices such as temperature sensors or digital pots.
for example 8051 based firmware showing how to communicate and control both ds1050s, look in appendix a. also, for additional information regarding the 2-wire interface, refer to the ds1050 datasheet.
dc fan motor controllerthe dc motor controller block of the reference schematic in figure 1 shows a simple way to control a 12v dc fan motor using u1, a ds1050-025, to generate a 25khz pulse-width-modulated signal which controls the average power delivered to the motor. a low duty cycle produces low average power, and in turn, a lower speed. as the duty cycle is increased, so does the amount of on time. the average power and speed increase. a duty cycle of 0% means that the motor is completely off, while a duty cycle of 50% means that the motor is on at half power. also, when working with motors, it is important to be aware of the extra energy required to start the motor. in other words, don't set the duty cycle to 3.125% and expect the motor to turn. the motor you use will have a spec associated with this phenomenon. likewise, when a motor has a large load and is expected to make a large jump in speed, the motor may stall if it is not incremented in several smaller steps. these are not work-arounds, but are instead a result of the laws of physics. fortunately, these are easy to implement in firmware once you know they exist (although the included firmware is open loop and does not implement either of these cases).
choosing a pwm frequency
when interfacing a pwm to a motor, it is important that the pwm frequency not be within the audio spectrum. otherwise, the motor will act like a speaker and produce an audible tone of the pwm frequency. hence, the 25khz version was used in the reference schematic.
additional considerations that need to be made when choosing a pwm frequency are power consumption, emi radiation, and output stage limitations. theoretically, the difference in current consumption between the 25khz and the 100khz version is 4x as indicated by i=cvf, with all other things constant. ironically, the 100khz version only consumes 300µa of current, but the motor pulls orders of magnitudes more.
although emi radiation is not always an initial design consideration, if system emi radiation is later a problem (due to other components), you may investigate which version of the ds1050 will contribute the least to the problem frequency.
finally, if for some reason you are required to use a particular power mosfet for q1, you will need to check the mosfet's gate threshold voltage to see if it can be driven directly from the 5v digital pwm without the need of any level translations. also, you will need to verify that the mosfet can handle the pwm frequency you are considering.
driver circuit
the digital pwm output of the ds1050 swings from ground to vcc at the rated frequency and programmed duty cycle. the power-up default duty cycle is 50%. the pwm output controls the gate of q1, an n-channel power mosfet, which is capable of handling the current required by the 12v motor. typical motor currents can be anywhere from 100ma to 500ma. the gate threshold voltage of q1 is 2.0-4.0v. the ds1050 will have no problem directly driving the gate of q1.
the 1n40018 diode, d1, is required across the supply terminals of the motor to clamp any back-emf generated when the fan is off but still spinning due to its momentum. this is especially important when using pulse-width-modulation since while the fan is in normal operation, its power is being cycled 25,000 times a second. during the off times, the fan is spinning and the motor then becomes a generator and generates back-emf.
when the ds1050 is instructed to enter shutdown mode, the pwm output floats. therefore, to keep the gate of q1 in a known state during shutdown, a pull-down resistor, r3, is used to make sure the fan is off. this resistor can also be used as a pull-up if you want the motor to turn on when the ds1050 is in shutdown, although this does defeat the purpose of going into shutdown.
like always, it is important that sufficient decoupling be provided. likewise, it is important that the decoupling capacitor, c1, has good high frequency performance and physically located as close as possible to u1 using short pcb traces.
additional notes
although pwm is great for controlling standard dc motors, additional research will be needed if you plan to use the tachometer output found on some dc motors. since the tachometer output of these fans are usually open-collector (and use an external pull-up resistor), issues arise when the supply to the fan is pulse-width-modulated particularly when the open-collector output is pulling the line low. this may also vary from one motor manufacturer to another. in cases where the tachometer output is required, it may be beneficial to use a p-channel mosfet instead of an n-channel mosfet, interfaced to the ds1050 using a level shifter of some sort to drive the gate of the mosfet.
lcd led backlight brightness controllerthe backlight brightness controller block in figure 1 shows an example of how to control the led backlight brightness using pwm. this is not intended to control the lcd contrast voltage, vee, but instead the led backlight. many application notes can be found showing how to control vee, but since 5v led backlights are relatively new, this application note is a first.
the lcd used in this example is an optrex dmc20481 20x4 character display. a nice feature of this display is the 5v yellow-green led backlight as opposed to the backlights of the recent past that required high voltage inverters to drive the backlight. this lcd uses a standard single row 16 pin connector to interface to the system. pin 15 is the led backlight anode and pin 16 is the led cathode. the led forward voltage is 4.1v typical with a maximum forward current of 260ma.
by varying the pwm duty cycle, the average power delivered to the led also varies. a low duty cycle means that the led is off more than it is on. this will produce a dim led. as the duty cycle is increased, so is the power, and hence, a brighter led. when the duty cycle is set to 100%, the led is on 100% of the time and at the maximum brightness.
choosing a pwm frequency
controlling an led using pwm is fairly simple. the only requirement for it to work is for the pwm to be fast enough that our eyes cannot see the led blink, which is about 30hz. however, the slowest ds1050 is 1khz. this will work fine. there is no advantage considering any of the faster versions. we will, in fact, benefit using the slower part which draws the least amount of current (although, the ds1050 current draw is nil compared to the 260ma consumed by the led backlight). finally, since 1khz is relatively slow, emi radiation and output stage limitations are of little concern.
driver circuit
a ds1050-001 (u2) is used to generate a 1khz pulse-width-modulated signal to once again control the average power delivered to the load. the pwm output of u2 is from ground to vcc at the rated frequency and programmed duty cycle. the power-up default duty cycle is 50%. the pwm output controls the gate of q2, an n-channel power mosfet, capable of handling the 260ma required by the led backlight. the gate threshold voltage of q2 is 2.0-4.0v, so feeding the pwm output directly to the gate will not be an issue.
the 1n4001 diode, d2, is used to drop down vcc to 4.3v which is less than the maximum forward voltage of the led. a resistor could have been used in place of the diode, but due to the relatively large currents, a larger wattage resistor would be required.
when the ds1050 is instructed to enter shutdown mode, it floats the pwm output. therefore, to keep the gate of q2 in a known state during shutdown and prevent it from floating, a pull-down resistor, r4, is used to make sure backlight is off.
like always, it is important that sufficient decoupling be provided. likewise, it is important that the decoupling capacitor, c2, has good high frequency performance and physically located as close as possible to u2 using short pcb traces.
additional notes
if your application requires control of the lcd contrast voltage vee as well, a ds1803 would be a perfect fit. just connect sda and scl of the ds1803 to the 2-wire bus and choose a slave address to set a2, a1, and a0 to. however, since the ds1803 and the ds1050 share the same device identifier of '0101', the slave address you choose must be different than u1 and u2's address.
for more information on controlling the lcd contrast voltage, refer to dallas semiconductor application note 69 micropower circuit monitors positive supply current.
firmwarefirmware for an 8051 based system is included in appendix a. it is intended to show an example of the lower layer routines needed to talk to the ds1050s. note, however, that the firmware implements an open loop system. the loop can easily be closed, for example, by adding a 2-wire temperature sensor and controlling the fan speed depending on the temperature. but for the purpose of illustrating examples of communicating with the ds1050, a menu based, open loop example is beneficial. a pc terminal program is used to give the ds1050s commands. the commands can then be looked up in the firmware to see exactly what is being performed. the basic menu commands are as follows:
increment pwm duty cycle of u1 decrement pwm duty cycle of u1 increment pwm duty cycle of u2 decrement pwm duty cycle of u2 reserved for future use (to control a ds1803) reserved for future use (to control a ds1803) put u1 and u2 in shutdown mode exit u1 and u2 from shutdown mode read from u1 and u2 and display to the pc screen when the system is powered up, both ds1050s default to 50% duty cycle. the duty cycle of either device can be increased on decreased using the corresponding menu commands. the firmware for the first 8 menu commands show how to perform 2-wire writes, while menu command 9 shows a 2-wire read.
here is an example of setting the pwm duty cycle.
lcall start2wire ; 2-wire start mov a,#pwm1write ; device identifier=0101, slave address=000, r/w=0 lcall writebits ; send the command byte lcall ackslavewrite ; check for an acknowledge from the slave mov a,pwm1data ; pwm1data is a variable containing the desired duty cycle lcall writebits ; send data lcall ackslavewrite ; check for an acknowledge from the slave lcall stop2wire ; 2-wire stop this code implements the example shown in figure 3-b.
and here is an example of putting both d1050s in shutdown mode (similar to figure 3-a).
; pwm1 lcall start2wire ; 2-wire start mov a,#pwm1write ; device identifier=0101, slave address=000, r/w=0 lcall writebits ; send command byte lcall ackslavewrite ; check for acknowledge from the slave mov a,#0c0h ; shutdown command, (change to 80 to exit shutdown) lcall writebits ; send command lcall ackslavewrite ; check for acknowledge from the slave lcall stop2wire ; 2-wire stop ; pwm2 lcall start2wire ; 2-wire start mov a,#pwm2write ; device identifier=0101, slave address=001, r/w=0 lcall writebits ; send command byte lcall ackslavewrite ; check for acknowledge from the slave mov a,#0c0h ; shutdown command, (change to 80 to exit shutdown) lcall writebits ; send command lcall ackslavewrite ; check for acknowledge from the slave lcall stop2wire ; 2-wire stop finally, here is an example reading both ds1050s.
; read pwm1 lcall start2wire ; 2-wire start mov a,#pwm1read ; device identifier=0101, slave address=000, r/w=1 lcall writebits ; send command byte lcall ackslavewrite ; check for acknowledge from the slave lcall readbits ; read data from ds1050 #1 (fan pwm) mov pwm1data,a ; the acc contains the data read from the ds1050 ; nack from master not required, but optional lcall stop2wire ; 2-wire stop lcall paccsp ; display byte on pc screen followed by a space ; read pwm2 lcall start2wire ; 2-wire start mov a,#pwm2read ; device identifier=0101, slave address=001, r/w=1 lcall writebits ; send command byte lcall ackslavewrite ; check for acknowledge from the slave lcall readbits ; read data from ds1050 #2 (lcd pwm) mov pwm2data,a ; the acc contains the data read from the ds1050 ; nack from the master not required, but optional lcall stop2wire ; 2-wire stop lcall paccsp ; display data on pc screen lcall crlf ; newline the firmware found in appendix a, as well as additional information can be found on our ftp site listed at the end of this application note under contact information.
conclusionthe ds1050 is an easy to use, dedicated pwm that simplifies system design by relieving the microcontroller the responsibility of generating pwm timing. it is not limited to the motor controllers and led controllers shown in this application note, but can be used in any application that needs to control the power being delivered to a load. furthermore, the ds1050 becomes exponentially more attractive as additional pwms and additional frequencies are needed as up to eight ds1050s can be placed on a single 2-wire bus. each ds1050 on the 2-wire bus can be individually addressed and sent a number of simple 2-wire commands to set, control, and read from the pwm. best of all, the ds1050 is available in a tiny, 8-pin µsop package in the following frequencies: 1khz, 5khz, 10khz, and 25khz. the ds1052, which is a 100khz version of the ds1050, is available as well.
appendix a;****************************************************************************** ;* ds1050 appnote firmware * ;* copyright (c) 1999,2000,2001 dallas semiconductor/maxim * ;****************************************************************************** ;* * ;* this program is used to show an example of how to use the ds1050 in a * ;* real application. * ;* * ;* revision history * ;* 1.0 10/05/01 bjv initial release * ;* * ;****************************************************************************** ;* * ;* ds87c520 reference: * ;* * ;* p0.0 - 74acq573 p2.0 - a8 * ;* p0.1 - p2.1 - a9 * ;* p0.2 - p2.2 - a10 * ;* p0.3 - p2.3 - a11 * ;* p0.4 - p2.4 - a12 * ;* p0.5 - p2.5 - a13 * ;* p0.6 - p2.6 - a14 * ;* p0.7 - p2.7 - a15 * ;* * ;* p3.0 - p1.0 - scl * ;* p3.1 - p1.1 - sda * ;* p3.2 - p1.2 - rxd1 - to pc serial port * ;* p3.3 - p1.3 - txd1 - to pc serial port * ;* p3.4 - p1.4 - ack fail led * ;* p3.5 - p1.5 - led * ;* p3.6 - *wr p1.6 - led * ;* p3.7 - *rd p1.7 - heartbeat led * ;* * ;* bank 0 r0 - used for 2-wire read and write, do not destroy! * ;* bank 0 r3 - used for binasc routine, do not destroy! * ;* * ;****************************************************************************** ;* notes: * ;* 1. ds87c520 is running at 22.1184mhz * ;* 2. connect serial port 1 (p1.2 and p1.3) to pc * ;* * ;****************************************************************************** ;****************************************************************************** $nomod51 ; disable predefined 8051 registers $include (reg520.inc) ; ds87c520 definition file ;------------------------------------------------------------------ ; software version ;------------------------------------------------------------------ major_version equ 1 ; major version number minor_version equ 0 ; minor version number ;------------------------------------------------------------------ ; constants ;------------------------------------------------------------------ cr equ 0dh ;ascii carriage return lf equ 0ah ;ascii line feed bs equ 08h ;ascii back space etx equ 03h ;ascii end of text bel equ 07h ;ascii bell nak equ 15h ;ascii negative acknowledge ;------------------------------------------------------------------ ; serial port configuration ;------------------------------------------------------------------ sbufin equ sbuf1 ;use serial port 1 sbufon equ sbuf1 rin bit scon1.0 tin bit scon1.1 ;------------------------------------------------------------------ ; ds1050 specific ;------------------------------------------------------------------ pwm1read equ 51h ; control byte, a0=a1=a2=0, read pwm1write equ 50h ; control byte, a0=a1=a2=0, write pwm2read equ 53h ; control byte, a0=1, a1=a2=0, read pwm2write equ 52h ; control byte, a0=1, a1=a2=0, write dseg at 30h pwm1data: ds 1 ;ds1050 #1 data pwm2data: ds 1 ;ds1050 #2 data ;------------------------------------------------------------------ ; 2-wire bit definitions ;------------------------------------------------------------------ sda bit p1.1 scl bit p1.0 stack equ $ ;stack is above data ;********************************************************************* ;* hardware interrupt vectors (table on page 95 of ds databook) * ;********************************************************************* cseg at 0 ;power up and reset ljmp main cseg at 0003h ;external interrupt 0 ljmp noisr cseg at 000bh ;timer 0 interrupt ljmp noisr cseg at 0013h ;external interrupt 1 ljmp noisr cseg at 001bh ;timer 1 interrupt ljmp noisr cseg at 0023h ;serial port 0 interrupt ljmp noisr cseg at 002bh ;timer 2 interrupt ljmp tmr2_int ;service heartbeat led cseg at 0033h ;power fail interrupt (dallas priority 1) ljmp noisr cseg at 003bh ;serial port 1 interrupt (dallas) ljmp noisr cseg at 0043h ;external interrupt 2 (dallas) ljmp noisr cseg at 004bh ;external interrupt 3 (dallas) ljmp noisr cseg at 0053h ;external interrupt 4 (dallas) ljmp noisr cseg at 005bh ;external interrupt 5 (dallas) ljmp noisr cseg at 0063h ;watchdog interrupt (dallas) ljmp noisr cseg at 006bh ;real-time clock (dallas) ljmp noisr ;********************************************************************* ;* main program * ;********************************************************************* cseg at 0080h main: clr ea ;disable interrupts mov sp,#stack ;initialize stack lcall init_520 ;initialize ds87c520 lcall init_lcd ;initialize lcd lcall ptbanner ;print banner to screen lcall init2wire ;initialize 2-wire port lcall init1050s ;initialize ds1050's lcall lcdshowstat ;display ds1050 data to lcd setb ea ;enable interrupts ;********************************************************************* mainloop: jnb rin,nochar ;check for user input from uart lcall echo ;echo char to screen lcall crlf ;newline clr rin ;clear receive flag cjne a,#etx,char1 ;jump if not etx (ctrl-c) call ptbanner ;reprint the banner to the screen ljmp mainloop ;loop forever nochar:cpl p1.6 ;toggle led - for debug only ljmp mainloop ;loop forever until char received ;****************************************************** ;*** menu commands *** ;****************************************************** char1:cjne a,#'1',char2 ; increment pwm1 mov a,pwm1data ; get current pwm1 setting ; this should be read from device cjne a,#20h,c1ne ; if less than 20h, then jump ; pwm1 is already at 100% - do nothing lcall lcdshowstat ; display both pwms on lcd ljmp mainloop c1ne: jc c1l ; check if ; pwm1 is >20, in shutdown mode ; do nothing lcall lcdshowstat ; display both pwms on lcd ljmp mainloop c1l: ; pwm1 is 20, in shutdown mode ; do nothing lcall lcdshowstat ; display both pwms on lcd ljmp mainloop c3l: ; pwm2 is ', etx lcdbanner: db 'ds1050 appnote',00h pwm1disp: db 'ds1050 #1 (fan)= ',00h pwm2disp: db 'ds1050 #2 (lcd)= ',00h ackf: db 'ack failed', cr, lf, etx db_power: db 'low power int', cr, lf, etx db_noisr: db 'noisr int', cr, lf, etx buetx: db etx ;just in case ;*************************************************************************** $include (dslib.a51) ;serial port debug routines end ;***************************************************************************
激光传感器在车辆宽高超限检测中的应用[图]
热缩电缆封帽生产工艺流程及其特性的介绍
为什么贴片电阻成为大众首选
区块链对电信行业是否有影响
美国站群服务器做Amazon引流的优势是什么
使用DS1050可编程PWMs控制直流电动机和LED背光液晶
乘用车EDR 2021年爆发,自主ADAS供应商或成最大受益方
IPC标准帮助制造商清楚地了解客户要求并达到预期目标
Unity正式支持苹果visionOS平台订阅用户
电压电流传感器原理
头部代工厂开始集中打向汽车芯片
首届慧远杯 AI+新智造大学生挑战赛颁奖典礼即将召开
“IPv6”对“人工智能+教育”有什么作用?
雷卯实验室:电源适配器 浪涌测试(视频)
海为C32S2R系列PLC在小区直饮水恒压供水控制水泵的设计方案
抢占显示技术新高点,中国印刷显示技术与世界同步
安森美半导体展示汽车CMOS图像传感器、激光雷达和雷达方案
洞悉工业无线遥控器市场前景—革新求变谋出路
智能会展迎宾机器人,可通过人脸识别来签到
变电站运维服务方案