PBP code to read R/C signal from receiver


+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    malc-c's Avatar
    malc-c Guest

    Default PBP code to read R/C signal from receiver

    Guys,

    Have tried searching the net and this forum, but nothing comes up, and as I'm a bit rusty on PBP, I'm after some pointers as to how to read the PPM signal from a normal RC receiver (1 -2ms repeated every 20ms).

    I've got some ASM code that already does this, but really want to learn and develope PBP a little more. One search did turn up something on RC groups, but Alain has removed the source code

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

    Wink So simple a question, the answer could be ...RTF...

    Hi, Malc

    What are you looking for exactly ???

    The basic reading is simply achieved only with a PULSIN Command ....

    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

    Default

    Short example:

    Code:
    '-------------------------------------------------------------------------------
    '-------------------------------------------------------------------------------
    
    @ DEVICE PIC12F683, MCLR_OFF
    @ DEVICE PIC12F683, INTRC_OSC_NOCLKOUT
    @ DEVICE PIC12F683, WDT_OFF
    @ DEVICE PIC12F683, BOD_ON
    @ DEVICE PIC12F683, PWRT_ON
    
    '-------------------------------------------------------------------------------
    
    OSCCON  = %01110000    ' Internal 4MHz osc
    ADCON0 = 0             ' A/D off
    CMCON0 = 7             ' Comparators off
    ANSEL = 0	           ' Set all digital
    WPU = 0                ' Internal pull-ups = off
    OPTION_REG = %10000000 ' Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
    GPIO = %00000000       ' All outputs = 0 on boot
    TRISIO = %00001000     ' GPIO.3 input, GPIO.0,2,3,4,5 output
    
    '-------------------------------------------------------------------------------
    
    signal VAR GPIO.3
    pulse  VAR BYTE
    
    '-------------------------------------------------------------------------------
    
    main:
           PulsIn signal, 1, pulse ' reads signal from receiver
    
           IF (pulse >= 148) AND (pulse <= 152) Then
              Low GPIO.0 ' turns LED off
           Else
                High GPIO.0 ' turns LED on
           EndIF
    
           GoTo main
    
    '-------------------------------------------------------------------------------
    
    End
    
    '-------------------------------------------------------------------------------
    '-------------------------------------------------------------------------------

  4. #4
    malc-c's Avatar
    malc-c Guest

    Default thanks

    Thanks for the code example. I'll hook up a receiver to my Easypic5 board and have a play... I'll also have a read of the online manual

  5. #5
    malc-c's Avatar
    malc-c Guest

    Default

    Dan,

    I've tried the following with a 12F675 and whilst it compiles and loads OK it doesn't do anything

    Code:
     @ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
    
     __CONFIG
     _INTRC_OSC_NOCLKOUT
     _WDT_ON
     _PWRTE_ON
     _MCLRE_OFF
     _BODEN_ON
    
    OPTION_REG = %10000000 ' Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
    GPIO = %00000000       ' All outputs = 0 on boot
    TRISIO = %00001000     ' GPIO.3 input, GPIO.0,2,3,4,5 output
    ANSEL = 0	           ' Set all digital
    WPU = 0                ' Internal pull-ups = off
    '-------------------------------------------------------------------------------
    
    signal VAR GPIO.3
    pulse  VAR BYTE
    
    '-------------------------------------------------------------------------------
    
    main:
           PulsIn signal, 1, pulse ' reads signal from receiver
    
           IF (pulse >= 148) AND (pulse <= 152) Then
              Low GPIO.0 ' turns LED off
           Else
                High GPIO.0 ' turns LED on
           EndIF
    
           GoTo main
    
    '-------------------------------------------------------------------------------
    
    End
    GPIO.0 is high all the time. GPIO.3 glows faint on the Easypic and brightens when the switch on the TX is activated indicating the PPM signals are being received on GPIO.3

    I've also loaded some hex generated from assembly that works so the connections are sound. Any ideas ???

  6. #6
    malc-c's Avatar
    malc-c Guest

    Default

    Edit:

    This seems to work

    Code:
    main:
           PulsIn signal, 1, pulse ' reads signal from receiver
    
           IF (pulse >= 100) AND (pulse <= 160) Then
              Low GPIO.0 ' turns LED off
           Else
                High GPIO.0 ' turns LED on
           EndIF
    
           GoTo main
    seems the range between >= and <= was the issue

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

    Wink

    There was no issue, Malc

    Led OFF for Neutral , ON for everything else.

    a bit surprising, but ... it is !

    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
    malc-c's Avatar
    malc-c Guest

    Default

    No issue, just the the original range didn't work. Once I changed the values between the <= and >= then it worked !

  9. #9

    Default

    I'm glad the code worked for you... Wish there were more threads about R/Cs electronics... I own 25 R/C trucks from Traxxas and now a heli clone of the Trex500 and many of them have PICs turning on/off lights, flashers, blilnkers, neons, sirens, and a few more things... PICs are great for R/C projects!!!

  10. #10
    malc-c's Avatar
    malc-c Guest

    Default

    Dan, have to agree with you. It would be nice to see some more RC related PIC / PBP stuff.

    Maybe we could start a thread and request the mods to sticky it in the code examples section ????

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 10:02
  2. R/C receiver to PIC16F84
    By tech in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 12th September 2008, 17:45
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  4. Timer PIC16F57
    By leonel in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 1st July 2005, 09:14
  5. can someone post example to code a bootloader using pbp?
    By nimonia in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th May 2005, 17:28

Posting Permissions

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