Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   PWM Input? (http://www.chiefdelphi.com/forums/showthread.php?t=126075)

DarthCoder 08-02-2014 16:59

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?

theawesome1730 08-02-2014 17:03

Re: PWM 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

DarthCoder 08-02-2014 17:05

Re: PWM Input?
 
This is the one we have http://blog.radioshack.com/2013/07/f...-range-sensor/

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

Joe Ross 08-02-2014 17:35

Re: PWM Input?
 
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.

Ether 08-02-2014 17:57

Re: PWM Input?
 
Quote:

Originally Posted by DarthCoder (Post 1339750)
Is there any way to read PWM from a digital input?

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

Oops... Maybe not with that part number.


DarthCoder 08-02-2014 17:59

Re: PWM Input?
 
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.

Ether 08-02-2014 18:27

Re: PWM Input?
 



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?



Joe Ross 08-02-2014 18:33

Re: PWM Input?
 
Quote:

Originally Posted by Ether (Post 1339784)



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.

Code:

/*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);
}


Ether 08-02-2014 18:47

Re: PWM Input?
 


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?



FrankJ 08-02-2014 21:18

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

Ether 08-02-2014 22:38

Re: PWM Input?
 
Quote:

Originally Posted by FrankJ (Post 1339849)
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.




All times are GMT -5. The time now is 02:35.

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