Hi Matt and other servo experts,
I have a vague idea for a project with (probably only 2) servos. Since I
have no experience with this hardware I want to make myself familiar
with it and the Jallib servo library. I have no real servo yet, but I
started with one of the samples, modified it for the PIC I plan to use
and for the (expected) minimum and maximum pulse durations.
I connected leds to the pins assigned as servo_1 and servo_2.
With a logic analyser I observed the following:
1. clkout pin has 2 MHz as expected and proves that my logic analyzer
has the correct timing
2. the pulse cycle is about 40 ms, while I expected 20 ms
3. time between start of pulses between subsequent servos: 4.5 ms
4. the pulse-widths are 0.57, 1.07 and 1.55 ms, while I expected 1, 1.5
and 2.0 ms
Then I made some variations: selected another timer and another
oscillator frequency. These gave me better and worse results (I may make
a table later), but never very close to the expected pulse widths and
cycle times. Servos may not be very critical w.r.t. the pulses, but I
wonder what the cause of these relatively large deviations could be.
Anyone done these experiments? If yes, what are your results??
I've attached the source of the variant which gives the above results.
I may try another PIC type later.
Regards, Rob.
-- R. Hamerling, NL
--
*Rob H*amerling - http://www.robh.nl
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/jallib.
For more options, visit https://groups.google.com/d/optout.
--
-----------------------------------------------------------------------------------
-- Title: Example of using the servo library with a 16f1718 and 2 servos
--
-- Author: Rob Hamerling, copyright (c) 2016, all rights reserved.
--
-- Adapted-by:
--
-- Compiler: 2.4q5
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the BSD license
(http://www.opensource.org/licenses/bsd-license.php)
--
-- Description: This library moves 2 servos as used in radio control (RC)
-- and also turns a led on and off after each movement.
--
-- Sources:
--
-- Notes:
--
--
-----------------------------------------------------------------------------------
include 16f1718 -- target PICmicro
pragma target clock 8_000_000 -- oscillator frequency
-- configuration memory settings (fuses)
pragma target OSC INTOSC_NOCLKOUT -- Internal oscillator
pragma target WDT DISABLED -- no watchdog
pragma target PWRTE ENABLED
pragma target MCLR EXTERNAL
pragma target BROWNOUT DISABLED
pragma target CLKOUTEN ENABLED -- clock out!
pragma target IESO DISABLED
pragma target FCMEN DISABLED
pragma target PPS1WAY DISABLED
pragma target ZCD OFF
pragma target PLLEN DISABLED -- PLL (maybe software controlled)
pragma target LVP DISABLED -- no Low Voltage Programming
OSCCON_IRCF = 0b1110 -- 8 MHz
OSCCON_SCS = 0b00 -- clock determined by fuses
OSCCON_SPLLEN = FALSE -- PLL disabled
enable_digital_io() -- disable analog I/O (if
-- LED IO definition
alias led is pin_a0
alias led_direction is pin_a0_direction
led_direction = output
-- setup servo pins
alias servo_1 is pin_B0
alias servo_1_direction is pin_B0_direction
servo_1_direction = output
alias servo_2 is pin_B1
alias servo_2_direction is pin_B1_direction
servo_2_direction = output
-- choose min & max servo movment / pulse size
const byte SERVO_MIN = 100 -- default is 100 (1.0 ms min pulse)
const byte SERVO_MAX = 200 -- default is 200 (2.0 ms max pulse)
const byte SERVO_USE_TIMER = 0 -- use PICs internal timer (0, 1 or 3)
include servo_rc_master -- include the servo library
servo_init() -- activate
-- example center all servo's
servo_move(127,1) -- select center position
servo_move(127,2)
-- use this to turn off a servo
;servo_1_on = False
-- example moving servos one and two and blink led
forever loop
servo_move(255,1) -- servo 1 right
servo_move(0,2) -- servo 2 left
_usec_delay (1_000_000)
led = !led
servo_move(127,1) -- servo 1 centered
servo_move(127,2) -- servo 2 centered
_usec_delay (1_000_000)
led = !led
servo_move(0,1) -- servo 1 left
servo_move(255,2) -- servo 2 right
_usec_delay (1_000_000)
led = !led
servo_move(127,1) -- servo 1 centered
servo_move(127,2) -- servo 2 centered
_usec_delay (1_000_000)
led = !led
end loop