Shop OBEX P1 Docs P2 Docs Learn Events
RC Receiver pulse reader — Parallax Forums

RC Receiver pulse reader

J.A.B.J.A.B. Posts: 13
edited 2007-12-23 23:40 in Propeller 1
I got my first propeller about three weeks ago, and have just started getting to know the little fellow.
I did some searches for code/examples of connecting a standard r/c receiver and remote transmitter to the propeller, since this is a robust and cheap way to get long range user control on all sorts of projects. But while I found lots of examples for controlling servoes, I could not find any doing the reverse. (Reading servo pulses)
So I decided this would be a good little project to learn the propeller asm flavor (mostly x86 experience from before).

So far I have made a working object for reading up to 8 channels from a r/c receiver (can easily be modified to support more channels).
Bear in mind I have just started with the propeller and wrote this to give my self a crash course on it, so I am looking for constructive feedback/tricks and general speedups.

Comments

  • Paul_HPaul_H Posts: 85
    edited 2007-12-23 22:42
    Hello JAB,

    I'm glad someone else had the same concern as me, and is better at writing asm code ! I had a similar goal for my autopilot PNAV, (or Propeller Navigator) to passthrough my RC radio's control, or hand control over to the Prop.

    Heres a link to the earlier thread. http://forums.parallax.com/forums/default.aspx?f=25&m=231689
    I also have simple benchtest of the PNAV software at my website www.pnav.net

    Thanks for the input.
    Paul


    PS - I agree it is difficult to search the site. I started using the contributed Google toolbar search plugin, which you can can get at www.foxhollow.ca/propeller/ (or read the thread at http://forums.parallax.com/forums/default.aspx?f=25&m=209696&g=209786)
  • deSilvadeSilva Posts: 2,967
    edited 2007-12-23 23:40
    J.A.B.

    Just a few entertaining notes
    (1) I should have coded
    PUB getrc(_pin) : value
    '' Get receiver servo pulse width as normal r/c values (0..100) 
      value := (get(_pin)-1500)/5
    



    (2) I would have incorporated _pinmask as a parameter for start, not in a separate routine

    (3) I would have allocated "pinmask" BEFORE the 8 value vector

    (4) I would not use the constant "Mhz", line 19 is extremely uncritical and you can easily use CLKFREQ/1000_000

    But that is all just a matter of taste..


    (5) Line 66: This is a new fresh COG you are using. ALL I/Os are input, there is no need to ANDN the DIRA again smile.gif

    (6) I would have used some nicer names for d1 through d4 smile.gif

    (7) Your algoritm is quite transparent and understandable, so you should leave it as is! Pundits will quibble that it is not a decent loop... To fight them, here is a "decent loop" smile.gif ... even two..

    : POS    tjz  d3, #:NEG                          ' Skip if no POS edge changes
             MOV thePinStates, d3
             MOVD vecpatchA, #pe0
             MOV eightPorts, #8
    
    : posloop
             RCR thePinStates,  #1   WC
    : vecpatchA
    IF_C     MOV    0-0,   c1
             ADD    :vecpatchA,  plus1DestConstant
             DJNZ   eightPorts,  #: posloop
    
    .........
    
    : NEG    tjz   d2, #:loop                        ' Skip if no NEG edge changes
             MOV thePinStates, d2
             MOVS vecpatchB, #pe0
             mov   p1, par                           ' Get data pointer
             MOV eightPorts, #8
    
    : negloop
             RCR thePinStates,  #1   WC
             MOV    d4,   cl
    : vecpatchB
             SUB     d4,  0-0
    IF_C     wrlong d4, p1                           ' Store pulse width
             ADD    p1, #4
             ADD    :vecpatchB,  #1
             DJNZ   eightPorts,  #: negloop
    
    



    Edit: I think I now fixed all typos.... Just found that "colon lower case p" is also swallowed by the forum

    Post Edited (deSilva) : 12/24/2007 12:04:53 AM GMT
Sign In or Register to comment.