Shop OBEX P1 Docs P2 Docs Learn Events
Pulse Position Modulation to analog voltage — Parallax Forums

Pulse Position Modulation to analog voltage

Hand LaunchHand Launch Posts: 6
edited 2011-10-31 18:02 in BASIC Stamp
My problem arises out of controls when trying to mix analog and digital signals. There is a specific instance where I must convert digital input to analog output. I don't know if the Stamp 2e I bought is the right direction, but simple analog circuits alone don't seem to be getting me there so the Stamp seems like it may be the next higher level of flexible solution as further explained within this post.

The digital input signal is a Pulse Position Modulated format, which differs from Pulse Width Modulation in that the full 100% range of the encoded variable takes only a fraction of the repeating frame, where as in PWM the 100% range of encoding is the entire 100% of the frame. So in PPM, regardless of what % of the variable is encoded (0% to 100%) there is still both digital high (+5v) and digital low (GND) portions of signal within the frame. This is problematic for a simple analog circuit since pure averaging won't yield a 2.5 v center or a 0-to-5v DC output, as further described...

I'm trying to read a PPM signal w/ a 760 micro-second center and convert it to a 0-to-5V analog voltage output w/ a 2.50 volt center corresponding to the 760 micro-sec center of the input. I've tried to filter out the AC of the PPM using various resistor-capacitor circuits, getting a variable DC between about 1.5 and 2.6 volts centered near 1.9v, a good start for the quick-n-cheap analog circuits. There are problems w/ this approach, mainly my output range is constricted and off-center compared to my desired result.

So now I'm contemplating gaiting the frame by some duration using some externally adjustable means, as required to extract just the encoded variable portion, then counting the period of the +5v portion and the period of the 0 volt portion, comparing the two values (subtraction? division?), adding the difference/result to 2.5 and then outputting the value as an analog voltage. The PPM has about 1024 step resolution (?), and I'd like to keep the output signal at least that res. Dividing one by the other and multiplying the result by 2.5 may also get me there.

The externally variable gait would also serve as a trim or balance in case there were some (uncommanded) drift of the signal value away from center for whatever the reason such as environmental, etc.

A similar avenue of solution is no doubt possible w/ a couple of simple and cheap components such as counter and gate(s) feeding more simple (pure) PWM into some sort of analog circuit(s) to average, bias and scale if/as required. I would, however, like the hardware portion of the solution to be off the shelf w/ no more recurring labor than plugging chips into sockets, to be industrially tolerant/durable, and to be tailorable to minor or even major future variances in the format of the PPM signal (i.e. different vendors). This way the majority of the labor to solve the problem will be in the form of a software (one time) solution.

My measurements are using a Fluke 73 multimeter and a venerable TekTronix analog scope, model 561 B circa 1969 (bow down!). The old Tek scope is about to give up the ghost, so I have a fancy new Tek dual domain portable unit coming for a test drive. It may be overkill but the fancy new Tek is free for a week, which should get me pretty far in this round of my ongoing efforts. Having any kind of scope is a HUGE benefit to this sort of effort.

I'm guessing this is a relatively common requirement and may have been solved many times before, but searching these forums gave no such indication. It could be that this it is not so in-demand to go from digital to analog vs. the other way around, but both of these signal types are so common I was expecting to find previous cases. It could also be that folks who already figured it out have never disclosed their means.

I humbly appreciate all comments and look forward to the diverse knowledge and experience base represented here!

