Go Down

Topic: Change pulseIn() instruction to pulseWidth() (Read 3573 times) previous topic - next topic

bobert0670

So I have been playing with arduino for a while now, and love it. In fact I even used one to solve a issue at a customers who has since purchased 50 systems.  I am workin on some home projects and need to read pulses from various sensors.  I noticed the pulseIn instruction which I thought would be great.  To my surprise it is actually a pulse width instruction. To count pulses I have to create a state and check if the input state changed or not to increment the counter.  I have been programming industrial controllers (PLC's) for many years and use "oneshot" instructions often.

I would like to suggest changing the operation of pulseIn() to just count pulses...... pulseIn(Input, HIGH or Low, DINT) this allows pulse counting on the state changing either high or low and incorporates a large counter.

I see the current instruction as a PulseWidth() instruction since that is more accurate to what the function does.

My two cents anyway.  Keep up the good work.


westfw

"pulseIn" is the name used for the similar function on prior systems (notably, the Parallax "Basic Stamp.")
So it's got about 20 years of precedent...

robtillaart

Naming is always difficult, but I agree, the name is not matching its function.

you could wrap the function to make your code more readable for yourself?
something like

uint32_t pulseWidth(...)
{
   return pulseIn(..);
}

Quote
I would like to suggest changing the operation of pulseIn() to just count pulses...... pulseIn(Input, HIGH or Low, DINT) this allows pulse counting on the state changing either high or low and incorporates a large counter.


I would name that function -  pulseCount(pin, mode);  // mode = { HIGH, LOW, CHANGE }

PulseIn() sounds for me as a boolean function, "if one or more pulses came in"

if (pulseIn(pin)) doSomeThing();


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

bobert0670

I agree Rob it does sound more of a Boolean instruction, like the one shot!  I suppose I went overboard when I suggested making a counter as well.  I don't have a problem with readability in the code, just thought I would contribute my 2 cents for all the help I have been given.

I also agree that it may have precedent in this environment, as I stated I am used to PLC controls, where it has existed as a one shot.  (Think Normally open contact with either an up or down arrow in the middle).


Go Up