PWM Input?

We need to be able to read a PWM input from a Radio Shack ultrasonic range finder. The PWM class only works for output, and we can’t seem to get the counter class working either. Is there any way to read PWM from a digital input?

Not through digital since it is on/off and the range finder would output multiple values other than 0 and 1, but you can through the analog breakout on the cRIO

This is the one we have http://blog.radioshack.com/2013/07/find-your-way-with-the-ultrasonic-range-sensor/

We’re pretty sure it’s PWM not analog.

You are correct that it is a digital PWM input. However, it is also requires a digital output on the same pin to trigger a distance measurement. The cRIO FPGA wasn’t designed to handle this use case. There are many other ultrasonic sensors that would be easier to use, including digital ones where the request and the response are on different pins. Alternately, you could build a circuit to separate the two signals.

I wonder if you could read the pulse width by treating it like a counter.

Oops… Maybe not with that part number.
*
*

Tried that. It never returned anything but 0, and infinity. We even tested the counter with slower inputs and it worked that time. I think the sensor is too fast for the counter class.

The bottom of Page3 of the User’s Guide for 2760342 implies that the SIG pin is a “Serial Monitor (9600)”. Sounds like RS-232 to me, not PWM. Am I misinterpreting this?

I think that’s talking about opening the serial monitor in the Arduino programming environment, so you that you can read the data that the Arduino code is sending over the serial port.

Here’s the relevant portion of the arduino code for reading the sensor.

/*Begin the detection and get the pulse back signal*/
void Ultrasonic::DistanceMeasure(void)
{
    pinMode(_pin, OUTPUT);
	digitalWrite(_pin, LOW);
	delayMicroseconds(2);
	digitalWrite(_pin, HIGH);
	delayMicroseconds(5);
	digitalWrite(_pin,LOW);
	pinMode(_pin,INPUT);
	duration = pulseIn(_pin,HIGH);
}

Thanks Joe. I searched for a datasheet that documents the protocol of the SIG pin for this device but was not successful.

What I was looking for was this: Is the protocol strictly command/response, or can it be set up to continuously broadcast its distance measurements? And if so, is the pulse width user configurable into a range that the FPGA sampling rate could handle?

Would not a counter count pulses rather than pulse width? It seems unless something is programed in the FPGA it is not doable.

The getperiod() method in the counter class in WPILib uses FPGA to measure the pulse width using a microsecond timer.