Pages: [1]   Go Down
Author Topic: Change pulseIn() instruction to pulseWidth()  (Read 2108 times)
0 Members and 1 Guest are viewing this topic.
N. Illinois
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"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...
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 169
Posts: 12441
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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();


Logged

Rob Tillaart

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

N. Illinois
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).

 
Logged

Pages: [1]   Go Up
Jump to: