Go to Post "Dear Santa, all I want for Christmas is a game hint." - Gregor [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 13-03-2012, 02:13
synthmusic synthmusic is offline
Registered User
FRC #3574
 
Join Date: Feb 2012
Location: Seattle
Posts: 5
synthmusic is an unknown quantity at this point
Reading an absolute encoder via PWM in C++

Hello all!

We are trying to get a reading from a sensor, the MAE3 from US Digital. Basically it outputs a PWM signial that shows its position by varying the width from 1 to 4096 uS. We're having trouble finding the right code that will grab that pulse width from the FPGA in a stable manner.

We can grab it in OperatorControl to show the signal is there, but the value varies by close to 10%, and often jumps to extreme numbers, assuming because we are in the main teleop loop.

Any pointers to the right object to use to get the PW correctly?

Thanks!!

"bBallAngle" is meant to show the number of microseconds elapsed for the width

Code:
bBallAngleSensor = new DigitalInput(2,11);

...

if (bBallAngleSensor->Get() == 1)
{
    // these for loops are to prevent a while lock.  if it loops 5000 times it will fall out
    // but a legit change will break;
    for (int i = 0; i < 5000; i++)
    {
        if (bBallAngleSensor->Get() == 0)
        {
            break;
        }
    }
    startTimeAngle = GetFPGATime();
    for (int i = 0; i < 5000; i++)
    {
        if (bBallAngleSensor->Get() == 1)
        {
            break;
        }
    }
    bBallAngle = GetFPGATime() - startTimeAngle;
}
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 17:40.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi