Pulsin Math question


Closed Thread
Results 1 to 10 of 10
  1. #1

    Default Pulsin Math question

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i would use a timer for that.. or capture module... but anyways... In your case, 2mSec should return 200

    2msec/10uSec=200 right?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Thanks for the tip Acetronics

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

    .

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    10 to 4 Mhz conversion i guess...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by ruijc View Post
    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8


    Did you find this post helpful? Yes | No

    Default

    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

    .

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ruijc View Post

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. Math question
    By vios in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd September 2007, 19:53
  2. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  3. pulsin question
    By schu4647 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 29th May 2006, 20:46
  4. PulsIn question.
    By Peter Oors in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th January 2006, 22:03
  5. Math question...
    By atomski in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th June 2004, 22:03

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts