PIC Lesson: Servo Motor

April 12th, 2010  Posted at   PIC Lesson
, arrow   |   46 Commentsarrow

Servo motor adalah alat electromechanical. Ia adalah sebuah motor yang mempunyai feedback loop. Oleh itu ia sebuah motor yang boleh dikawal posisi dan kelajuannya tanpa feedback kepada microcontroller. Servo motor hanya berputar dalam lingkungan sudutnya sahaja, contohnya hanya boleh berputar pada 1800.

Servo motor mempunyai tiga wayar. Kebiasaannya wayar merah adalah supply positif, wayar hitam adalah ground manakala wayar ketiga adalah signal daripada microcontroller. Wayar signal mempunyai beberapa standard warna iaitu warna putih, kuning atau oren.

Servo motor bergerak mengikut pulse signal. Signal ke servo adalah berbentuk PWM dengan frequency lebih kurang 50Hz iaitu masa bagi satu cycle adalah 20mS. Posisi armature servo motor bergantung pada duty cycle PWM tersebut. Dengan mengubah-ubah duty cycle, servo motor akan bergerak atau berputar. Dengan ini juga, kelajuannya boleh di kawal. Contoh signal untuk menggerakkan servo motor berputar mengikut arah jam atau mengikut arah lawan jam seperti diagram di bawah.

Walaubagaimanapun, untuk memprogram servo, tidak boleh menggunakan PWM Module dalam PIC kerana PWM yang diperlukan adalah frekuensi rendah. Oleh itu, PWM boleh dihasilkan menggunakan counter di dalam timer interrupt. Kemudian, hanya perlu menetapkan nilai posisi servo tersebut.

Berikut adalah skematik untuk menggerakkan servo mnggunakan input analog.

Berikut adalah contoh program PIC untuk menghasilkan signal di atas. Di dalam program ini, variable resistor digunakan untuk menetapkan posisi servo. Untuk mengubah kelajuan servo, hanya perlu menetapkan masa  untuk servo berada pada posisi tersebut.

Berikut adalah videonya.

Anda mungkin belum baca post ini

  • PIC Lesson: DC Motor
  • PIC Lesson: Brushless DC Motor
  • PIC Lesson: Servo Controller
  • PIC Lesson: Stepper Motor Driver
  • PIC Lesson: Stepper Motor

46 komen untuk PIC Lesson: Servo Motor

Pages: [5] 4 3 2 1 » Show All

  1. 46. Komen dari Lin pada 6:05 AM, 24th March 2012

    Im using a power supply that can supply 15A it should be more than enought ?

    I modify it into this and it worked.
    if (counter1 == position1) servo1=0;
    if (counter2 == position2) servo2=0;
    if (counter3 == position3) servo3=0;
    if (counter4 == position4) servo4=0;
    if (counter5 == position5) servo5=0;
    if (counter6 == position6) servo6=0;

    if (counter1 == 391){
    counter1=0;
    servo1=1;
    }
    if (counter2 == 391){
    counter2=0;
    servo2=1;
    }
    if (counter3 == 391){
    counter3=0;
    servo3=1;
    }
    if (counter4 == 391){
    counter4=0;
    servo4=1;
    }
    if (counter5 == 391){
    counter5=0;
    servo5=1;
    }
    if (counter6 == 391){
    counter6=0;
    servo6=1;
    }

    And i still dun understand what is the difference .

  2. 45. Komen dari Shahrul pada 8:02 PM, 23rd March 2012

    Lin, I don’t know why. Make sure your power supply to the servo can supply enough current. Sometimes servo drain power supply current and program not proper working.

  3. 44. Komen dari Lin pada 7:44 PM, 23rd March 2012

    Is this code able to control more then one servo ?
    I modify it into this.
    static void interrupt isr(void){
    if(TMR0IF = 1){
    TMR0IF = 0;
    counter++;
    if (counter == position1) servo1=0;
    if (counter == position2) servo2=0;
    if (counter == 391){
    counter=0;
    servo1=1;
    servo2=1;
    }
    }
    }

    But somehow servo1 will rotate clockwise nonstop till it hit the border.

  4. 43. Komen dari mtaufiq23 pada 7:09 PM, 7th March 2012

    ok…TQ saudara…

  5. 42. Komen dari Shahrul pada 5:44 PM, 7th March 2012

    mtaufiq23, contoh tersebut guna preescale 256. Tgk setting kat OPTION_REG.
    Contoh kat Servo Motor, preescale=1. 20MHz/(4x1x(256-0)x390) = 50Hz
    Contoh kat DC Motor, preescale=2. 20MHz/(4x2x(256-0)x4883) = 2Hz

  6. 41. Komen dari mtaufiq23 pada 10:50 AM, 7th March 2012

    ini comment saudara yg sy angkat dr page dc motor lesson saudara:

    frequency = Crystal_freq/(4x256xPreescalexCounter) = 20000000/(4x256x2x4883)=2Hz (T=0.5s)

    compare with this page:

    (20MHz/(4*256*390)=50Hz)

    there is another 256 here…klau sy tgk kat website http://www.microcontrollerboard.com/pic-timer0-tutorial.html ni rumus utk internal clock adalah seperti diatas dimana jika kita set tmr0=0…how? sy confuse sbb nampak mcm rumus untuk external clock cam tulis dlm website tu…

Pages: [5] 4 3 2 1 » Show All

Dah baca, tinggalkan komen anda disini