Devices & Components
Arduino Uno Rev3
Project description
Code
Code
c_cpp
1/* Code developed by L.Boaz 2 * Nissi Embedded Laboratory 3 * India - 627 808 4 * nissiprojectzone@gmail.com 5 * facebook/nissiembeddedlab 6 */ 7const int PWMGenerator = 5; //980Hz pulse generator arduino itself 8const int PulseIN = 7; // pulse counter pin 9float ONCycle; //oncycle variable 10float OFFCycle; // offcycle variable got microsecond 11float T; // tota l time to one cycle ONCycle + OFFcycle 12int F; // Frequency = 1/T 13float DutyCycle; // D = (TON/(TON+TOFF))*100 % 14void setup() 15{ 16 pinMode(PWMGenerator, OUTPUT); 17 pinMode(PulseIN, INPUT); 18 Serial.begin(9600); 19 analogWrite(PWMGenerator,100); //sample pulse 980Hz 20} 21void loop() 22{ 23 ONCycle = pulseIn(PulseIN, HIGH); 24 OFFCycle = pulseIn(PulseIN, LOW); 25 //Serial.println(ONCycle); 26 //Serial.println(OFFCycle); 27 T = ONCycle + OFFCycle; 28 DutyCycle = (ONCycle / T) * 100; 29 F = 1000000 / T; // 1000000= microsecond 10^-6 goes to upper 30 Serial.print("Frequency = "); 31 Serial.print(F); 32 Serial.print(" Hz"); 33 Serial.print("\ 34"); 35 Serial.print("DutyCycle = "); 36 Serial.print(DutyCycle, 2); 37 Serial.print(" %"); 38 Serial.print("\ 39"); 40 delay(1000); 41} 42
Downloadable files
Wiring
Wiring

Wiring
Wiring

Comments
Only logged in users can leave comments