Hown - Store e-shop | Products for tools hand rotary diy gear air materials drill bit hand tool hardware home garden electronics led car lights © Hown Store
seen from United Kingdom
seen from United States

seen from Germany
seen from India

seen from Italy

seen from Netherlands
seen from United States

seen from United States
seen from United States

seen from United States
seen from United Kingdom
seen from Germany

seen from United States
seen from United States
seen from Germany
seen from Netherlands
seen from United Arab Emirates

seen from Netherlands

seen from Malaysia

seen from United States
Hown - Store e-shop | Products for tools hand rotary diy gear air materials drill bit hand tool hardware home garden electronics led car lights © Hown Store
Owl Code Evolution V.02
Here's the Owl V.02: http://pastebin.com/YejZyZ3Z
There are QUITE a few new changes. First off, you'll notice that PubMain is a bit chubbier. I moved all of the ping information and the serial terminal access to the Main function. Instead of cog Servo, it's called GotoAngle.
And then we also have this global variable "Target". We set it to 0 first, and if Target = Angle, then we add 5 to target. Angle is another global variable that in the Compass module is set to aziadjust (value of compass reading in degrees). So if the target was the same value as the angle measured, then we'd increment the target by 5. So 0 - 5 - 10 - 15.
So here's the GotoAngle function. The main difference here is the lack of ramping but now the new incorporation of error terms. So essentially you see that 1520 was the stop pulse width for the rc servo this time around. And depending on the difference between the target, and actual angle, we'd send a different pulse width. So the larger the difference, the faster the servo would move, and the smaller the distance, the slower the servo would move.
So this section you can see the ping portion is removed, and we have Angle being set to aziadjust. It's pretty barebones to be honest. I also deleted the AziTerm portion of the code because we didn't need it!
@atdiy/@tymkrs
Parallax RC Servo Part III: My own code!
So! I kept most of the same stuff but corrected some of the portions that were confusing. Since I don't fully understand the CTRA region, I just kept it the same. @RoyEltham suggested I look at this link for more information: http://www.parallaxsemiconductor.com/sites/default/files/appnotes/AN001-P8X32ACounters-v2.0_2.pdf
What is the most different is that for tC, I multiplied it by 20_000 instead of 21_500 because the time between each pulse width is 20ms. This saves us later from having to adjust with 200ms here, there, etc.
So what the different repeat loops are doing is the following. First they are each repeating 100 times.
phsa := -tCw: (or -tCtr or -tCcw) is saying which direction you want this to go in and initiates the pulse.
t += tC: This means t = t + tC and essentially resets the variable t to be the current clock cycle (cnt) and the required space between pulse widths tC (20ms). So it deliberately gets the clock cycle after the pulse width goes through, and adds 20ms.
waitcnt (t): This means wait until the current clock cycle has gotten to equal t. Then the cycle repeats!
Looking at this code from a "bird's-eye view":
Set clock settings
Set counter settings
Set variables
RC Servo goes clockwise
RC Servo stops
RC Servo goes counter clockwise
RC Servo stops
You'll note that I had to use 1490 for tCtr (stopped servo) as opposed to 1500 per the information sheet for the servo. That's because when I used 1500, it seemed to go in the clockwise direction, though slower. So I just adjusted it slightly and now it actually stops with 1490! So that works.
@atdiy/@tymkrs
Parallax RC Servo Part II: Code Analysis 1/2
So this was the example code for the parallax rc servo given in the "datasheet", so I thought I'd go through it and try to expand on the comments the original coder wrote in. This servo is supposed to go clockwise full speed for 21 seconds, hold still 2 seconds, and then go counterclockwise full speed for 2 seconds.
clkmode = xtal1 + pll16x: This is where we set what the crystal is and how much more we want to multiply (pll) its frequency by, which in this case is 16.
_xinfreq = 5_000_000: This is where we say what the crystal frequency is, in this case 5MHz.
servoPin = 0: This is according to the comments, where you can designate which pin the servo's signal will go to. But is also essentially naming the number 0. This means it can be used to both represent a pin and a value, but it's like your Find and Replace function - it just finds where servoPin is and replaces it with the number 0.
PUB CenterServo | tInc, tc, tCtr, tCw, tCcw, t: I like to think of this as saying that this is the program called CenterServo and after the | symbol, they wrote out a number of local variables that only this program uses.
ctra[30..26] := %00100: So ctra is Counter A, and this is something that all cogs have one of. It seems to be setting certain pins as HIGH (1) or LOW (0). In this case, the counters of pins 30 - 26, pin 28 is HIGH. It seems that you put the number of the pin you want to work with in it.
ctra[8..0] := servoPin: Now if you substitute 0 for servoPin (since that's what servoPin is equal to), then pins 8 to 0 equal 0 (LOW).
frqa := 1: The frequency is set to 1 (no idea what for)
dira[servoPin]~~: This is setting pin 0 as an output. (servoPin just stands for 0)
Then the code sets the local variables.
tInc := clkfreq/1_000_000: Clkfreq stands for the number of clock cycles that represent one second, so by dividing it by a million, you end up with a 1 microsecond increment.
tC := tInc * 21_500: The comment says Low pulse. Between each pulse is 20ms, and though this says 21.5ms, I'll address why we have that extra 1.5 towards the end.
tCtr := tInc *1500: (tctr = time center) This takes the microsecond increment and multiplies it by 1.5 so that the pulse width can be 1.5ms, which if you remember, is the servo centered.
tCw := tInc *1300: (tcw = time clockwise) This takes the microsecond increment and multiplies it by 1.3 so that the pulse width can be 1.3ms, which if you remember, makes the servo goes clockwise.
tCcw := tInc *1700: (tccw = time counter-clockwise) This takes the microsecond increment and multiplies it by 1.7 so that the pulse width can be 1.7ms, which if you remember, makes the servo goes counter-clockwise.
t := cnt: And this one gets the current clock cycle
Onto what the code does next post!
@atdiy/@tymkrs
Parallax RC Servo Part I: PWM/Hookup Basics
So since we have the parallax RC servo, I thought I'd take a closer look at what is required to run it:
So unlike other RC servos, this is what is known as a continuous servo. There are different ranges of motion, for example 90 - 180 - 360 (continuous). The Parallax RC Servo is a continuous servo and runs off of 4-6V. Maximum RPM will vary with input voltage and 50 RPM @ 5 V is typical. Connections below:
And as mentioned previously, the direction of the motor is determined by the width of the pulses. In the Parallax continous servo, this is no different:
This is a centered servo. The space between pulses will always be 20ms, and the pulse width is 1.5ms to keep it centered. I believe there is pre-calibration to ensure that center is center as well.
So you notice again that the space between pulses is 20ms and the pulse width is 1.3ms - but essentially, the as the length of the pulse decreases from 1.5 ms, the servo will gradually rotate faster in the clockwise direction.
And on the flip side, as you increase the pulse width from 1.5, the servo will gradually rotate faster in the counter clockwise direction.
And next time - code analysis for a Spin example!
@atdiy/@tymkrs
RC Servo Basics
So I talked before about servos and what they are, but I decided I like spinning things anyway :)
So I suppose I will start with the RC servo, maybe take a look and see what the innards of the Parallax one actually does. So per this site, RC servos have:
DC electric motor Gears with an output shaft Positioning sensing mechanism Control circuitry
The controlling intelligence, in this case the operator of the model, indicates to the servo the position that the output shaft should have. The position-sensing mechanism tells the servo what position the shaft currently has. The control circuitry notes the difference between the desired position and the current position, and uses the motor to "make it so". If the difference in position is large, the motor moves rapidly to the correct position; if the difference is small, the adjustment is more subtle. As for the operator, all he knows is that he moved a slider half-way up, and the rudder on his model plane moved to the center position, and will stay there until he moves the slider again.
This is a lot like what JohnS_AZ had mentioned previously.
Inside the box is an electric motor which rotates the arm that sticks out the top. There is ALSO a small potentiometer that measures exactly where the arm is so when you hook it up, it can give that information to the MCU.
When you send a PWM signal to it, that signal represents where you want the arm to point. So a little circuit inside the servo compares your PWM signal to the measurement from the internal pot, and ends up with an error term. It then drives the motor one direction or the other to make the internal pot match your PWM signal.
And the article goes through different connections that different manufacturers use (in terms of color) and style, and for the most part, a colored line is the PWM signal, the white is power, and the black is ground.
It seems that when you do pulse width modulation, the width of the pulses sent control the position to take. So
pulse width angle comment 0.6m Sec -45 degrees minimum pulse length 1.5m Sec 0 degrees center position 2.4 mSec -45 degrees maximum pulse length
Another example - you notice the time for one pulse (on and off) is equal to other pulses, but the actual on portion of the pulse changes and that determines direction of the servo.
So it doesn't matter how fast these pulses are sent, only how wide they are.