61. 64-nano-Seconds Pulse Detection

Design a task using a microcontroller with the following requirements

  • Detect a pulse generated by the pulse generator.
  • Upon detecting the pulse, toggle the LED.
  • No pulses should be missed, and the LED state must be updated immediately

Note: We can generate pulses using any microcontroller.

Also, consider the following condition

  • An important task is continuously running in a void loop(). It needs to be executed continuously and cannot be altered or changed. 

Your void loop() should be as given below.

void loop() {
  	while (true){
		 //In this loop Microcontroller is busy in monitoring and performing   important tasks constantly.
}
}

For example:

Code for pulse generation using Arduino UNO.

  • The code generates a pulse of width 64 nanoseconds every 5000 ms.
  • The pulse is generated on digital pin no. 7 of Arduino UNO. 
void setup() {
  Serial.begin(115200);        // Initialize serial communication at 115200 baud rate
  pinMode(7, OUTPUT);          // Set pin 7 as an output pin
  digitalWrite(7, LOW);        // Set pin 7 to LOW (initial state)
}

void loop() {
  PORTD = 0x80;                // Set the 7th bit of PORTD to HIGH (binary 10000000), turning on pin 7
  PORTD = 0x00;                // Set all bits of PORTD to LOW (binary 00000000), turning off pin 7
  Serial.println("Pulse Generated");  // Print "Pulse Generated" to the Serial Monitor
  delay(5000);                 // Wait for 5000 milliseconds (5 seconds) before repeating the process
}

 

Generated output pulse:

The pulse below is generated by the Pulse Generator after every 5 seconds.

The width of the pulse is around 64 nanoseconds.

 

 

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!