Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Issue with PulsePosition and RC input

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    10

    Issue with PulsePosition and RC input

    Hi all,

    I'm using a Teensy 3.5 and having trouble using the PulsePosition library to read a regular RC servo signal. Here's the deal.

    Using a simple pulseIN() code works ok, but of course is not ideal. Code as below:
    Code:
    char pin = 6;
    
    void setup() {
      Serial.begin(9600);
      while (!Serial);
      pinMode(pin, INPUT);
    }
    
    void loop() {
      Serial.println(pulseIn(pin, HIGH));
      delay(500);
    }
    Output:
    Code:
    1493
    1331
    990
    990
    990
    1233
    1754
    1949
    2015
    2014
    1949
    1380
    990
    990
    991
    990
    990
    990
    990
    990
    990
    990
    990
    The LoopBack example of PulsePosition also works ok if the two pins are connected toegther (10 to 6 in this case) as shown below(I changed the input pin to pin 6 in this case):
    Code:
    #include <PulsePosition.h>
    
    // Simple loopback test: create 1 output to transmit
    // test pulses, and 1 input to receive the pulses
    PulsePositionOutput myOut;
    PulsePositionInput myIn;
    
    void setup() {
      myOut.begin(10);  // connect pins 6 and 10 together...
      myIn.begin(6);
      myOut.write(1, 600.03);
      myOut.write(2, 1500);
      myOut.write(3, 759.24);
      // slots 4 and 5 will default to 1500 us
      myOut.write(6, 1234.56);
    }
    
    int count=0;
    
    void loop() {
      int i, num;
    
      // Every time new data arrives, simply print it
      // to the Arduino Serial Monitor.
      num = myIn.available();
      if (num > 0) {
        count = count + 1;
        Serial.print(count);
        Serial.print(" :  ");
        for (i=1; i <= num; i++) {
          float val = myIn.read(i);
          Serial.print(val);
          Serial.print("  ");
        }
        Serial.println();
      }
    }
    Output:
    Code:
    1 :  521.12  852.88  251.25  493.80  1450.07  345.50  410.95  
    2 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    3 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    4 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    5 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    6 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    7 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    8 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    9 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    10 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    11 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    12 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    13 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    14 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    15 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    16 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    17 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    18 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    19 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    20 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    21 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    22 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    23 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    24 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    25 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    26 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    27 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    28 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    29 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    30 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    31 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55  
    32 :  600.02  1500.00  759.23  1500.00  1500.00  1234.55
    However, the same code above will not detect any pulse if connected to a RC servo PWM generator. The generator has been tested with many different servos as well as with an Arduino and is working fine. I've tried connecting an RC receiver (verified working) and that does not trigger any signal as well.

    This leads me to think that the issue is in software and not hardware, as all hardware seems to be working normally.

    Can anyone offer any ideas as to why this behavior?
    Last edited by yconst; 06-21-2018 at 10:19 PM.

  2. #2
    Senior Member
    Join Date
    May 2017
    Posts
    241
    When I looked at this recently, I came to the conclusion that the pulse position library does not read and write the same type of signals that a RC servo responds to. The pulse position library is dealing with the signals that the RC receiver processes which is a waveform with say all 8 channels encoded. The RC receiver breaks that waveform up into individual signals that go to each servo.

    I am using CHANGE pin interrupts and the elapsed timers in my recent project to read servo signals like this:

    Code:
      elapsedMicros ele_time;
    
      attachInterrupt( ELE_PIN, ele_service, CHANGE );   this is in setup()
    
    void ele_service(){
       if( digitalReadFast(ELE_PIN) == HIGH ) ele_time = 0;
       else user_ele = ele_time;
    }

  3. #3
    Junior Member
    Join Date
    May 2018
    Posts
    10
    I have an RC receiver that can output PPM so I hooked it up to the input pin (pin 6), but to no good. The pin still reads nothing. As soon as I hook up the Teensy PPM generator from the example at pin 10, I get input.

    Also thanks for the example code, but my ultimate aim is to read PPM (multi-channel), so I guess I need the PulsePosition library. The PWM mentioned above is just a test to simplify things. I would expect it to appear as a single-channel PPM input.

    I'm starting to think that there may be timing constraints in the PulsePosition library settings that do not allow it to capture RC PPM signals.. Would be great to have an expert on the library chime in on this topic.

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,600
    In your second code from post #1, pin 6 is the output and pin 10 the input...

  5. #5
    Junior Member
    Join Date
    May 2018
    Posts
    10
    Oops sorry that's just in the code I posted because I changed the numbers while posting (editing now..)! To make sure it is not the case I also tried input on pin 9 but I still get the same result as described above.

  6. #6
    Senior Member
    Join Date
    May 2017
    Posts
    241
    With Theremingenieur's input, you should be reading the PPM signal now.


    >>> I would expect it to appear as a single-channel PPM input.
    That's what I was thinking when looking at using the pulse position library to read PWM. But the PPM signals are timed from rising edge to rising edge and not from rising edge to falling edge.

    Click image for larger version. 

Name:	opwm_ppm.gif 
Views:	110 
Size:	10.7 KB 
ID:	14061

  7. #7
    Junior Member
    Join Date
    May 2018
    Posts
    10
    Thanks for the input. I admit that using PWM in place of PPM was a bit far fetched.. however it still does not explain why the RC receiver PPM signal is not being picked up. I will try using interrupts for verification and let you guys know how it goes.

  8. #8
    Junior Member
    Join Date
    May 2018
    Posts
    10
    Solved! Adding
    Code:
    pinMode(pin, INPUT_PULLUP);
    to setup() allows the Teensy 3.5 to read the PPM signal from the RC receiver. It seems that the receiver output is inverted then?

    Anyway, thanks everyone for your input.

  9. #9
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,655
    Re: output is inverted

    you might configure for falling, PulsePositionInput myInput(FALLING);

    that's what I used with a Spektrum trainer cable, and you need a common ground between PPM cable and T3.5

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,087
    Quote Originally Posted by yconst View Post
    It seems that the receiver output is inverted then?
    Sounds like it was an "open collector" type signal.

  11. #11
    Junior Member
    Join Date
    May 2018
    Posts
    10
    Thanks manitou and Paul for your input. I managed to solve the issue as I mentioned in a previous post by adding

    Code:
    pinMode(pin, INPUT_PULLUP);
    to setup(). After adding this the PPM signal is picked up properly. I am not experienced enough in electronics to identify why the pullup bit is required. My guess was that the receiver output was inverted, but that's just a guess.

    Anyway, thank you all for the input and help.

  12. #12
    Paul, I'm having trouble with the Pulse Position Library as well. My signal has a 7 ms HIGH sync, followed by a 500uS LOW, then a 1000-2000uSec HIGH pulse - Chan 0), then another 500uS LOW, then Chan 1 HIGH, etc. I get channels 0-3 properly in the output RS-232 string, but all the other channels show 1500 like they aren't there. I need 8 channels.

    My goal is to output all 8 channels just as I receive them, but now and then change one or two outputs based on certain conditions, while leaving the other 6 or 7 channels the same as the inputs. I haven't gotten far enough to test if the outputs are in the right format yet.

    Can you tell me how I might get 8 channels of input?

Posting Permissions

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