2011年10月2日 星期日

DIY - PIC:PIC18F4550 雙極步進馬達 CW 轉動程式 (一百一十四):

DIY - PICPIC18F4550 雙極步進馬達 CW 轉動程式  (一百一十四)


PIC18F4550 雙極步進馬達 (Bipolar Stepper Motor) CW (Clock Wise, 順時針) 轉動程式,雙極步進馬達 CW (Clock Wise, 順時針) 轉動程式是開關 RA1RA4RA2RA3  (A -B -A B) 順序是為了配合雙極步進馬達電路線圈的連接。首先是 RA1 ON  (電流流入 A –A ) ,然後需要 RA1 OFF,跟著 RA4 ON  (電流流入 -B B ) RA4 OFF,再將 RA2 ON (電流流入 -A A ) RA2 OFF,最後是 RA3 ON (電流流入 B -B ) RA3 OFF,循環這個 RA ON OFF 的順序,雙極步進馬達便會順時針轉動。

Teac 雙極步進馬達CW 轉動
  PIC18F4550 雙極步進馬達CW (Clock Wise, 順時針) 轉動程式
void main(void)
{
    TRISA = 0b00000001;                         // Setup PORTA RA1 - RA7 as Output

    while(1)
    {
    LATAbits.LATA1 = 1;                         // RA0=1 LED=ON Scope=1 A+ White
    Delay10KTCYx(240);                          // 10,000 x 1 x (4 x 0.05us) = 2ms
                                                                          // Scope = 2ms
    LATAbits.LATA1 = 0;                        // RA1=0 LED=OFF Scope=50ms

    LATAbits.LATA4 = 1;                        // RA4=1 LED=ON Scope=1 B- Yellow
    Delay10KTCYx(240);                         // 10,000 x 1 x (4 x 0.05us) = 2ms
                                                                          // Scope = 2ms
    LATAbits.LATA4 = 0;                        // RA4=0 LED=OFF Scope=50ms

    LATAbits.LATA2 = 1;                        // RA2=1 LED=ON Scope=1 A- Red
    Delay10KTCYx(240);                         // 10,000 x 1 x (4 x 0.05us) = 2ms
                                                                          // Scope = 2ms
    LATAbits.LATA2 = 0;                        // RA2=0 LED=OFF Scope=50ms

    LATAbits.LATA3 = 1;                         // RA3=1 LED=ON Scope=1 B+ Blue
    Delay10KTCYx(240);                          // 10,000 x 1 x (4 x 0.05us) = 2ms
                                                                          // Scope = 2ms
    LATAbits.LATA3 = 0;                        // RA3=0 LED=OFF Scope=50ms

    }
}




Teac 雙極步進馬達CW 開始轉動
Teac 雙極步進馬達CW 開始轉動
2011   10 02 天氣報告 
氣溫:24.5 @ 22:00 
相對濕度:百分之80% 
天氣:微雨 
一號熱帶氣旋警告信號現正生效。

沒有留言:

張貼留言