推輓(Push-Pull) vs 開漏(Open-Drain)

作者:crifan (http://bbs.chinaunix.net)
郵箱:[email protected]

【Open-Drain與Push-Pull】
GPIO的功能,簡單說就是可以根據自己的需要去配置爲輸入或輸出。(General Purpose Input Output,簡稱爲GPIO或總線擴展器,利用工業標準I2C、SMBus™或SPI™接口簡化了I/O口的擴展。當微控制器或芯片組沒有足夠的I/O端口,或當系統需要採用遠端串行通信或控制時,GPIO產品能夠提供額外的控制和監視功能。)但是在配置GPIO管腳的時候,常會見到兩種模式:開漏(open-drain,漏極開路)和推輓(push-pull)。對此兩種模式,有何區別和聯繫,下面整理了一些資料,來詳細解釋一下:

【Push-Pull推輓輸出】

原理:

輸出的器件是指輸出腳內部集成有一對互補的MOSFET,當Q1導通、Q2截止時輸出高電平;而當Q1截止導通、Q2導通時輸出低電平。Push-Pull輸出,實際上內部是用了兩個晶體管(transistor),此處分別稱爲Top-Transistor和Bottom-Transistor。通過開關對應的晶體管,輸出對應的電平。Top-Transistor打開(Bottom-Transistor關閉),輸出爲高電平;Bottom-Transistor打開(Top-Transistor關閉),輸出低電平。Push-pull即能夠漏電流(sink current),又可以集電流(source current)。其也許有,也許沒有另外一個狀態:高阻抗(high impedance)狀態。除非Push-pull需要支持額外的高阻抗狀態,否則不需要額外的上拉電阻。

特點:在CMOS電路里面應該叫CMOS輸出更合適,因爲在CMOS裏面的push-pull輸出能力不可能做得雙極那麼大。輸出能力看IC內部輸出極N管P管的面積。push-pull是現在CMOS電路里面用得最多的輸出級設計方式。

優點:(1)可以吸電流,也可以貫電流;(2)和開漏輸出相比,push-pull的高低電平由IC的電源低定,不能簡單的做邏輯操作等。

缺點:一條總線上只能有一個push-pull輸出的器件;

【Open-Drain開漏輸出】

原理:

開漏電路就是指以MOSFET的漏極爲輸出的電路。指內部輸出和地之間有個N溝道的MOSFET(Q1),這些器件可以用於電平轉換的應用。輸出電壓由Vcc決定。Vcc可以大於輸入高電平電壓VCC (call UP-Translate)也可以低於輸入高電平電壓VCC(call Down-Translate)
Open-Drain輸出,則是比push-pull少了個top transistor,只有那個bottom transistor。(就像push-pull中的那樣)當bottom transistor關閉,則輸出爲高電平。此處沒法輸出高電平,想要輸出高電平,必須外部再接一個上拉電阻(pull-up resistor)。Open-drain只能夠漏電流(sink current),如果想要集電流(source current),則需要加一個上拉電阻。

優點:
(1)對於各種電壓節點間的電平轉換非常有用,可以用於各種電壓節點的Up-translate和Down-translate轉換
(2)可以將多個開漏輸出的Pin腳,連接到一條線上,形成“與邏輯”關係,即“線與”功能,任意一個變低後,開漏線上的邏輯就爲0了。這也是I2C,SMBus等總線判斷總線佔用狀態的原理。
(3)利用 外部電路的驅動能力,減少IC內部的驅動。當IC內部MOSFET導通時,驅動電流是從外部的VCC流經R pull-up ,MOSFET到GND。IC內部僅需很小的柵極驅動電流。

(4)可以利用改變上拉電源的電壓,改變傳輸電平,如圖, IC的邏輯電平由電源Vcc1決定,而輸出高電平則由Vcc2決定。這樣我們就可以用低電平邏輯控制輸出高電平邏輯了。

OD輸出電平的原理

缺點:開漏Pin不連接外部的上拉電阻,則只能輸出低電平。當輸出電平爲低時,N溝道三極管是導通的,這樣在Vcc'和GND之間有一個持續的電流流過上拉電阻R和三極管Q1。這會影響整個系統的功耗。採用較大值的上拉電阻可以減小電流。但是,但是大的阻值會使輸出信號的上升時間變慢。即上拉電阻R pull-up的阻值 決定了邏輯電平轉換的沿的速度。阻值越大,速度越低功耗越小。反之亦然。

==================================

常見的GPIO的模式可以配置爲open-drain或push-pull,具體實現上,常爲通過配置對應的寄存器的某些位來配置爲open-drain或是push-pull。當我們通過CPU去設置那些GPIO的配置寄存器的某位的時候,其GPIO硬件IC內部的實現是,會去打開或關閉對應的top transistor。相應地,如果設置爲了Open-D模式的話,是需要上拉電阻才能實現,也能夠輸出高電平的。因此,如果硬件內部(internal)本身包含了對應的上拉電阻的話,此時會去關閉或打開對應的上拉電阻。如果GPIO硬件IC內部沒有對應的上拉電阻的話,那麼你的硬件電路中,必須自己提供對應的外部(external)的上拉電阻。而push-pull輸出的優勢是速度快,因爲線路是以兩種方式驅動的。而帶了上拉電阻的線路,即使以最快的速度去提升電壓,最快也要一個常量的R×C的時間。其中R是電阻,C是寄生電容(parasitic capacitance),包括了pin腳的電容和板子的電容。但是,push-pull相對的缺點是往往需要消耗更多的電流,即功耗相對大。而open-drain所消耗的電流相對較小,由電阻R所限制,而R不能太小,因爲當輸出爲低電平的時候,需要sink更低的transistor,這意味着更高的功耗。而open-drain的好處之一是,允許你short多個open-drain的電路,共用一個上拉電阻,此種做法稱爲wired-OR連接,此時可以通過拉低任何一個IO的pin腳使得輸出爲低電平。爲了輸出高電平,則所有的都輸出高電平。此種邏輯,就是“線與”的功能,可以不需要額外的門電路來實現此部分邏輯。

"open drain push pull
The push-pull output actually uses two transistors. Each will be on to drive the output to the appropriate level: the top transistor will be on when the output has to be driven high and the bottom transistor will turn on when the output has to go low.

The open-drain output lacks the top transistor. When the output has to go high you simply turn off the bottom transistor, but the line is now pulled high only by the pullup resistor.

Your micro allows you to select between the two types, which means that by setting some bits in some register you actually enable/ disable the top transistor and enable/disable the pullup (if internal, otherwise you just disable the top transistor and have to use an external pullup)

The advantage of the push-pull output is the higher speed, because the line is driven both ways. With the pullup the line can only rise as fast as the RC time constant allows. The R is the pullup, the C is the parasitic capacitance, including the pin capacitance and the board capacitance.
The push-pull can typically source more current. With the open-drain the current is limited by the R and R cannot be made very small, because the lower transistor has to sink that current when the output is low; that means higher power consumption.

However, the open-drain allows you to cshort several outputs together, with a common pullup. This is called an wired-OR connection. Now you can drive the output low with any of the IO pins. To drive it high all ouputs have to be high. This is advantageous in some situations, because it eliminates the external gates that would otherwise be required."
===================================

【open-drain和push-pull的總結】
對於GPIO的模式的設置,在不考慮是否需要額外的上拉電阻的情況下,是設置爲open-drain還是push-pull,說到底,還是個權衡的問題:
如果你想要電平轉換速度快的話,那麼就選push-pull,但是缺點是功耗相對會大些。
如果你想要功耗低,且同時具有“線與”的功能,那麼就用open-drain的模式。(同時注意GPIO硬件模塊內部是否有上拉電阻,如果沒有,需要硬件電路上添加額外的上拉電阻)
正所謂,轉換速度與功耗,是魚與熊掌,二則不可兼得焉。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章