How do you store 1 to 2ms servo pulses in a variable?


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    pulsewidth var word

    main:
    pulsin port-whatever-pin-whatever, 1, pulsewidth '1 if you pulse is active high
    pulsewidth = 2000 - pulsewidth
    pulsout port-whatever-pin-whatever, pulsewidth
    goto main

    Of course, this assumes that your max pulse width is 2ms, usually they go a tad bit farther than 2ms (2.5ms is max endpoint on one of my Futaba's). And the 2000 will also depend on how fast your oscillator runs.
    And this will (by default), run at the correct frequency, since the pulsin will only activate when you're servo gets a pulse. Then the program will output the 'inverted' pulse, then go back to the start and wait for the next pulse.

    3 other questions:
    What's a berk?
    What is it to be berky?
    What's a boffin, and how many of them does it take to screw in a light bulb?

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


    Did you find this post helpful? Yes | No

    Thumbs down Servo pulse inverting calculation ...

    Hi, Skimask

    I wonder it was a typo ...

    but inverting "formula" is :

    Inv.pulsewidth = ( 2*Neutral ) - pulsewidth

    so, in µS it's .... ( 2*1500 ) - pulsewidth

    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 " !!!
    *****************************************

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Skimask
    I wonder it was a typo ...
    but inverting "formula" is :
    Inv.pulsewidth = ( 2*Neutral ) - pulsewidth
    so, in µS it's .... ( 2*1500 ) - pulsewidth
    Alain
    I've been using my bit of 'pseudo-code' for awhile, works for me, but there's also a lot of assumptions (4mhz osc, 1500us perfect center, 2000 perfect endpoint, etc).
    I like your bit of code better and I'm going to change my ways of doing those.

  4. #4
    Join Date
    Jun 2007
    Location
    SW England
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    But my understanding is that PULSIN and PULSOUT only applies to PORT B.
    Is there a way that RC pulses can be read into PORT A?
    Can it indeed be done on the PIC16F84 with the PICBASIC compiler?

    Appreciate your time and help with this.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Martin Peters View Post
    But my understanding is that PULSIN and PULSOUT only applies to PORT B.
    Where'd you get that info?
    PulsIn/PulsOut doesn't have those restrictions.
    If the pin can be read, you can use PulsIn.
    If the pin can be written, you can use PulsOut.
    It's all in the PBP manual.

    And are you using PicBasic (PBC) or PicBasicPro (PBP)?
    And which version?

  6. #6
    Join Date
    Jun 2007
    Location
    SW England
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    That info. was gleaned from "PIC BASIC - An Introduction" (Neil Edwards & Jasper Roberts). Apologies, I thought I'd already stated the compiler is PICBASIC (PBC).
    The PULSIN / PULSOUT commands work fine with PORT B, but not with PORT A. I'm looking to store five R/C channels on each of the five Port A pins, before routing them to PORT B.
    From the above postings I've learnt how to get the needed servo reverse action (thanks), but how do you get the RC pulse on PORT A when PBC doesn't recognise PULSIN for that port?

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Well, we don't know for sure which PIC you're using (you hinted at the 16F84, but never really specified)...but...
    As far as PBC, yep, you sure did mention it... I missed it. My bad.
    And PBC is limited in that respect, Pin 0 - Pin 7, that's what you get. Maybe Pin 8 will get you PortA.0. I don't know, I don't use PBC.
    If you want my advice, get the upgrade to PBP. You'll be MUCH happier in the long run.

    Short of that, don't use the pulsin statement ('cause PBC won't let you).
    Write your own tight loop to mock pulsin.
    Wait for the pin to go high (or low)
    Sit in a tight loop counting the passes thru the loop while the pin is high (or low)
    Exit when the pin changes again.
    Take the loop count, multiply it by the # of us spent in each loop, and you've got your answer...

    OR...
    Use the pulsin on the PortB, and use a delay loop to send the 'pulsout' on PortA.

Similar Threads

  1. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 08:31
  2. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 14:35
  3. one line led light make image
    By bioul in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 13:19
  4. HSERIN doesn´t work
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2007, 15:23
  5. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21:36

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