Connect with us

please help controlling of a servo motor with 8051 ( incrementing its angle by 5 )

Discussion in 'Microcontrollers, Programming and IoT' started by anikdas, Jan 6, 2013.

Scroll to continue with content
  1. anikdas

    anikdas

    7
    0
    Jan 6, 2013
    hallo guys
    I want to control a servo motor with 8051 microcontroller and to increment its angle by 5 degree and when its reach then after its get to 180 degree it will agian decrement its angle by 5 degree and reach to zero ..
    in proteus simulation its not happenig and stucked to 90..

    i am attaching the proteus simulation where u can get the circuit that i am using and i am aslo attaching the keil zip file where u can get the c code

    please guys help me

    u can also double click on the servo motor in proteus and make its maximum degree to 180 ..then it will get stuck to 180 degree
    please anyone help me
     

    Attached Files:

  2. davenn

    davenn Moderator

    13,833
    1,950
    Sep 5, 2009
    PLEASE DONT multi post the same topic!!

    Dave
     
  3. anikdas

    anikdas

    7
    0
    Jan 6, 2013
    sorry i dont know that i will not do that again
     
  4. anikdas

    anikdas

    7
    0
    Jan 6, 2013
    plss some one help me out
     
  5. donkey

    donkey

    1,293
    56
    Feb 26, 2011
    ok just for me I thought I would let you know, I will never download zip files its just too risky.
    you can however go to the advanced text chat and paste code there for us to read. as for the other zip still not going to download it
     
  6. anikdas

    anikdas

    7
    0
    Jan 6, 2013
    // Program to rotate servo by 5 degree from previous position starting from 0 degree

    // 0 degree = 700us
    // 180 degree = 5500us
    // Timer1 pulse after 50us -23

    #include<reg51.h>
    sbit output=P1^0; //Output to motor
    int count;

    void delay(unsigned int msec) // Function for delay
    {
    int i,j;
    for(i=0;i<msec;i++)
    for(j=0;j<1275;j++);
    }

    void timer(int msec) // Function for timer
    {
    int i;
    TR1=1;
    for(i=0;i<msec;i++)
    {
    while(TF1==0);
    TF1=0;
    }
    TR1=0;
    }
    void main()
    {
    int i;
    TMOD=0x20; // Mode2
    TH1= -23; // 50usec timer
    output=0;
    count=14;
    while(1)
    {
    if(count>=100)
    count=14;
    else
    count=count+5;
    for(i=0;i<200;i++)
    {
    output=1;
    timer(count);
    output=0;
    timer(360);
    }
    delay(100);
    }
    }


    the code is like this
     
  7. anikdas

    anikdas

    7
    0
    Jan 6, 2013
    the circuit i am using is like this

    the circuit
     

    Attached Files:

  8. anikdas

    anikdas

    7
    0
    Jan 6, 2013
    please guys ne1 help me
     
  9. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,496
    2,837
    Jan 21, 2010
    Have you tested your code module by module? (for example do you know that your delay actually delays the correct amount?)

    Have you looked at the signal going to the servo when a fixed angle is selected to confirm that it has the correct mark/space ratio, amplitude, etc.?

    Please don't dump the whole thing in our lap with an "it doesn't work". Telling us what you've tested already would be extremely helpful (lest we simply waste time asking you to do it again).
     
  10. anikdas

    anikdas

    7
    0
    Jan 6, 2013
    no i havnot done that..i dont know how to do that,,, can u please tell me how toplease
     
  11. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,496
    2,837
    Jan 21, 2010
    Well, firstly, perhaps you can write a program using your delay routine to flash a LED 1 second on, 1 second off...

    If you do that, you'll be able to check with a watch that the timing is reasonably correct. If it stays in time over a minute, the error is less than 2%.

    Then you might choose to set it to 5 ms on/5 ms off and using your current circuit look at the output on an oscilloscope. Is the timing still correct? What does the waveform look like (is it a rail to rail square wave?)

    Now manually set the mark/space ration to whatever you expect will turn the servo to some predetermined angle. Does it work? Does the waveform still look correct when connected to the servo?

    Now change the program so it only outputs the waveform while the button is pressed.

    Keep going.

    The process is called stepwise refinement. You start with something simple that you can understand as a unit and is easily testable without having too many unknowns. You then refine the process to add features which get it closer and closer to your final solution, each time making an incremental change that can be tested and shown to work.

    It helps if you have a plan as to how your program will work, because this process can start with testing your low level routines, moving up a level each time you are confident that layer is working.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-