Searching \ for '[PIC] Sample Servo Driver Code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/ios.htm?key=servo
Search entire site for: 'Sample Servo Driver Code'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Sample Servo Driver Code'
2011\09\08@180737 by Josh Koffman

face picon face
Hi all,

I'm having some trouble deciding on the best way to drive some hobby
R/C servos. It's been many years since I've dealt with them. As usual,
when I'm in this state I look around for sample code that might exist
on the web and see if it helps steer me. Problem here is that I'm
having some trouble locating it.

I'd love to find code that's for the 18F series as I think it'll be
more relevant to the available peripherals in the chip. Most of what
I'm finding is for 16F chips, and most include a large amount of code
dedicated to serial comms and complex command sets, neither of which
are important to me at the moment and are making the code harder to
understand. Then of course, I've found some lovely examples with zero
comments or explanations. Nice!

At the moment I'm working through Ashley Roll's code
(http://www.digitalnemesis.com/info/projects/picservo/) but if anyone
knows of anything out there for 18F that just simply drives a servo,
I'd love to see it!

Thanks,

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\08@182853 by Tamas Rudnai

face picon face
Hi Josh,

It is pretty easy to do, you just need to send a 1ms pulse for the lowest
position, 2ms for the highest, 1.5ms for the middle etc. You have to send
that pulse at every 20ms (you do not need to be very precise with this one,
it can be 15ms or 25ms, it will work, the only thing you need to be tight is
the pulse width) Almost like a PWM except the duty cycle is always in
between 1% - 2%... Pretty easy to do so.

There are loads of example, usually if you search for something like "servo
tester PIC 18F"... For example:

http://www.instructables.com/id/Use-a-PIC-Microcontroller-to-Control-a-Hobby-Servo/

The source is in C but it might give you some idea especially with reading
the description - and then I am pretty sure you will be able to do it by
yourself.

Good luck,
Tamas



On Thu, Sep 8, 2011 at 11:07 PM, Josh Koffman <spam_OUTjoshybearTakeThisOuTspamgmail.com> wrote:

{Quote hidden}

>

2011\09\08@182952 by Josh Koffman

face picon face
On Thu, Sep 8, 2011 at 6:07 PM, Josh Koffman <.....joshybearKILLspamspam@spam@gmail.com> wrote:
> At the moment I'm working through Ashley Roll's code
> (http://www.digitalnemesis.com/info/projects/picservo/) but if anyone
> knows of anything out there for 18F that just simply drives a servo,
> I'd love to see it!

Oops, forgot to mention I'm looking for assembly code. I've found a
bunch of C code, but that's not something I can do properly.

Thanks!

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\08@184312 by Bob Blick

face
flavicon
face
On Thursday, September 08, 2011 6:29 PM, "Josh Koffman"  wrote:

> Oops, forgot to mention I'm looking for assembly code. I've found a
> bunch of C code, but that's not something I can do properly.

I usually use a CCP peripheral in Compare mode to generate the pulse.
Use a general purpose timer to let you know when to repeat.

If you need to drive more than one servo you should hit them all
round-robin style, and you can use the same CCP output pin to do it as
an enable for diode/CMOS/TTL logic to "AND" it with a set of general
purpose output pins. Or you can use a 3-to-8 demultiplexer, etc.

But basically use the CCP compare output pin. Sorry I have only done it
in a 16F in C.

Cheerful regards,

Bob

-- http://www.fastmail.fm - IMAP accessible web-mail

2011\09\08@185419 by Michael Watterson

face picon face
Bob Blick wrote:
{Quote hidden}

You can compile it (all free) and see the Assembler it produces (with source and symbols) as well as the HEX.

2011\09\08@214321 by Josh Koffman

face picon face
On Thursday, September 8, 2011, Bob Blick <bobblickspamKILLspamftml.net> wrote:
> I usually use a CCP peripheral in Compare mode to generate the pulse.
> Use a general purpose timer to let you know when to repeat.
>
> If you need to drive more than one servo you should hit them all
> round-robin style, and you can use the same CCP output pin to do it as
> an enable for diode/CMOS/TTL logic to "AND" it with a set of general
> purpose output pins. Or you can use a 3-to-8 demultiplexer, etc.
>
> But basically use the CCP compare output pin. Sorry I have only done it
> in a 16F in C.

Hi Bob,

Let me make sure I understand the method you're talking about. You're
suggesting using a regular timer set to interrup roughly every 20mS.
At that point I'd set the output pin to positive. I'd also then read
my current desired servo position and use it to trigger the CCP module
in compare mode which when triggered would drop the pin back low. Does
that sound right?

Now on to my more specific questions.

If I'm doing this on a PIC running at 8MHz (internal osc) is there a
clever way to use the same timer peripheral for both the 20mS trigger
_and_ the CCP source that triggers the end of the pulse?

What do you have the CCP interrupt do? I could conceivably have it
automatically set the output pin low, but that limits which pins I can
use this routine on. Any reason why I can't use it in interrupt only
mode and trigger the pin state change in the ISR?

I'm not sure I entirely follow your multiple outputs ideas. I think
that what you're saying is that I should have the CCP trigger on the
differences, the use some other port outputs to trigger which servo
gets the signal. Are you suggesting that I use the same timer to start
the pulse for all servos or to alternate between servos. At 20mS
between each pulse per servo, I could easily squeeze in 8 separate
servos.

I hope my questions make sense!

Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\08@214552 by Josh Koffman

face picon face
On Thu, Sep 8, 2011 at 6:28 PM, Tamas Rudnai <.....tamas.rudnaiKILLspamspam.....gmail.com> wrote:
> It is pretty easy to do, you just need to send a 1ms pulse for the lowest
> position, 2ms for the highest, 1.5ms for the middle etc. You have to send
> that pulse at every 20ms (you do not need to be very precise with this one,
> it can be 15ms or 25ms, it will work, the only thing you need to be tight is
> the pulse width) Almost like a PWM except the duty cycle is always in
> between 1% - 2%... Pretty easy to do so.
>
> There are loads of example, usually if you search for something like "servo
> tester PIC 18F"... For example:
>
> http://www.instructables.com/id/Use-a-PIC-Microcontroller-to-Control-a-Hobby-Servo/
>
> The source is in C but it might give you some idea especially with reading
> the description - and then I am pretty sure you will be able to do it by
> yourself.

Hi Tamas,

I've spent a bunch of time searching but haven't found much that's
enlightening. My problem with projects like the one you linked to is
that because their only purpose is to drive the servo, they aren't
written to do much else, and they don't take advantage of the
peripherals present in the chip. I guess I'm being picky!

I am going to try just writing my own, hopefully it won't go too badly :)

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\08@214702 by Josh Koffman

face picon face
On Thu, Sep 8, 2011 at 6:53 PM, Michael Watterson <EraseMEmikespam_OUTspamTakeThisOuTradioway.org> wrote:
> There is also JAL servo library for 16F, 18F
> You can compile it (all free) and see the Assembler it produces (with
> source and symbols) as well as the HEX.

Hi Michael,

Thanks for the suggestion. I think I'll try writing my own but if I
run into trouble I might look at compiling the JAL library. I'd like
to avoid adding another layer of complexity on the project for now
though.

Thanks!

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\08@215459 by David Duffy (AVD)

flavicon
face
On 9/09/2011 11:45 AM, Josh Koffman wrote:
> I've spent a bunch of time searching but haven't found much that's
> enlightening. My problem with projects like the one you linked to is
> that because their only purpose is to drive the servo, they aren't
> written to do much else, and they don't take advantage of the
> peripherals present in the chip. I guess I'm being picky! I am going
> to try just writing my own, hopefully it won't go too badly :) Josh
Josh, the basic idea is:

Set up a free running 20ms timer on tmr0.

When tmr0 fires, set the first servo output high and set tmr1 to the pulse width you want for servo 1.

When tmr1 fires, turn servo output 1 off, turn servo 2 output on and set tmr1 to the pulse width you want for servo 2.

Repeat unitl all servos are serviced, then wait for the 20ms timer to fire again.

This round robin works for up to 8 servos as 8 x 2ms = 16ms so you can service them all within the 20ms.  The pulse positions move about somewhat within each 20ms event, but the servos don't seem to mind.
David...

-- ___________________________________________
David Duffy        Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717      Fax: +61 7 38234717
Our Web Site: http://www.audiovisualdevices.com.au
___________________________________________

2011\09\08@230427 by Josh Koffman

face picon face
On Thu, Sep 8, 2011 at 9:54 PM, David Duffy (AVD)
<davidspamspam_OUTaudiovisualdevices.com.au> wrote:
> Josh, the basic idea is:
>
> Set up a free running 20ms timer on tmr0.
>
> When tmr0 fires, set the first servo output high and set tmr1 to the
> pulse width you want for servo 1.
>
> When tmr1 fires, turn servo output 1 off, turn servo 2 output on and set
> tmr1 to the pulse width you want for servo 2.
>
> Repeat unitl all servos are serviced, then wait for the 20ms timer to
> fire again.
>
> This round robin works for up to 8 servos as 8 x 2ms = 16ms so you can
> service them all within the 20ms.  The pulse positions move about
> somewhat within each 20ms event, but the servos don't seem to mind.

Ok, that's what I figured. Is there a clever way to save a timer and
integrate it all into one? That's where I was headed with my comments
before. I don't know if this is possible, but could you have say TMR3
generating the 20mS interrupt, then use the CCP module on TMR3 to
generate the pulse width? I haven't had the time to do the math to see
if that would work, but I have no idea if it's even within the realm
of possibility.

Thanks!

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\08@231012 by David Duffy (AVD)

flavicon
face
On 9/09/2011 1:04 PM, Josh Koffman wrote:
{Quote hidden}

I guess you could subtract the sum of the 8 servo on-times from 20ms and use that for a 9th time period.
David...

-- ___________________________________________
David Duffy        Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717      Fax: +61 7 38234717
Our Web Site: http://www.audiovisualdevices.com.au
___________________________________________

2011\09\08@232703 by Josh Koffman

face picon face
On Thu, Sep 8, 2011 at 11:09 PM, David Duffy (AVD)
<KILLspamdavidKILLspamspamaudiovisualdevices.com.au> wrote:
>> Ok, that's what I figured. Is there a clever way to save a timer and
>> integrate it all into one? That's where I was headed with my comments
>> before. I don't know if this is possible, but could you have say TMR3
>> generating the 20mS interrupt, then use the CCP module on TMR3 to
>> generate the pulse width? I haven't had the time to do the math to see
>> if that would work, but I have no idea if it's even within the realm
>> of possibility.
>
> I guess you could subtract the sum of the 8 servo on-times from 20ms and
> use that for a 9th time period.

Sorry, I didn't mean for use as a 9th output. I plan to get a single
servo working, then expand if needed. I think I understand what you're
talking about, I was talking about saving timer peripherals in general
though.

Thanks!

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\08@233159 by David Duffy (AVD)

flavicon
face
On 9/09/2011 1:23 PM, Josh Koffman wrote:
> On Thu, Sep 8, 2011 at 11:09 PM, David Duffy (AVD)
> <RemoveMEdavidTakeThisOuTspamaudiovisualdevices.com.au>  wrote:
>>> Ok, that's what I figured. Is there a clever way to save a timer and
>>> integrate it all into one? That's where I was headed with my comments
>>> before. I don't know if this is possible, but could you have say TMR3
>>> generating the 20mS interrupt, then use the CCP module on TMR3 to
>>> generate the pulse width? I haven't had the time to do the math to see
>>> if that would work, but I have no idea if it's even within the realm
>>> of possibility.
>> I guess you could subtract the sum of the 8 servo on-times from 20ms and
>> use that for a 9th time period.
> Sorry, I didn't mean for use as a 9th output. I plan to get a single
> servo working, then expand if needed. I think I understand what you're
> talking about, I was talking about saving timer peripherals in general
> though.
>

I meant use the n+1 time to give you the overall 20ms cycle period using the same timer.
So the total time is S1 + S2 ... Sn + Gap Time, each timed sequentally.
David...

-- ___________________________________________
David Duffy        Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717      Fax: +61 7 38234717
Our Web Site: http://www.audiovisualdevices.com.au
___________________________________________

2011\09\08@235316 by Josh Koffman

face picon face
On Thu, Sep 8, 2011 at 11:31 PM, David Duffy (AVD)
<spamBeGonedavidspamBeGonespamaudiovisualdevices.com.au> wrote:
> I meant use the n+1 time to give you the overall 20ms cycle period using
> the same timer.
> So the total time is S1 + S2 ... Sn + Gap Time, each timed sequentally.

Oh, I gotcha. Interesting idea...

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\09@005352 by Josh Koffman

face picon face
Ok, I've been doing some math, and I'd love a double check of my thinking.

I'm working on an 18F1320, and I'm looking to use TMR2 and TMR3 for
servo stuff. The chip is running off the 8MHz internal oscillator.

To generate the 20mS trigger, I'm looking at TMR2. If I setup the
prescale at 1:16 and the postscale at 1:10, then I think I should be
able to load the period register (PR2) with d'250' and get a 50Hz
interrupt.

Once I've got that going (I won't be able to try it until tomorrow)
I'll be looking at TMR3 to generate the 1mS to 2mS variable pulse. If
I setup TMR3 in 16 bit mode, with a prescale of 1:8, I think I can get
an interrupt at 1mS if I preload the timer register with 65286, and an
interrupt at 2mS if I load with 65031. So I should be able to take my
control value (from whatever, analog pot, data in, etc), subtract it
from 65286, and away I go.

Does that sound plausible?

Thanks!

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\09@011913 by David Duffy (AVD)

flavicon
face
On 9/09/2011 2:53 PM, Josh Koffman wrote:
{Quote hidden}

That sounds pretty much what I did, but with timers 0 and 1.  I was using a PIC16F1934 running at 20MHz with DMX reception as well.
David...

-- ___________________________________________
David Duffy        Audio Visual Devices P/L
Unit 8, 10 Hook St, Capalaba 4157 Australia
Ph: +61 7 38235717      Fax: +61 7 38234717
Our Web Site: http://www.audiovisualdevices.com.au
___________________________________________

2011\09\09@013850 by IVP

face picon face
> 8MHz internal oscillator

Is the voltage and temperature drift OK for your app

2011\09\09@070422 by cdb

flavicon
face
::I've spent a bunch of time searching but haven't found much that's
::enlightening.

As you would like it to be in assembler, have a look at the code from 4 Square books or is that Square4 books. Nope got up off my chair Square1 books http://www.sq-1.com. You can download the book code, but it won't be commented in a normal fashion and is deliberately obfuscated to entice you to purchase the books to go with the code.

The code is complete, just refers to purple-prune and include brown-sauce files.

Colin
--
cdb, TakeThisOuTcolinEraseMEspamspam_OUTbtech-online.co.uk on 9/09/2011
Web presence: http://www.btech-online.co.uk   Hosted by:  http://www.justhost.com.au
 This email is to be considered private if addressed to a named  individual or HR department, and public if addressed to a blog,  forum or news article.

2011\09\09@073650 by Tamas Rudnai

face picon face
On Fri, Sep 9, 2011 at 2:45 AM, Josh Koffman <RemoveMEjoshybearspamTakeThisOuTgmail.com> wrote:

> Hi Tamas,
>
> I've spent a bunch of time searching but haven't found much that's
> enlightening. My problem with projects like the one you linked to is
> that because their only purpose is to drive the servo, they aren't
> written to do much else, and they don't take advantage of the
> peripherals present in the chip. I guess I'm being picky!
>

Hi Josh,

If you need only 1 servo to drive then you have pretty much like 18ms to do
something else, then 1ms from the time you put the signal high, and only
from then you need to worry about the length of the signal. The only thing
is that you need to be very precise with the width of the pulse otherwise
the servo will shaking and make noise, consuming more power etc.

If you have a timer interrupt you are better off, or with the CCP/PWM
module. With a free running PWM is the only problem is that you have 1%-2%
duty cycle all the time, therefore if you have a 10 bit PWM, you will then
have an 1024 resolution for the entire 20ms period, therefore you will have
a 10.24 (~10 steps) resolution for the entire servo movement, which is way
too low.

So what you would need is a PWM set up to 2-2.5 ms periods and to make sure
it will fire only once at every 20ms (or just it puts output to low when end
of duty cycle if you have that kind of functionality on the silicon). You
can also do this by by software using a timer interrupt, but things are
getting tricky when you need to work with more than one servo at a time.
Also you have to make sure no other interrupts will occur otherwise will
affect your timings (for example you are serving another interrupt while
timer fires, so it will causing you an unwanted delay till timer ISR been
served, which then affects the pulse width). The most easy is when you
handle one servo at a time and then switch to the next servo one by one. You
can handle 8-10 servos like this to fit each to the 20ms period. Most
analogue radio system works like this. And once you use 18F you use high
priority for the timer and low for other stuff so you will have no problem
serving those.

Tamas



>
> I am going to try just writing my own, hopefully it won't go too badly :)
>
> Josh
> --
> A common mistake that people make when trying to design something
> completely foolproof is to underestimate the ingenuity of complete
> fools.
>         -Douglas Adams
>
>

2011\09\09@120711 by Bob Blick

face
flavicon
face
On Thursday, September 08, 2011 9:43 PM, "Josh Koffman"  wrote:
{Quote hidden}

Yes, exactly.


> If I'm doing this on a PIC running at 8MHz (internal osc) is there a
> clever way to use the same timer peripheral for both the 20mS trigger
> _and_ the CCP source that triggers the end of the pulse?

Sure, just use TMR1 in freerunning mode, and enable interrupts for it.
You won't neccessarily be setting your servo pin each time, maybe every
other time or every fourth time, it depends what repetition rate you use
and how many servos you are driving.
> What do you have the CCP interrupt do? I could conceivably have it
> automatically set the output pin low, but that limits which pins I can
> use this routine on. Any reason why I can't use it in interrupt only
> mode and trigger the pin state change in the ISR?

You don't use the CCP interrupt, don't enable it. Use the peripheral in
Compare mode and have it set the pin low after the pulse width you
set(must be calculated based on TMR1, you can stop TMR1 while you do the
the addition).


> I'm not sure I entirely follow your multiple outputs ideas. I think
> that what you're saying is that I should have the CCP trigger on the
> differences, the use some other port outputs to trigger which servo
> gets the signal. Are you suggesting that I use the same timer to start
> the pulse for all servos or to alternate between servos. At 20mS
> between each pulse per servo, I could easily squeeze in 8 separate
> servos.

Let's say you want to drive 8 servos and you can use all of PORTB to do
it, and that CCP1 output is on RC2. And let's also use a two-input AND
gate for each servo. One input for each AND gate goes to RC2, and the
other inputs each get one of PORTB's pins. Start with all PORTB low.

Timer interrupt happens, you clear PORTB. Pause TMR1. Add your servo
pulse value for servo #0 and TMR1 value together and put in CCPR1. Do
what it takes to set RC2 high and enable CCP1 to clear it without
glitching. Set RB0 to enable servo #0 and unpause TMR1. Return from
interrupt.

The next time the interrupt happens, do the same thing for servo #1 and
RB1. Cycle through until all servos have been serviced.

So you get exact cycle times regardless of servo positions, the servos
are updated round-robin so your power supply is happiest, you get the
precision of .5 uS for your servo pulses.

I have done it in the past with only three PORTB pins and the CCP
output. Instead of eight AND gates you use a 3 line to 8 line decoder
like the 74HC138. Unfortunately the output is inverted so you need a
stack of inverters.

Instead of using AND gates you can use a resistor and diode per pin, but
it's uncool unless you are desperate, and it loads the CCP output really
hard.

Cheerful regards,

Bob

-- http://www.fastmail.fm - Access all of your messages and folders
                         wherever you are

2011\09\09@123434 by Bob Blick

face
flavicon
face
On Friday, September 09, 2011 9:07 AM, "Bob Blick" wrote:

> Instead of using AND gates you can use a resistor and diode per pin, but
> it's uncool unless you are desperate, and it loads the CCP output really
> hard.

I forgot to say that if you only drive one servo, you drive it directly
off CCP output, no other pins or parts are needed.

Bob

-- http://www.fastmail.fm - A no graphics, no pop-ups email service

2011\09\09@132524 by Isaac Marino Bavaresco

flavicon
face
The OP could also do the following:

Using a single timer, in the main loop set it for the first servo pulse
width and set the corresponding pin high.
When the timer interrupt occurs, inside the ISR clear the first servo
pin, set the next servo pin to one and program this servo's pulse width,
and so on for the remaining servos. Turn off the pin of servo 'n', turn
on the pin of servo 'n+1' and set the timer to interrupt after the pulse
width of servo 'n+1'.
After the last servo is served set the timer to interrupt after the
remaining time to complete the 20ms frame, and then start over, but this
time the first servo pin is set by the ISR.


Most servos work correctly with a pulse repetition rate less than 50
times per second, so it may be possible to have more than 10 servos, as
the usual maximum pulse width for a servo is 2ms.


Isaac


Em 9/9/2011 13:07, Bob Blick escreveu:
{Quote hidden}

>

2011\09\09@140616 by Bob Blick

face
flavicon
face
On Friday, September 09, 2011 2:25 PM, "Isaac Marino Bavaresco"  wrote:
> The OP could also do the following:
>
> Using a single timer, in the main loop set it for the first servo pulse
> width and set the corresponding pin high.
> When the timer interrupt occurs, inside the ISR clear the first servo
> pin, set the next servo pin to one and program this servo's pulse width,
> and so on for the remaining servos. Turn off the pin of servo 'n', turn
> on the pin of servo 'n+1' and set the timer to interrupt after the pulse
> width of servo 'n+1'.
> After the last servo is served set the timer to interrupt after the
> remaining time to complete the 20ms frame, and then start over, but this
> time the first servo pin is set by the ISR.

Won't you get some jitter this way?

When I use CCP Compare for the pulse, and freerunning a timer interrupt
for the repeat, it is very stable.

Friendly regards,

Bob

-- http://www.fastmail.fm - The professional email service

2011\09\09@143553 by Isaac Marino Bavaresco

flavicon
face
Em 9/9/2011 15:06, Bob Blick escreveu:
{Quote hidden}

Yes, some. But standard servos aren't that precise, and a few
micro-seconds of jitter perhaps will not show on the output. Old R/C
transmitters (analog AM ones and even some analog FM ones) had lots of
jitter and everything worked OK.

Newer no-brand china servos show a "ladder" response curve, they turn in
"steps" (we could call them digital servos :D ) after a certain amount
of change in the signal.


If the OP never disables the interrupts and he codes very carefully, he
can reduce the jitter to one or two clock cycles, which would be
imperceptible.


Isaac

2011\09\09@154141 by Kerry Wentworth

flavicon
face
Bob Blick wrote:
>
> I have done it in the past with only three PORTB pins and the CCP
> output. Instead of eight AND gates you use a 3 line to 8 line decoder
> like the 74HC138. Unfortunately the output is inverted so you need a
> stack of inverters.
>
> Instead of using AND gates you can use a resistor and diode per pin, but
> it's uncool unless you are desperate, and it loads the CCP output really
> hard.
>
> Cheerful regards,
>
> Bob
Or use a 74HC238, which is the same as a 74HC138 except the outputs are non-inverted.

Kerry

2011\09\09@171536 by Isaac Marino Bavaresco

flavicon
face
Em 9/9/2011 16:40, Kerry Wentworth escreveu:
> Bob Blick wrote:
>> I have done it in the past with only three PORTB pins and the CCP
>> output. Instead of eight AND gates you use a 3 line to 8 line decoder
>> like the 74HC138. Unfortunately the output is inverted so you need a
>> stack of inverters.
>>
>> Instead of using AND gates you can use a resistor and diode per pin, but
>> it's uncool unless you are desperate, and it loads the CCP output really
>> hard.
>>
>> Cheerful regards,
>>
>> Bob
> Or use a 74HC238, which is the same as a 74HC138 except the outputs are
> non-inverted.
>
> Kerry


Or use a Johnson counter like the 4017 to make a ring counter with just
one output at '1'. You would need just one I/O pin for the clock of the
counter (perhaps one more to reset it in the case of a loss of
synchronization, or better one input to monitor the "rest" output to
know when the "1" is at it).
Leave one output of the counter unused to be the "rest" place for the
bit "1".


Isaac

2011\09\09@235042 by Josh Koffman

face picon face
On Fri, Sep 9, 2011 at 7:04 AM, cdb <colinEraseMEspam.....btech-online.co.uk> wrote:
> As you would like it to be in assembler, have a look at the code from 4
> Square books or is that Square4 books. Nope got up off my chair Square1
> books http://www.sq-1.com. You can download the book code, but it won't be
> commented in a normal fashion and is deliberately obfuscated to entice you
> to purchase the books to go with the code.
>
> The code is complete, just refers to purple-prune and include brown-sauce
> files.

Ah...I have a bunch of David's books...but they're currently in
storage. Out of curiosity, which book does he talk about servos in? He
was nice enough to sell me some of his books that had been damaged at
a discount back when I was still a student.

Thanks!

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\09@235151 by Josh Koffman

face picon face
On Fri, Sep 9, 2011 at 1:38 AM, IVP <EraseMEjoecolquittspamclear.net.nz> wrote:
>> 8MHz internal oscillator
>
> Is the voltage and temperature drift OK for your app ?

In this case, yes. This particular app is to add a bit of movement to
a decoration, so nothing critical. I will be switching to a more
stable clock if I try to add serial comms as well.

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

2011\09\10@000204 by Josh Koffman

face picon face
On Fri, Sep 9, 2011 at 12:07 PM, Bob Blick <RemoveMEbobblickEraseMEspamEraseMEftml.net> wrote:
{Quote hidden}

Ah, an excellent explanation, thank you Bob. One question though. Once
you've done the servo #0, what triggers the start of servo #1? My
first though would be to have the CCP interrupt as well as having it
clear the pin. Then the pin would get cleared with no jitter, and
you'd end up in the ISR soon after to service the next servo.

Today I wrote some code and got the servo working using two timers,
one generating the 20mS period and the other turning off the output at
the appointed time. Worked ok, but I got a bit of jitter. So I decided
to try using the CCP, still clocked off a separate timer. I did
realize that on my current test board I don't have access to the CCP
pin, so I'll have to wait for my boards to come in to try actually
using the automatic pin clearing. I figured I'd try using the CCP as a
trigger to clear the pin in the ISR though. Didn't work. After quite a
while of going over and over what I'd done, I had a look at the errata
for the chip I'm using (18F1320). Turns out that the way the datasheet
says to set T3CON to indicate that TMR3 clocks the CCP module is a
reserved state and doesn't work. Nice. Fixed that and it works. Still
some jitter, which is understandable.

Next up I will try to move it all to one timer, just like Bob describes.

Thanks!

Josh
-- A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
        -Douglas Adams

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...