PDA

View Full Version : Pulsin Math question



ruijc
- 2nd April 2008, 13:43
Hi all,

I'm looking to understand the math behind the pulsin command.

I have seen some examples and some posts here but also giving diferent maths.

The background objective is to try and measure the output signal of a Futaba RX.

I will be working with a 4Mhz pic, but here's my thoughts:

Resolutions
20Mhz - 2us
10Mhz - 4us
4Mhz - 10us

The pulses that will be measured will be:
pulse left = 1ms
pulse center = 1.5ms
pulse right = 2ms
( all in a 20ms period )

Now, I need to count these pulses and detect if it’s a 1ms,1.5ms or 2ms within the 20ms frame.

I will maybe have to use DEFINE PULSIN_MAX 2000 to limit pulsin to 20ms.
So far so good...

Searching the net i've seen an example code using a 4Mhz pic and was like this:
SERVOMAX CONST 165
PULSIN portd.0, 1, W0
IF W0 > SERVOMAX THEN
Portb.0 = 1
ENDIF
My interpretation of this code is that the pulsin return value of a 2ms pulse would be ~200.

Now, i've seen somewhere here a math like : ( For a pulse of 1.5ms and 10Mhz clock ) : 150*10/4=375 counts

Assuming that math for a pulse of 2ms and a 4Mhz clock would be : 200*4/10=80 counts

My doubt is :
Since the resolution for 4Mhz is 10us, the count for a 2ms pulse shouldn’t be, not 80, not 200 BUT 20 ?

Thanks

mister_e
- 2nd April 2008, 13:56
i would use a timer for that.. or capture module... but anyways... In your case, 2mSec should return 200

2msec/10uSec=200 right?

Acetronics2
- 2nd April 2008, 15:04
Hi, Rujic

Do not set PULSIN_MAX too close to the 20ms value ... Some RC sets use a 40Hz frame ... or even variable frame rates ! ( some coders work with a constant sync time ...)

Alain

ruijc
- 2nd April 2008, 15:04
Thanks Mister-e,

makes perfect sense ;)

Just curiosity... what does this formula mean then ?



( For a pulse of 1.5ms and 10Mhz clock ) : 150*10/4=375 counts


thanks

ruijc
- 2nd April 2008, 15:06
Thanks for the tip Acetronics ;)

What do you sugest ? What will it work better ( for a Futaba RX ) ?

.

mister_e
- 2nd April 2008, 15:07
10 to 4 Mhz conversion i guess...

Acetronics2
- 2nd April 2008, 15:23
Thanks for the tip Acetronics ;)

What do you sugest ? What will it work better ( for a Futaba RX ) ?

.

1) I always use 25ms for PULSIN_MAX ...( add the pulse duration and it's Ok for all ! )

2) Ah, Futaba RXs !!!

Some care has to be taken for Futaba and Sanwa, some of their receivers output a ~ 3.5v high level ...

So, They will work with a TTL input, but not with a Schmitt trigger input ( as PortB.0 in interrupt mode i.e ...) : it will work with a PULSIN PORTB.0 , but not ON INTERRUPT (i.e.) ... that can offer happy debugging times !!!

Alain

ruijc
- 2nd April 2008, 15:30
Thanks Mister-e ;)



... that can offer happy debugging times !!!

:)

Thanks Acetronics

To protect the hardware i was thinking of placing a 220 Ohms resistor between the RX and the Pic.

Hope it works :D

.

Acetronics2
- 2nd April 2008, 16:06
To protect the hardware i was thinking of placing a 220 Ohms resistor between the RX and the Pic.

.

From the Rx outputs , one might consider not to draw more than 1 mA in all circumstances ... so, 4.7k in series, and 100k for an input Pulldown are safe values. 47k in series do not introduce significant noise levels ( 470k then for Pulldown !!! )

Alain

ruijc
- 2nd April 2008, 16:15
Thanks for the tip Acetronics,

OK...( let's see if i understood ;) ) will use the 4K7 between RX and Pic and the 100K pulldown for the pic's input pin.

Thanks :)