Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Measuring PWM input signals

  1. #11
    virtuald Guest

    Default Re: Measuring PWM input signals

    Quote Originally Posted by Joe Hershberger View Post
    In the process of looking at the state of the InterruptableSensorBase class to explain this to you, I discovered that the class was never finished. I'm not sure if or how it has ever worked. It never reserves an interrupt number and it uses an uninitialized variable as the interrupt number. I guess no one is using interrupts since no one has complained about the total lack of functionality yet.
    This doesn't surprise me -- given all of the functionality that WPILib provides, there is generally very little reason to use interrupts.

    Actually, we were using interrupts for 4 hall effect sensors we were using -- interrupts do appear to work, at least partially. We *did* have mysterious bugs with it, however we were blaming that on hardware errors -- since we kept finding malfunctioning sensors. Go figure.

    Quote Originally Posted by Joe Hershberger View Post
    It sounds like what you are wanting is actually exactly what the interrupts do (time stamp events). Counters do something similar (or rather the timers attached to the counters) but presumably more useful... they return the time between edges. It is asumed that you are interested in the difference, not the absolute times. You would just subtract the edge times once you get them anyway, right? Because it is a difference, you don't have to make sure you read two consecutive edges. You can just read whenever, and it is still valid.

    You could also use two counters (one for high semi-period and the other for low semi-period) and use DMA to transfer the samples so you know they are consistent.
    Well to be honest, I'm not exactly sure what it is that I want -- but I'd like it to work.

    The idea I had came up with (that I cant test until monday) is call "SetPulseLengthMode(1.0)" on two seperate counters, and then get the period from them.

    Code:
    // specify the source
    countXhi.SetUpSource(3);
    countXlow.SetUpSource(3);
    		
    // specify the edge
    countXhi.SetUpSourceEdge(true, false);
    countXlow.SetUpSourceEdge(false, true);
    		
    // setup the counters
    countXhi.SetPulseLengthMode(1.0);
    countXlow.SetPulseLengthMode(1.0);
    		
    countXhi.Start();
    countXlow.Start();
    
    
    ... stuff here ...
    
    double axH = countXhi.GetPeriod();
    double axL = countXlow.GetPeriod();
    
    // convert to m/s^2 -- 50% duty cycle is 0g
    double ax = (((axH / (axH + axL)) - .5) * 8.0) * 9.81;
    The document at http://zone.ni.com/reference/en-XX/h...ps/measperiod/ discusses these various counter types, and it would seem to me that semi-period mode is *not* what I'm wanting, since I care only about the duty cycle of the output from the accelerometer.

    *sighs*

    It would be nice if FIRST just would have given our team the accelerometer with the kit of parts...

  2. #12
    Join Date
    Sep 2008
    Location
    National Instruments: Austin, TX
    Posts
    445

    Default Re: Measuring PWM input signals

    Quote Originally Posted by virtuald View Post
    The idea I had came up with (that I cant test until monday) is call "SetPulseLengthMode(1.0)" on two seperate counters, and then get the period from them.
    I can guarantee that it won't work as written. Pulse length mode is a special mode for dealing with gear tooth sensors from 3 years ago. The direction to count is specified with the pulse length of the signal from the sensor. That threshold parameter (that you are setting to 1.0) is the point that the counter starts counting up instead of down. It has nothing to do with measuring the pulse width.

    Quote Originally Posted by virtuald View Post
    The document at http://zone.ni.com/reference/en-XX/h...ps/measperiod/ discusses these various counter types, and it would seem to me that semi-period mode is *not* what I'm wanting, since I care only about the duty cycle of the output from the accelerometer.
    Ooooo.... that can be confusing if you don't read it carefully. That documentation is for the NI Data Acquisition products and the DAQmx driver. It doesn't really apply for the FRC FPGA. The whole reason why the answer to the original question was not simply "use this mode..." is that there is no mode that clearly gives duty cycle. It's important to understand that the FRC counters have dedicated timers associated with each one. I recommend you mostly ignore the documentation on that page for the purposes of FRC as most of it does not apply. It is referring to timing modes, while FRC deals with primarily with counting modes.

    The one exception is semi-period mode. It is the only mode in FRC that is primarily a timing mode. One thing that is a bit confusing is that the semi-period mode in the FRC FPGA would be best represented by the documentation for the "Pulse Width Measurement" mode in DAQmx. The reason is that unlike DAQ counters, the FRC counters cannot return both semi-periods at once... you have to specify which you want (in the call to SetSemiPeriodMode()) and it will always give you the time of just that one.

    Another thing to know (that I don't see in the documentation), is that when you select semi-period mode, you should NOT call Set*SourceEdge().

    The counter driver in C++ and the corresponding documentation leaves a bit to be desired. :/

    Quote Originally Posted by virtuald View Post
    It would be nice if FIRST just would have given our team the accelerometer with the kit of parts...
    I thought you were just supposed to report anything missing from your kit a few days after kickoff and they will complete the kit.

  3. #13
    virtuald Guest

    Default Re: Measuring PWM input signals

    Quote Originally Posted by Joe Hershberger View Post
    Ooooo.... that can be confusing if you don't read it carefully. That documentation is for the NI Data Acquisition products and the DAQmx driver. It doesn't really apply for the FRC FPGA.
    Ah, I figured that since it was talking about LabView stuff, and the FPGA was LabView, there was some correlation in the docs. Guess not, good to know.

    The reason is that unlike DAQ counters, the FRC counters cannot return both semi-periods at once... you have to specify which you want (in the call to SetSemiPeriodMode()) and it will always give you the time of just that one.
    Ok, so then the code would be exactly the same, except the initialization would be different. So.. this should (probably) do what I'm wanting:

    Code:
    // specify the source
    countXhi.SetUpSource(3);
    countXlow.SetUpSource(3);
    		
    // setup the counters for semi-period mode
    countXhi.SetSemiPeriodMode(true);
    countXlow.SetSemiPeriodMode(false);
    		
    countXhi.Start();
    countXlow.Start();
    
    
    ... stuff here ...
    
    double axH = countXhi.GetPeriod();
    double axL = countXlow.GetPeriod();
    
    // convert to m/s^2 -- 50% duty cycle is 0g
    double ax = (((axH / (axH + axL)) - .5) * 8.0) * 9.81;

    I thought you were just supposed to report anything missing from your kit a few days after kickoff and they will complete the kit.
    AFAIK that's what we did and it didn't happen, sadly enough.

  4. #14
    Join Date
    Sep 2008
    Location
    National Instruments: Austin, TX
    Posts
    445

    Default Re: Measuring PWM input signals

    That's pretty close, but you'll run into a resource reservation error. Try something more like this:

    Code:
    DigitalInput source(3);
    
    // specify the source
    countXhi.SetUpSource(source);
    countXlow.SetUpSource(source);
    		
    // setup the counters for semi-period mode
    countXhi.SetSemiPeriodMode(true);
    countXlow.SetSemiPeriodMode(false);
    		
    ...
    Cheers
    -Joe

  5. #15
    virtuald Guest

    Default Re: Measuring PWM input signals

    Awesome, that seems to have done the trick -- I'm displaying the expected values for the pulses on the LCD, so must be at least *partially* working. The accelerometer seems to be a bit noisy, but from what I gather this is a constant problem with accelerometers..

  6. #16
    Join Date
    Sep 2008
    Location
    National Instruments: Austin, TX
    Posts
    445

    Default Re: Measuring PWM input signals

    Quote Originally Posted by Joe Hershberger View Post
    In the process of looking at the state of the InterruptableSensorBase class to explain this to you, I discovered that the class was never finished. I'm not sure if or how it has ever worked. It never reserves an interrupt number and it uses an uninitialized variable as the interrupt number. I guess no one is using interrupts since no one has complained about the total lack of functionality yet.
    Nevermind on this. I wasn't digging deep enough through the inheritance.

  7. #17
    virtuald Guest

    Default Re: Measuring PWM input signals

    Quote Originally Posted by Joe Hershberger View Post
    Nevermind on this. I wasn't digging deep enough through the inheritance.
    Ah, ok.

    Still needs a user parameter (ref: http://forums.usfirst.org/showthread.php?t=11936 ).

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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