-HL

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-10-27 15:26
    Hand Launch,

    Welcome to the forum! Could I make one small suggestion? I think you would attract more help for your query if you broke it up into shorter paragraphs. As it is, it's a very difficult-to-scan monolith of words.

    Thanks,
    -Phil
  • Hand LaunchHand Launch Posts: 6
    edited 2011-10-27 15:34
    Thanks Phil - too true!{return}
    got it

    -HL
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-27 15:58
    The problem you get with PPM is that, unless there's some kind of sync pulse or external clock, you have no idea what the pulse position is in relation to. PWM works because there's a reference (the end of the frame). So, the question for you is "where is there a 'start of frame' or 'end of frame' reference?" Without a reference, you have no idea what you're measuring.
  • Hand LaunchHand Launch Posts: 6
    edited 2011-10-27 17:02
    Right Mike,

    That is why I'm thinking external control of the gaiting would be useful to set the analog output voltage to 2.5 v neutral reference when the digital waveform is known to be at center position. In my case the digital wave is a sum of a MEMS angular acceleration x-ducer output and a user input PPM signal at a lower (~50 Hz?) refresh rate. Those two signals are combined within the MEMS box and output as this higher freq PPM animal.

    So if the device/system is stationary and no control input is being given, the gaiting could be adjusted manually to yield 2.5 v at the output. This would work for a fixed gate "length" as long as that fixed length was somewhere in the neighborhood of the variable portion of the PPM frame .and. not any longer than that frame, a range of value(s) that should be relatively easy to make a first guess at using a scope.

    Its conceivable that a portion of code could be written and activated by a 'trim' button to automatically set gate duration and start point (relative to overall waveform) for a 2.50 v centered output. Likewise this technique could also allow for exercising the user control input to both endpoints (i.e. if ctrl input is held for say 1/2 second at each endpoint) so that the scaling may be calibrated in addition to the centering without any need of potentiometer & associated reliability issues. Setting a trim to small constant offsets from 2.50 volts may also be useful to the end user in this application, so a digital trim w/ one button for each direction and a third for centering may be a good solution.

    Another point to mention is that the scope trace of this PPM MEMS output shows only one single repeating 'square-ish' wave, no extra bit transitions, so that's a bonus in terms of simplicity of sync. When the variable inputs are varied (MEMS rotated or user input deflected) to either end of their full ranges, the scope shows the square-ish (or rectangular or whatever you want to call it) wave always has some of both high and low logical state left in it - the wave never collapses to all high or all low. This is why, according to all available references I'm able to find, I call it PPM by definition, not PWM. It is single channel or an encoding of a single variable, so good news for sync efforts.

    I could just try triggering on one state transition and if that doesn't work, try the other. Or count the entire wave form and the middle transition, then do math based on the results.

    One more thing is that when I measure on the old Tek scope I always get a negative voltage relative to GND no matter which way I select trigger, so I'm assuming the device works on inverted logic, no biggie but still important to maintain proper sense of whatever solution is attempted. I'm grounding my probe (the Parallax bargain probes I bought to get the Tek scope up and running) on the ground of these devices so I know its properly grounded. Same result on whatever ground I clip to within the test cell. I think the Tek is so old it largely predates many common digital design practices, not that I would ever down-talk such an amazing measurement tool. (bow down some more!)

    This is fun because I'm sure there must be many routes to a solution, just like structural design problems (more my background) typically have families of solutions. It is a beautiful problem in that respect, as well as the fact that these two very different forms of signal are both so common that clean and effective mixing of the two types must surely be useful in many applications. I should have posted this long ago, but never got into it far enough to lay it out in full detail.

    -HL
  • stamptrolstamptrol Posts: 1,731
    edited 2011-10-28 06:57
    Hand Launch,

    To echo Mike, if you don't have a reference, there is no way of knowing where the pulse is within the frame. Averaging a single constant width pulse will keep giving the same result; any change would be due to the next pulse being nearer or farther away.

    For instance is the "...user input PPM signal..." at a constant 50 Hz? What sets the 50 Hz rate? Could we use it as a reference?

    Have you got a diagram?

    Cheers,
  • Hand LaunchHand Launch Posts: 6
    edited 2011-10-28 10:04
    Here are a couple of videos that show some set-up and measurements of the unfiltered MEMS output which has a variable duty cycle and a constant frame rate.

    vid #0 is my 'cheapo' servo driver which I would like to replace with something that I can tailor using software: http://www.youtube.com/watch?v=DnbihDmPOuw

    vid #1 is the long one http://www.youtube.com/watch?v=BvWKlKDCUEE
    vid #2 is very short http://www.youtube.com/watch?v=lxL_czlYi1Y

    Generally I don't favor the cheapo servo driver as a signal generator due to typically low resolution and range of motion issues (cropping, asymmetry, etc.) so that is one agenda item for the BStamp development effort in terms of a better signal (or better preservation of my beautifully analog control input device signal) to feed the MEMS angular accelerometer. Filtering the MEMS sensor output to get back to analog is my primary goal.

    I'm going through this exercise because the MEMS device is good at what it does, which is higher frequency inertial detection and reporting through superposition of its own detected signal onto the user input signal. It even dithers its own input as the user input approaches full deflection in either direction, thus relinquishing authority in times when the user usurps said same authority. It is an animal truly designed for active stabilized user controls application. Nice.

    The MEMS device lives in the PPM domain, so the PPM domain is where we must go to consult it. Meanwhile back in the universe of the user, we love our analog (continuous and silky smooth) control signal characteristics, so in the user domain we must speak the analog language. Both have their advantages, so why not use each to its own advantage. It merely requires honest translation between the two languages to share the proper meaning....

    I have been able to get analog filtered output using simple resistor-capacitor circuits w/ variable resistor to demonstrate the effect of different resistance. I am very proud of my 'dip-sister' test resister but it probably isn't a new idea. In these videos you can see the transformation from the PPM digital control waveform to a analog voltage that varies directly w/ the position of the input controller. The fuzz in the control is noise from the fluorescent lighting which I need for the camera but goes away w/ lights out.

    vid #3 is another long one: http://www.youtube.com/watch?v=FWGjVQDqWn0
    vid #4 is short and loads faster: http://www.youtube.com/watch?v=VImMTlebDBs

    If the BStamp device characterizes the simple waveform in an undeflected and undisturbed condition, it seems to me a gate could be calculated to center around the center of the active portion of the frame. This may require a full duty cycle of the input control signal (i.e. prompted/executed by the Stamp as required) to establish the location and size of the gate, which would then allow for gate calibration no matter what MEMS angular accel product were chosen.

    This post is already too long to get into the potential logical path of execution for such effort, but I have a clear idea of the actions and duty cycle measurements involved, and I'm guessing it could be completely executed within way under one second duration once the MEMS is on line after its 3 or 4 second startup cycle.



    -HL
  • stamptrolstamptrol Posts: 1,731
    edited 2011-10-31 10:24
    Hand Launch

    From your post, I believe you are making satisfactory progress.

    Nonetheless, in considering what you want to do, I stumbled on the Youtube engineering lectures by Surendra Prasad of IIT in Delhi. His Lecture 39 covers PWM and PPM (PPM starts about 29 minutes in). They are quite well done for a classroom setting.

    The important point made is that you can get from PPM to analog in two steps. The first is low pass filtering (which you've done) plus a stage of integration (which the Stamp could do).

    Now with two analog signals (the converted PPM plus the manual offset) , its a small job to combine them as you desire.

    Cheers,
  • Hand LaunchHand Launch Posts: 6
    edited 2011-10-31 18:02
    Thanks Tom,

    I've download that and given it a look, good stuff (tough audio, obviously mastered on tape w/ what sounds like a loose belt drive tape deck).

    Now it seems my signal is actually single/sole value PWM as opposed to PPM according to Prof. Prasad. Its really nice to have great references like that available so easily. Gotta like the internet age!

    Anyway since its a single/sole value, there are only two bit transitions in each frame, one at the beginning and one in the middle. What would be the third bit transition is actually the start of the next frame, or the next reference pulse.

    Because there is a signal bit transition at the beginning of my frame, counting the pulse width (to the second transition) and the frame width (to the third transition, same transition direction as the first, reset counters) should be an ideal task for BStamp.

    Here is what I envision as the potential utility of a BStamp for my controls signal system architecture:

    The user has to pwr up the system and not touch the controls or move the device.

    When the device starts up there is some arbitrary initialization period for the rotational sensor. The Stamp may be programmed to wait for whatever period after system power-up or after detecting some signature signal activity associated w/ that pwr-up. During the wait a lamp indication (flashing yellow/amber for example) may be used to signify 'waiting'. At the end of this period when some frame appears on the signal line, the BStamp could detect that fact, record what is the center value and frame length, and then change the indicator lamp (i.e. to solid amber from flashing) to signify to the user: "ready for next step".

    That solid lamp indication could signal the user to input control from one end of the range to the other (w/ some minimum loiter time at each end of that range to be sure the extremes are reached after any capacitive lag or time constant). Then a steady lamp indication again to tell the user: "go to the next step", the user moves the controller to the other end of the range....

    During that stop-to-stop motion of the input controller, the BStamp should be useful for calculation of the range of measured signal that represents that full range of input signal value.

    The calculated range of input value could then be used to scale and center an analog voltage output for use as the control signal, scaled to 0-to-5v and centered at 2.5v. Naturally all of this depends on high enough frequency in the counting to get good resolution of the modulated pulse width, and fast enough execution of instructions to handle a few instructions every few milliseconds, all of which it seems these BStamp products should be able to handle w/ careful coding to keep things efficient.

    I'm very excited to get my developer's kit in the mail and get to work! I'm sure I'll have more questions, which I'll save till I've read all the documentation....

    -HL
Sign In or Register to comment.