2014年2月26日 星期三

74HCT595N工作原理

這是一顆計數暫存晶片

可以使用序列的方式傳入Q0~Q7的狀態(high or low)到內部register,然後輸出時chip依照register值去拉Q0~Q7的狀態

可以使用少數腳位一次控制Q0~Q7的狀態,此外由於此chip可以串接,所以可以一次控制更多腳位


下列圖來源: http://arduino.cc/en/uploads/Tutorial/595datasheet.pdf



74HCT595N腳位:

  • VCC:5V
  • GND
  • Ds: serial data in
  • Q0~Q7: 8根輸出pin
  • Q7': storage register對應到Q7的bit,最為多顆chip 串接用
  • MR: (active low) 清空shift register
  • OE: (active low) 
    • OE拉low,STcp raising時,將storage輸出至Q0~Q7 
    • OE拉high,Q0~Q7輸出為高阻抗(相當於沒接上這顆chip)
  • SHcp: raising edge trigger, 觸發shift register shift 1 bit(新的1bit資料由Ds取)
  • STcp: raising edge trigger


從文件可以知道,74HCT595N有兩個register(8bit):
  1. shift register - 序列資料輸入時使用
  2. storage register - 控制Q0~Q7輸出時為high or low

從文件可以知道,SHcp/STcp最高可運作在100Mhz(每個clock 10ns)

  • 由此可得知下面範例SHcp/STcp拉high/low時,每次delay只要5ns,不過由於Arduino delay最小只能用1 micro second,所以設定delayMicroseconds(1)即可


基本原理
  1. 透過序列的方式將資料傳入shift register
  2. 將shift register資料傳入storage register
    1. 每個SHcp raising edge,資料會一直輸入進去chip的shift register
      1. Q0'~Q7'代表shift register的值
      2. Serial date寫入方向:
        1. Ds > Q0' > Q1' > Q2' > Q3' > Q4' > Q5' > Q6' > Q7'
  3. 輸出到Q0~Q7
範例:
  1. 連接
    1. chip 接上VCC/GND
    2. micro controller gpio 接上Ds/MR/OE/SHcp/STcp
  2. 初始化:
    1. Ds/MR/OE/SHcp/STcp全部拉low
      1. 此時由於MR為low,shift register全部清為0
    2. STcp LOW->HIGH->LOW,將shift register的值寫入storage register
      1. 此時由於OE為LOW,storage register的值馬上會輸出至Q0~Q7
  3. 資料寫至shift register
    1. MR 拉HIGH
    2. 將Q7的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
    3. 將Q6的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
    4. 將Q5的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
    5. 將Q4的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
    6. 將Q3的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
    7. 將Q2的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
    8. 將Q1的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
    9. 將Q0的值設到Ds, SHcp LOW->HIGN->LOW將資料移入shift register
  4. 將資料從shift register移到storage register
    1. STcp LOW->HIGH->LOW
      1. 此時由於OE為LOW,storage register的值馬上會輸出至Q0~Q7


實做:

  • 使用MTADRL293D 電機驅動模組,其中
    • Ds: Arduino pin 8
    • MR: 固定拉high
    • OE: Arduino pin 7
    • SHcp: Arduino pin 4
    • STcp: Arduino pin 12

Arduino可使用我寫的library操作74HCT595N:



簡單控制74HCT595N的範例程式碼:
const int DS = 8;
const int OE = 7;
const int SHCP = 4;
const int STCP = 12;

void setup(){
  Serial.begin(115200);

  while (!Serial){
    ;
  }

  delay(1000);
  Serial.println("=== setup() ===");

  pinMode(DS, OUTPUT);
  pinMode(OE, OUTPUT);
  pinMode(SHCP, OUTPUT);
  pinMode(STCP, OUTPUT);

  digitalWrite(DS, LOW);
  digitalWrite(OE, HIGH); //Q0~Q7 維持高阻抗
  digitalWrite(SHCP, LOW);
  digitalWrite(STCP, LOW);
}

void loop(){
  Serial.println("=== loop() ===");
  delay(1000);

  //serial data input into serial register
  //Q0~Q7: 00001111
  Serial.println("##serial data input into serial register");
  digitalWrite(DS, HIGH);//Q7
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);
  digitalWrite(DS, HIGH);//Q6
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);
  digitalWrite(DS, HIGH);//Q5
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);
  digitalWrite(DS, HIGH);//Q4
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);
  digitalWrite(DS, LOW);//Q3
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);
  digitalWrite(DS, LOW);//Q2
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);
  digitalWrite(DS, LOW);//Q1
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);
  digitalWrite(DS, LOW);//Q0
  digitalWrite(SHCP, HIGH);
  delayMicroseconds(1);
  digitalWrite(SHCP, LOW);
  delayMicroseconds(1);

  delay(1000);

  //serial register -> storage register
  Serial.println("##serial register -> storage register");
  digitalWrite(STCP, HIGH);
  delay(10);
  digitalWrite(STCP, LOW);
  delay(10);

  delay(1000);

  //storage register -> Q0~Q7
  Serial.println("##storage register -> Q0~Q7");
  digitalWrite(OE, LOW);

  delay(1000);

  Serial.println("##finish");
  while(true){
    ;
  }
}






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


相關連結




待續

沒有留言:

張貼留言