![]() |
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); |
Re: Reading an absolute encoder via PWM in C++
You could probably use the Counter object and GetPeriod() method to make the FPGA keep track of the pulses instead of doing it in your code.
|
Re: Reading an absolute encoder via PWM in C++
Quote:
|
Re: Reading an absolute encoder via PWM in C++
Quote:
|
Re: Reading an absolute encoder via PWM in C++
There is a PWM class in WPILib but I don't know if that's only for outputting PWM or if it also supports reading PWM inputs. |
Re: Reading an absolute encoder via PWM in C++
Quote:
|
Re: Reading an absolute encoder via PWM in C++
In LabVIEW, you can configure a Counter for "Semi-Period" mode, which measures the pulse width of either high or low pulses instead of time between edges. This is what you want. Is there something similar in C++? (Since it's FPGA-level, I assume there's an interface in C++)
|
Re: Reading an absolute encoder via PWM in C++
The C++ Counter class has a semiperiod mode as well, though I have never used it.
|
Re: Reading an absolute encoder via PWM in C++
Quote:
Code:
/** |
Re: Reading an absolute encoder via PWM in C++
Thanks everyone!
To avoid a hail of quotes, I'll simply summarize: I tried the Counter class, but it didn't seem to want to do much more than, well, count. Every attempt at .GetPeriod() returned infinity, clearly hitting this Counter code: Code:
double Counter::GetPeriod()RufflesRidge, I followed that link, and it does look promising, I shall try it out tonight. |
Re: Reading an absolute encoder via PWM in C++
Quote:
|
Re: Reading an absolute encoder via PWM in C++
Quote:
We used the analog version of the MAE3 on robots in 2007-2009 with very good success, including a prototype swerve drive we built in the off-season. |
Re: Reading an absolute encoder via PWM in C++
Quote:
In LabVIEW, the Create Counter is polymorphic (there are multiple versions which you can select with a drop-down box). For the Semi-Period mode, the help says this: Code:
Open Semi Period ModeCode:
High Pulse (T) specifies, when TRUE, that the counter measures the length of the high time of the pulse. When FALSE, the counter measures the length of the low time of the pulse.The LabVIEW description of Up/Down mode says this: Code:
Open UpDown Mode |
Re: Reading an absolute encoder via PWM in C++
Once again, thanks for the ideas! Given other priorities and troubleshooting, we called in an order for the analog version as noted here
Quote:
Once we get through the competition this year, we'll do some exploratory work on this, because I'd really like to get to a working and stable solution for people to use as an AbsoluteEncoder or some such thing. |
Re: Reading an absolute encoder via PWM in C++
2 Attachment(s)
Quote:
|
| All times are GMT -5. The time now is 13:40. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi