DIY ARDUINO BASED PWM FREQUENCY MEASURING AND DUTY CYCLE MEASURING

We can use the default plusein function to measure any digital wave signal time period. It is default installed library in ide.

Here is the code:

#define Read 7

void setup()

{

  Serial.begin(115200);

  pinMode(Read, INPUT);

}

void loop()

{

  float t_on = pulseIn(Read, HIGH);

  float t_off = pulseIn(Read, LOW);

  float Time = (t_on / (t_on + t_off)) * 100;

  float freq = 1 / (t_on + t_off);

  Serial.println("the on time:");

  Serial.print(t_on);

  Serial.println("the duty cycles:");

  Serial.print(Time, 4);

  Serial.print("%");

  Serial.println("");

  delay(500);

  if (freq > 1000.0)

  {

    Serial.println("the freq in khz:");

    Serial.print(freq /1000.0, 4);

    delay(500);

    Serial.println("");

  } else

  {

    Serial.println("the freq in hz:");

    Serial.print(freq, 4);

    delay(500);

    Serial.println("");

  }

}

Comments

Popular posts from this blog

"Kernel Panic” error After upgrading Parrot OS

HACK HC-05(BLUETOOTH MODULE) FRIMWARE INTO HID FRIMWARE

HACK AND CLONE CAR KEY FOB, MY EPIC FAILURE...!!