Menu

fixed frame update and driving FrSky DJT module directly with Trinket Pro 5V

Bugs
Doug LaRue
2015-11-03
2015-11-07
  • Doug LaRue

    Doug LaRue - 2015-11-03

    I'm using the PPMOut example and have added the updateTimings() method as updateTimingsFF() so I can switch back and forth. Of cource the new method was added to the PPMOut.h file. What I'm getting looks like no pause period is being set. I've looked on an Oscope. But when I throw some debug into the channel read section of loop() that must delay enough because then my FrSky receiver at least gets jittering data.

    I also added this update I saw you mention in another thread:

    //DJL #define PPMOUT_WORK_SIZE(channels) ((channels) + (((channels) + 1) * 4)))
    to #define PPMOUT_WORK_SIZE(channels) ((channels) + (((channels) +1) * 2) * sizeof(uint16_t))
    

    Here's my TestPPMOut.ino example( using Adafruit Trinket Pro 5v ):

    /* ---------------------------------------------------------------------------
    ** This software is in the public domain, furnished "as is", without technical
    ** support, and with no warranty, express or implied, as to its usefulness for
    ** any purpose.
    **
    ** ppmout_example.pde
    ** Demonstrate Pulse Position Modulation Output functionality
    **
    ** Author: Daniel van den Ouden
    ** Project: ArduinoRCLib
    ** Website: http://sourceforge.net/p/arduinorclib/
    ** -------------------------------------------------------------------------*/
    
    //NOTE: weird formating while posting, this line is not in the code: include <PPMOut.h>
    #include <PPMOut.h>
    #include <Timer1.h>
    
    #define DEBUG     // enable FTDI port output for debugging, disable serial write of JSIG data
    #ifdef DEBUG
     #define DEBUG_PRINT(x)  Serial.print (x)
     #define DEBUG_PRINTLN(x)  Serial.println (x)
    #else
     #define DEBUG_PRINT(x)
     #define DEBUG_PRINTLN(x)
    #endif
    
    #define CHANNELS 2
    
    uint8_t  g_pins[CHANNELS] = {A0, A1};//, A1, A1};//, A1, A1, A1, A1}; // Input pins
    uint16_t g_input[CHANNELS];                   // Input buffer in microseconds
    uint8_t  g_work[PPMOUT_WORK_SIZE(CHANNELS)];  // we need to have a work buffer for the PPMOut class
    
    // PPMOut requires two buffers:
    //     Input buffer containing input samples in microseconds
    //     Work buffer of ((channels + 1) * 2) elements for internal calculations and frame buffering
    // This setup removes any limit on the number of channels you want, and makes sure the library doesn't use more
    // memory than it really needs, since the client code supplies the buffers.
    rc::PPMOut g_PPMOut(CHANNELS, g_input, g_work, CHANNELS);
    
    void setup()
    {
        // Initialize timer1, this is required for all features that use Timer1
        // (PPMIn/PPMOut/ServoIn/ServoOut)
        rc::Timer1::init(); // use (true) for debugging(ie slows everything down;
    
        for (uint8_t i = 0;  i < CHANNELS; ++i)
        {
            // set up input pins
            pinMode(g_pins[i], INPUT);
    
            // fill input buffer, convert raw values to microseconds
            g_input[i] = 1500; //DJL map(analogRead(g_pins[i]), 0, 1024, 1000, 2000);
        }
    
        // initialize PPMOut with some settings
        g_PPMOut.setPulseLength(448); //448);   // pulse length in microseconds
        g_PPMOut.setPauseLength(10448); //10448); // length of pause after last channel in microseconds
        // note: this is also called the end of frame, or start of frame, and is usually around 10ms
    
        // start PPMOut, use pin 9 (pins 9 and 10 are preferred)
        //g_PPMOut.start(9);
            g_PPMOut.start(9,true); // inverts the PPM signal
    
            #ifdef DEBUG
            Serial.begin(19200);
            DEBUG_PRINTLN("Start DEBUG");
            #endif        
    }
    
    void loop()
    {
        // update the input buffer
        for (uint8_t i = 0;  i < CHANNELS; ++i)
        {
            // fill input buffer, convert raw values to microseconds
            g_input[i] = map(analogRead(g_pins[i]), 0, 1024, 1000, 2000);
                    if( i==0 ){
                    DEBUG_PRINTLN(""); DEBUG_PRINT("mapped AnalogRead="); DEBUG_PRINT(g_input[i]);
                    }
                    else{
                      DEBUG_PRINT(":"); DEBUG_PRINT(g_input[i]);
                    }
        }
    
        // tell PPMOut there are new values available in the input buffer
        g_PPMOut.update();
    }
    

    PPMOut.cpp added method:

    // fixed frame...
    void PPMOut::updateTimingsFF()
    {
        uint16_t* scratch = m_timings;
        uint16_t pause = m_pauseLength;
        // copy all pre-calculated timings
        for (uint8_t i = 0; i < m_channelCount; ++i)
        {
            // set pulse length
            *scratch = m_pulseLength;
            ++scratch;
            // set timing
            *scratch = m_channelTimings[i] - m_pulseLength;
            pause -= m_channelTimings[i];
            ++scratch;
        }
        // set final pulse length
        *scratch = m_pulseLength;
        ++scratch;
        // set pause length
        *scratch = pause - m_pulseLength;
        // update number of timings
        m_timingCount = (m_channelCount + 1) * 2;
    }
    
     

    Last edit: Doug LaRue 2015-11-04
    • Doug LaRue

      Doug LaRue - 2015-11-07

      I grabbed v.04 and it worked with the output inverted using the default timing in the example.

       

Anonymous
Anonymous

Add attachments
Cancel