Log in

View Full Version : servo PWM sampling-what Fosc should I use?


3dude_2231
22-08-2007, 13:52
Hi.

my goal is to sample a servo pulse from an R/C receiver,
and I'm not sure what XTAL to use,
I mean, what is the minimum Fosc I should use?

if a 4MHz = 1MHz internal clock,
so with a 1:1 prescaler I should get 1 sample every 1 mS.
if I'm correct, a servo's pulse is between 0.9mS and 2.1 mS,
meaning I need something quicker, am I correct?

will a 20MHz XTAL be the answer?

thanks,
Ran.

Alan Anderson
22-08-2007, 14:51
if a 4MHz = 1MHz internal clock,
so with a 1:1 prescaler I should get 1 sample every 1 mS.
if I'm correct, a servo's pulse is between 0.9mS and 2.1 mS,
meaning I need something quicker, am I correct?

You've got the right idea, but the wrong numbers.

First correction: a standard hobby servo signal has a pulse width that varies from 1 to 2 milliseconds. If you want to measure that range with eight bits of precision, you'll need a resolution of 256 counts per millisecond.

Second correction: with the clock running at 1MHz, each cycle is one microsecond. That's almost four times as fast as the task requires. If the processor you're using can measure pulses using the raw clock speed, you'll be fine with a 4MHz crystal.

(If you're indeed using a different servo standard with only a 200 microsecond range from end to end, a 1MHz clock will still give you more than 7 bits of resolution.)

3dude_2231
22-08-2007, 15:11
thank you very much!

:)

EricVanWyk
22-08-2007, 16:20
Depending on what processor you are using, you might be able to convince the hardware to do it for you, rather than polling it. This will let you run it with a different sample frequency AND lets you do other stuff while you are waiting.

On the PIC, I think it is called the "Input Compare" or "Input Capture Compare".

In any case, you are right in assuming that the resolution you can get is directly related to your crystal frequency.

What processor are you using?

3dude_2231
22-08-2007, 16:41
I'm using the PIC 16f690,
using the capture mode, I'm able to get the pulse's width :)

but, Alan Anderson really solved the problem for me :D

thanks anyway :)

Qbranch
22-08-2007, 22:51
3dude__2231 .... what exaclty are you building anyways?! :confused:

</raging curiosity>

-q

3dude_2231
23-08-2007, 13:17
actually, nothing too fancy.
(still working on the schematics, as the plan changes everyday).

but the main idea is this:
I'm transmitting to an R/C receiver,
that receiver puts out PWM signals (X and Y axis).
one PIC16f690 reads the X axis data,
sending the motors reverse bits directly to the motor driver.
and the forward bits to the second PIC16f690, that reads the Y data,
and decides whether to send "1" and "0", 2 "1"s, or 2 "0"s.

that's it :)

</hoping to satisfy curiosity>

Ran.