Announcement

Collapse
No announcement yet.

Servos

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Servos

    I'm a bit new to servos. Right now I'm just testing a little code. I'm running a PIC16LF1823 at 8 Mhz with Xtal (define OSC 8). I get that a servo wants to see a certain size pulse but all the code I've looked at confuses me unless there's something about servos I simply don't know. And what that is is I can't see how (from the code I've looked at) to initialize the servos bearings, meaning the code I've seen says something like go to 'center' of rotation, or go right or left but I don't see how the servo knows where it is start point is. Unless all servos go to 'center' when shutting down which in some ways doesn't seem possible.

    The other thing I need to figure out is how to translate necessary pulse widths due to the fact that the 16LF1823's response for instance to a Pause commands is to make it 8 times longer than most other PICS (and also I'm running the PIC at 8Mhz.
    Any input is appreciated.

  • #2
    Keith55555, A normal NON Digital servo works on the difference in pulse width. Centered the servo should be getting approx. 1500 Microseconds of a high pulse. At approx. -90 degrees the servo is expecting about 1000 Microseconds. Then at +90 degrees the servo is expecting about 2000 Microseconds. The update time (period) should be approx. 20 Milliseconds (50 Hz.). With a period longer than this the servo will become unstable as it is trying to integrate the pulse width. There is a program I wrote some time ago which is able to operate 2 servos. I will see if I can find it and post it or, you can just search the forum as I believe it is posted here.
    Dave Purola,
    N8NTA
    EN82fn

    Comment


    • #3
      Thanks David. I'd really like to see that. The thing worrying me the most is the translation of the proper pulse width to my choice in PICs (16LF1823) because I'm not sure if the calls like 'pause' being 8 times normal delay effect the numbers I'll enter.
      Will it running at 8Mhz also have the need to recalculate pulse width timing?

      Comment


      • #4
        Keith, I don't understand the reference "because I'm not sure if the calls like 'pause' being 8 times normal delay effect the numbers I'll enter.". As long as you enter the statement "DEFINE OSC 8" at the start of the program, the "PAUSE" or "PAUSEUS" statements will automatically be scaled to the correct timing during the compile.
        '
        Dave Purola,
        N8NTA
        EN82fn

        Comment


        • #5
          Yeah, for some reason, and I found out the hard way, that if with this specific chip, if for instance I write : 'pause 500' the actual pause calculates to 4 seconds instead of .5 seconds. Something to do with the default on any reset being 500khz. I don't understand it but it is true (darryl explained this to me before he passed). The pause time would be scaled by the define for the oscillator but this timing exception would still be there.
          Now I don't know if I should incorporate this into calculating a 'pause' should I use that method for deriving the pulse width.

          Comment


          • #6
            So this is what I tried ignoring all my fears of the pause timing business (see attached). I copied this pretty much from someone and then altered the processor's particular needs.
            I turned it on and the servo moved to one side but didn't stop and kept wanting to go further. The I encountered the alert that "Target DeviceDoes Not matchSelected Device. But I don't think that has anything to do with having tried it for real. More likely my programming cable. I've had this happen before.

            Comment


            • #7
              Like I said Keith, You should use the PAUSEUS command instead of the PULSOUT command as it is adjusted for the "DEFINE OSC 8". It is accurate... Using the PULSEOUT command does not look at the "DEFINE OSC" settings but uses the main oscillator frequency. The code writer has to do the conversion. If you look at page 196 of the PBP3.0 manual it explains the situation with PULSOUT.
              Dave Purola,
              N8NTA
              EN82fn

              Comment


              • #8
                I went to micro-seconds (see attached). When I powered up the servo seemed to self-center. I don't know if this is a function of servos or not but that's what it looked like. Then again it went to one side and stayed on trying to go further where it was mechanically stopped. I then looked at the servos specs (also attached) and wondered if this has a specialized pulse width protocol (cycle is the same I see for others; 20ms) and could this be the problem. The servo is a Hitec HS-125MG.

                Comment


                • #9
                  given that the pbp default config for a 16lf1823 is

                  [CODE]#CONFIG
                  cfg1 = _FOSC_INTOSC
                  cfg1&= _WDTE_ON
                  cfg1&= _PWRTE_OFF
                  cfg1&= _MCLRE_ON
                  cfg1&= _CP_OFF
                  cfg1&= _CPD_OFF
                  cfg1&= _BOREN_ON
                  cfg1&= _CLKOUTEN_OFF
                  cfg1&= _IESO_ON
                  cfg1&= _FCMEN_ON
                  __CONFIG _CONFIG1, cfg1

                  cfg2 = _WRT_OFF
                  cfg2&= _PLLEN_OFF
                  cfg2&= _STVREN_ON
                  cfg2&= _BORV_19
                  cfg2&= _LVP_OFF
                  __CONFIG _CONFIG2, cfg2

                  #ENDCONFIG[/CODE

                  and your code has no config section then I very much doubt the chip has a fosc of 8mhz . you are aware of course that define OSC 8 does nothing but inform the compiler of what speed to base timing calculations on .
                  even if the chip was running at 8mhz [ pulseout porttx,y ,100 ] would yield a 500uS pulse . way out of spec for any standard servo , yours included [which has standard specs]

                  range is 900 to 2100 uS

                  and post your code in code tags not pictures to make getting assistance more likely





                  ]

                  Comment


                  • #10
                    Keith, 20000 Microseconds = 20 Milliseconds, NOT 2 Milliseconds. Your calculations are off by a factor of 10. It should be 2000 Microseconds.
                    Dave Purola,
                    N8NTA
                    EN82fn

                    Comment


                    • #11
                      Thanks for catching that David. Using that proper frame rate, indeed I get the back and forth motion symmetrically, however, it is certainly not the extent of the servos rotational angle. I have been playing with those numbers both for the extremes of the pulse width and frame rate but angle (maybe +/-20 degrees) remains close to the same. Also, I notice if I change the frame rate higher, motion slows down which was going to be my next question as to how one changes the speed of the rotation. I assume this has to do with pauses between the FOR/TO 'steps'.

                      Comment


                      • #12
                        DO NOT change the frame rate from 20 Ms. What is probably happening is the servo is loosing sync and having a hard time integrating the pulse width. As for the minimum and maximum pulse width's, That's in the spec. you made available. Now as for as the speed of the servo, that is also in the spec. and that will be the maximum speed it will travel. To slow it down, one would place a longer delay between each pulse width step or, make the step's smaller.
                        Dave Purola,
                        N8NTA
                        EN82fn

                        Comment


                        • #13
                          So I tried to simplify this by pretty much copying some posted code for a servo and went to a 4Mhz internal oscillator. What I expect to happen is for the servo horn to go from one extreme, wait a second and go to the other extreme. Instead, swings to one side and then has small back and forth movement near that extreme position pausing the 1 second.
                          Tried to link to dropbox video but not sure it is working properly since the link seems to just go to my general dropbox location. Can someone confirm if it brings you to the video? Thanks


                          OSCCON=%01101010
                          output porta.2
                          porta.2=0

                          ANSELA=0
                          ANSELC=0
                          CM1CON0=0
                          CM1CON1=0
                          b1 var byte

                          start:for b1=1 to 100
                          high porta.2
                          pauseus 1000
                          low porta.2
                          pauseus 19000
                          next b1
                          pause 1000
                          for b1=1 to 100
                          high porta.2
                          Pauseus 2000
                          low porta.2
                          pauseus 18000
                          pause 1000
                          next b1
                          goto start

                          Comment


                          • #14
                            Keith, the pause 1000 at the end of the first loop will loose sync with the servo. The first loop should take 20 Ms. x 100 or approx. 2 seconds that the servo will be at the minimum rotation. But then in the second loop after the 2000 Microsecond high pulse and the next 18000 microsecond low period you are waiting for 1 second before continuing the loop. The servo will loose sync by that time.

                            start:for b1=1 to 100
                            high porta.2
                            pauseus 1000
                            low porta.2
                            pauseus 19000
                            next b1
                            pause 1000 < loose this line or the servo will loose sync
                            for b1=1 to 100
                            high porta.2
                            Pauseus 2000
                            low porta.2
                            pauseus 18000
                            pause 1000 < loose this line or the servo will loose sync
                            next b1
                            goto start
                            Dave Purola,
                            N8NTA
                            EN82fn

                            Comment


                            • #15
                              Thanks David, that did it. Since you know I'm new to the servo,and it seems what your saying is that the servo always needs to keep sync via the 20ms pulse and I can't just have it reach a position and not be 'talking to it all the time, my next objective is to trigger an event (a sound happens). So that event has to be calculated within that 20ms minus the pulse width to the servo signal? Again, thanks for your patience; We're getting there.

                              Comment

                              Working...
                              X