user54800: I have 3rd party device that create PWM output which I want to measure it with Arduino, the problem I have is when I shared ground between the two boards which cause the Pulsein output to become zero. (why this is happening, and how to fix it)
The reason I am connecting the ground since I need measure other signals on that board. (All other signals are responding fine)

simulate this circuit – Schematic created using CircuitLab
code:
#define pulse_ip 3
unsigned long duration;
int ontime,offtime,duty;
float freq,period;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(pulse_ip, INPUT);
}
   
void loop() {
  // put your main code here, to run repeatedly:

  ontime = pulseIn(pulse_ip, HIGH);
  offtime = pulseIn(pulse_ip, LOW);
  period = ontime + offtime;
  freq = 1000000.0 / period;
  duty = (ontime / period) * 100;
  Serial.print(offtime);
  Serial.print("-");
  Serial.print(ontime);
  Serial.print("-");
  Serial.print(period);
  Serial.print("-");
  Serial.print(freq);
  Serial.print("-");
  Serial.print((duty * 255) / 100);
  Serial.print("-");
  Serial.println(duty);
  delay(1000);
  
}


user37622: Without connected grounds the signal on the input pin you read with pulseIn must be random noise.
Two pulseIn one waiting for HIGH change and second waiting for LOW don't make sense because for parameter HIGH, pulseIn waits for the pin to go from LOW to HIGH, starts timing, then waits for the pin to go LOW and stops timing. Then it returns the length of the pulse in microseconds.

54800: <p>I have 3rd party device that create PWM output which I want to measure it with Arduino, the problem I have is when I shared ground between the two boards which cause the Pulsein output to become zero. (why this is happening, and how to fix it)</p>
<p>The reason I am connecting the ground since I need measure other signals on that board. (All other signals are responding fine)</p>

<p><img src="https://i.stack.imgur.com/GaJd8.png" alt="schematic" /></p>

<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fGaJd8.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>
<p>code:</p>
<pre class="lang-cpp prettyprint-override"><code>#define pulse_ip 3
unsigned long duration;
int ontime,offtime,duty;
float freq,period;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(pulse_ip, INPUT);
}
   
void loop() {
  // put your main code here, to run repeatedly:

  ontime = pulseIn(pulse_ip, HIGH);
  offtime = pulseIn(pulse_ip, LOW);
  period = ontime + offtime;
  freq = 1000000.0 / period;
  duty = (ontime / period) * 100;
  Serial.print(offtime);
  Serial.print(&quot;-&quot;);
  Serial.print(ontime);
  Serial.print(&quot;-&quot;);
  Serial.print(period);
  Serial.print(&quot;-&quot;);
  Serial.print(freq);
  Serial.print(&quot;-&quot;);
  Serial.print((duty * 255) / 100);
  Serial.print(&quot;-&quot;);
  Serial.println(duty);
  delay(1000);
  
}
</code></pre>
 37622: <p>Without connected grounds the signal on the input pin you read with pulseIn must be random noise.</p>
<p>Two <code>pulseIn</code> one waiting for HIGH change and second waiting for LOW don't make sense because for parameter HIGH, <code>pulseIn</code> <strong>waits for the pin to go from LOW to HIGH</strong>, starts timing, <strong>then waits for the pin to go LOW</strong> and stops timing. Then it returns the length of the pulse in microseconds.</p>
