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

    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.

  2. #2
    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.

  3. #3
    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?

  4. #4
    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?

  5. #5
    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.

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


    Did you find this post helpful? Yes | No

    Default

    'Fraid you're waaaay over me now.

    I've downloaded the PBP demo version and the code in your first post works great. But the project calls for five seperate pulses on each pin of PORT A (running on a PIC16F84, BTW).
    Adding a few more lines to your original code just isn't working. Re:

    Pulse0 VAR WORD
    Pulse1 VAR WORD
    Pulse2 VAR WORD
    Pulse3 VAR WORD
    Pulse4 VAR WORD

    Main:

    PulsIn PORTA.0, 1, Pulse0
    PulsIn PORTA.1, 1, Pulse1
    PulsIn PORTA.2, 1, Pulse2
    PulsIn PORTA.3, 1, Pulse3
    PulsIn PORTA.4, 1, Pulse4

    PulsOut PORTB.0, Pulse0
    PulsOut PORTB.1, Pulse1
    PulsOut PORTB.2, Pulse2
    PulsOut PORTB.3, Pulse3
    PulsOut PORTB.4, Pulse4

    GoTo Main

    End

    Works fine with just one servo, but as soon as the extra code is added, nothing happens at all.

    Would you be interested in commiting yourself to help with this? You obviously have the wherewithal to do this stuff, but I wouldn't expect your help for free. Care to name your price?

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


    Did you find this post helpful? Yes | No

    Post Other solution ... always other solutions !!!

    Hi, Martin

    Do you know these tiny inverters are VERY simple to build with CMOS circuits ???

    TONS of circuit schemes are available on the web ...

    Note those gadgets also are available as ready to use devices from R/C manufacturers ... if you're ready to pay for.

    I can't believe you have to "invert" all the 5 channels at the same 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 " !!!
    *****************************************

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Look in the manual under 'DEFINE PULSIN_MAX'

    I get the feeling that your code is getting 'hung up' waiting for a pulsin, and it doesn't happen, or it's just not arriving when you want it to. Pulsin times out and returns 0 for a value.

    If you limit your pulsin to 3ms (DEFINE PULSIN_MAX 300 @ 4Mhz will limit pulsin to 3ms), the program might work like you want it to. But then you have to add some 'error checking' code. I.E., if the pulsin timed out, don't output the 'dead' value, re-output the old value, something along those lines.

Similar Threads

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