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

Thread: Teensy 3.6 interrupts for RC Receiver

  1. #1
    Junior Member
    Join Date
    Feb 2018
    Posts
    12

    Teensy 3.6 interrupts for RC Receiver

    I am trying to configure a Teensy 3.6 to use with flysky FS-T6 for PPM. the receiver is powered from the 5v pin on an Arduino.

    I have tried using attachInterrupt, attachInterruptVector. I also tried using the PPM libraries and configuring interrupts through the registers. Also tried running the sketch on Windows and Linux laptops. The methods above have also been tried on multiple pins.

    All the results I am getting are not correct.
    below is the simplest routine I used to measure the pulses from the receiver.

    Code:
    unsigned long timer_Roll;
    uint16_t roll_Reciever_Pulse;
    
    void setup() {
      Serial.begin(9600);
      pinMode(24,INPUT);
      attachInterrupt(24,interrupt,CHANGE);
    }
    
    void loop() {
    
    }
    
    
    
    void interrupt(){
        if(digitalReadFast(24) == 1){         
          timer_Roll = micros();
        }
        else if(digitalReadFast(24) == 0){
          roll_Reciever_Pulse = micros() - timer_Roll;
          Serial.println(roll_Reciever_Pulse);
       }
    }
    All the data from the methods above look similar to the data attached. Could someone help me understand? is it something really obvious? I am really out of ideas...PulseLength.txt
    Last edited by MattTeensy; 02-15-2018 at 10:03 PM.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,591

  3. #3
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    I have tried it the data looks the same.
    I just wrote this to retest.

    Code:
    #include <PulsePosition.h>
    PulsePositionInput myInput(RISING);
    
    void setup() {
      Serial.begin(9600);
      myInput.begin(23);
    }
    
    void loop() {
      if(myInput.available() > 0){
        for(int i = 1; i <= myInput.available(); i++) {
        Serial.print(myInput.available());
        Serial.print(" ");
        Serial.println(myInput.read(i));
        }
      }
      delay(10);
    }
    Attached is the data
    Attached Files Attached Files
    Last edited by MattTeensy; 02-16-2018 at 06:42 AM.

  4. #4
    Maybe you should not put a "Serial.println" inside the interupt service routine (ISR should be quick).
    Instead try to put results in a array or so and print out later on.

    Also, I dont know how teensy in comparation to ardunio it handles. But you can try to change the pin number in "attachInterrupt(24,interrupt,CHANGE)" into "digitalPinToInterrupt(24)".

  5. #5
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    Serial.println takes roughly a microsecond to run on a teensy 3.6. Once the variable is set the pulses repeat at close to 50hz so there is almost 18000 microseconds free. Its more about getting better pulse data.
    I have tried using digitalPinToInterrupt the routine doesnt run if I dont attach the receiver to the pin with the first method above.

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,591
    Quote Originally Posted by MattTeensy View Post
    Code:
      if(myInput.available() > 0){
        for(int i = 1; i <= myInput.available(); i++) {
        Serial.print(myInput.available());
        Serial.print(" ");
        Serial.println(myInput.read(i));
        }
    Use myInput.available() only once per data set, like the example code:

    Code:
    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();
      }
    }
    Click File > Examples > PulsePosition > LoopBack

    Run the example with pins 9 and 10 connected. Then disconnect the pins and connect your PPM data to pin 10.

  7. #7
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    I did this during the writing of that example. I will try using the pulse position example instead. I set a variable

    Code:
    int j = myInput.available();
    and the for loop was limited by j.

    Code:
    for(int i = 1; i <= j; i++)
    The data was still no good. Thank you for the feedback its been really quick.

    Is there anything else I can try?

  8. #8
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,201
    Can you attach a photo of your wiring. Do you have a common ground? Are you getting the PPM from the trainer cable on the FS-T6 transmitter? What is the max voltage of the PPM signal? (T3.6 is NOT 5v tolerant)

    Do you have scope or logic analyzer with which to monitor the PPM signal?

    EDIT: Here is PulsePosition loopback example results for PPM signal from Spektrum Dx5E trainer cable, PulsePositionInput myIn(FALLING); and sticks in neutral position

    Code:
         2792 :  1425.02  1500.92  1500.73  1501.90  1600.92  1101.04
         2793 :  1424.77  1500.92  1501.15  1501.60  1601.04  1100.79
         2794 :  1424.90  1500.90  1501.17  1501.60  1601.04  1100.77
    Click image for larger version. 

