PIC Lesson: Servo Motor

April 12th, 2010  Posted at   PIC Lesson
, arrow   |   57 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 videonya.

Anda mungkin belum baca post ini

57 komen untuk PIC Lesson: Servo Motor

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

  1. 20. Komen dari Goh pada 12:37 AM, 31st March 2011

    Thanks for your reply.
    However, from the OPTION register, I thought you are using internal clock which is 4MHz?

  2. 19. Komen dari Shahrul pada 2:14 AM, 30th March 2011

    Goh, value 390 for develop 50Hz servo signal. (20MHz/(4*256*390)=50Hz). Value 10 to 50 for develop duty cycle 0.5ms to 2.5ms out of 20ms. This is still can be try-and-error for increase or decrease from 50Hz and get other min and max position.

  3. 18. Komen dari Goh pada 12:13 AM, 30th March 2011

    Thanks Shahrul and Leong! It’s working fine now.
    However, two more questions. May I know why the max and min value are set to 10 and 50? I tried other values, they are causing some problem? How to derive the values?
    Besides, why
    if(counter==390){
    counter=0;
    SERVO=1;}
    Why 390? How to derive?
    Please help! Thanks a lot!

  4. 17. Komen dari Shahrul pada 12:54 PM, 21st March 2011

    Thanks Leong for help comment. When using servo motor, the power supply need high continuous current. The 9V battery not suitable, better use rechargeable LiPo battery or DC power supply.

  5. 16. Komen dari LEONG pada 12:31 PM, 21st March 2011

    GOH,
    I dunno u whether you are facing the same problem like me last time.What i facing last time, not matter what signal i give, it will turn to maximum and start to shaking. After several testing, i notice is because of the current i supply from dc power supply to the servo motor is no enough. If you are using dc power supply to test your servo motor,you can turn the current to maximum. Because when the servo motor turn, it need current to turn, if the current is no enough, it will not turn to the position you set and turn to the maximun.I think you no need worry that the current will burn your motor because when it turn, it only use the current it need to turn only. Hope it help you

  6. 15. Komen dari Goh pada 12:50 AM, 21st March 2011

    Shahrul, I understand that the code should be working. But my problem now is the servo rotate clockwise to maximum then stop and fix there whenever I connect it to the circuit regardless of the potential meter.
    May I know what errors that can cause to this problem? It is because I changed option and adgo?
    Thanks!

  7. 14. Komen dari Shahrul pada 10:00 PM, 19th March 2011

    Goh, only Timer0 is use. Timer1 and Timer2 off. ADCON1 set in the read_a2d() function.

  8. 13. Komen dari Goh pada 8:14 PM, 18th March 2011

    Hi,
    I tried the code, it is not working. The led is blinking and I can load the Hex file into pic. But the servo is not rotating. It is possible that there is some error with the code? As I see all the timers are turn off and prr is set to 225. As I know prr is related to timer2.
    Besides, why ADCON1=0b00000110. All AN is set to digital input as I thought AN0 is analog? Please help. Thx

  9. 12. Komen dari Shahrul pada 4:09 PM, 17th March 2011

    Goh, you click Start >> Search >> All Files.
    First search the ‘pic.h’ files. Then open it. Find the name include file of your pic example ‘pic1687x.h’
    Second search the ‘pic1687x.h’. Then open it. Find the declaration of the ADCON bit. You can see what the name it’s use.

  10. 11. Komen dari Goh pada 3:51 PM, 17th March 2011

    Hi, I tried to compile your code. It showed errors as below:
    undefined identifier “OPTION”
    undefined identifier “ADGO”
    Hence, I changed the OPTION to OPTION_REG. But I don’t know what I can modify for ADG0. Please help. Thx

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

Dah baca, tinggalkan komen anda disini

What is 3 + 14 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)