Name:	spektrum.png 
Views:	41 
Size:	139.9 KB 
ID:	12945
    Last edited by manitou; 02-16-2018 at 04:56 PM.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,591
    Quote Originally Posted by MattTeensy View Post
    Is there anything else I can try?
    Sure, there are lots of things you can try. But the question is what sort of thing to try next...

    Since you got wrong results with the known-good PulsePosition example, I'd imagine more fiddling on the software side or with interrupts to be very unlikely to help.

    The 2 directions to take at this point are investigating whether your signal really is PPM encoded, and whether you've connecting it properly to Teensy. Both of these are best done with an oscilloscope or logic analyzer to actually see the waveform.

  10. #10
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    I have an Arduino which measures the pulses correctly, Similarly to the first method above. I don't have an oscilliscope. I will attach a photo of the wiring shortly.

    Would the 5v tolerance be an issue if its measuring such short pulses?

    I dont know how I would measure the voltage from the receiver. The receiver itself is 5v...

  11. #11
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    Unfortunately having tried to upload a photo it repeatedly says upload failed but its quite easy to just explain.

    Essentially I have the receiver powered by the Arduino with two cables, Ground and 5v. 1 wire connecting the receiver to the Teensy is what I have been using to measure the PPM.

    Given that the receiver could send pulses of 5v is it possible that the low value of the pulses could register as high by the Teensy?

  12. #12
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,201
    You may need to shrink your photo. forum has limit on file size.

    ? The RC receivers that i am familiar with have 3-pin group for each channel, and for the power/gnd connection. And the signal pin in the 3-pin group is doing PWM not PPM. PPM is coming in via the radio signal. PWM is used to drive each servo motor.

    The 5v signal may have damaged the T3.6

  13. #13
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    I did try changing the file size but will remember for next time.

    That is really useful to know. All the forums I read made me believe I was looking to read PPM signals but PWM seems obvious now.

    I dont think the teensy is damaged. Its been connected for roughly only 10 seconds when testing.

    What would be the simplest method converting the signals to 3.3v?

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,591
    Quote Originally Posted by MattTeensy View Post
    What would be the simplest method converting the signals to 3.3v?
    A resistor divider is the simplest way. But the resistors do place a slight load on the signal, so this only works if the signal output is "strong" enough to drive the resistors.

  15. #15
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,201
    as Paul notes the voltage divider
    Click image for larger version. 

Name:	resistive-logic-downshifter.png 
Views:	34 
Size:	19.9 KB 
ID:	12946

    I can't speak to the likelihood of damage from 5v servo PWM to T3.6 pin
    Last edited by manitou; 02-16-2018 at 06:51 PM.

  16. #16
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    I did think of using a voltage divider but is this a feasible solution for four channels?

    Is the strength of the signals proportional to the strength of the resistors? Could I use "too strong" resistors?

    I think I may be wrong about the teensy being broken. If i print digitalRead of the pin I was testing on without anything attached its reading 1...

    Is there a more effective and efficient way to lower signal voltage with a little research?

  17. #17
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,201
    adafruit and sparkfun have multi-port level shifters
    https://www.sparkfun.com/products/12009

  18. #18
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,201
    Quote Originally Posted by MattTeensy View Post

    I think I may be wrong about the teensy being broken. If i print digitalRead of the pin I was testing on without anything attached its reading 1...
    Hard to say what voltage is of "floating" input pin.
    A better test is to read pin (pinMode INPUT) in a loop() and then jumper GND to the pin, or jumper 3v3 to the pin. Remember for T3.6, no 5v testing!

  19. #19
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,591
    Quote Originally Posted by MattTeensy View Post
    I did think of using a voltage divider but is this a feasible solution for four channels?

    Is the strength of the signals proportional to the strength of the resistors? Could I use "too strong" resistors?
    This is really a question about the output capability of your "flysky FS-T6". Generally the higher value the resistors, the less they will load the FS-T6 output, but the weaker the signal they'll deliver to Teensy. I recommend at most 15K+10K resistors. While higher values might work, those will give a good signal that's still certain to work with Teensy.

    Since you're talking about 4 signals, it sounds like these are each a PWM signal containing 1 value which repeats every cycle?

    PPM signals contain up to 16 values, where all the values repeat on every cycle of the waveform. PWM=1, PPM=many. Important to know the difference!

  20. #20
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    its so easy when people tell you! you can spend days doing something that someone can fix in 1 hour.

    Having testing the floating pin by connecting to ground it doesn't actually look broken....

    Which is there best method to measure PWM waveform given that I have a voltage divider. I would really like to have to pulse length correct for just one channel at the moment. I am using 1k and 2k resistors (they are all I have for the ratio in hand).

  21. #21
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,201
    FYI, here is library for reading multiple PWM pins from RC receiver
    https://github.com/simondlevy/RXInterrupt

    And T3.2 and T3.5 are 5v tolerant.

  22. #22
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    Having added the voltage divider, and using the routine in the library above the data still doesn't look correct. below should be a photo of the wiring. the order I have the resistors in is signal wire from receiver - 1k resistor - signal to teensy - 2k resistor.

    Photo of wiring:
    Click image for larger version. 

Name:	20180216_234015.jpg 
Views:	37 
Size:	121.0 KB 
ID:	12947

    data is attached... Data.txt

    really appreciate any feedback.

  23. #23
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,201
    Me thinks you need a common ground since you have two separate power supplies. Run a jumper from ground on Arduino to ground on T3.6. (or at least I can't see common ground in photo)

  24. #24
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    worked straight away!!!

  25. #25
    Junior Member
    Join Date
    Feb 2018
    Posts
    12
    Do I really need a logic converter for the receiver signals. My thinking is that the effective voltage would be less which is why I was happy to test 5v on teensy. In the same way you can control LED brightness with PWM. Is that reasonable... I am relatively new to understanding hardware.

    Also why did sharing the common ground solve this problem?

Posting Permissions

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