2

I am new to this forum, and I have a question regard EE and Arduino based boards.

Are Arduino based boards capable of producing pulses in the range of MICROseconds (usecs)? For example, I would like to generate 1 pulse (say 5 volts for 200usecs) given an arbitrary command I send to the microcontroller. This pulse would be used to activate a device it is attached to. Is this possible?

I have an Azteeg X3 Pro board (ATMEGA2560 and RAMPS 1.4 base).

Ideally, this picture is what I am trying to do. enter image description here

Jseung321
  • 23
  • 2
  • 1
    Well, according to [this](http://forum.arduino.cc/index.php?topic=4324.0) discussion, yes, but you can't rely on the "Arduino" language for that. And depending on how frequently you want the pulses you might not have much time to do "other stuff". – Wesley Lee Feb 02 '17 at 07:45
  • 3
    do you need the pulse width to be exactly 200usec? is it okay if it is 195 us or 205 us? – User323693 Feb 02 '17 at 07:54
  • The range doesn't have to me too accurate so it's okay – Jseung321 Feb 02 '17 at 18:33

2 Answers2

4

Are Arduino based boards capable of producing pulses in the range of MICROseconds (usecs)?

This can be achieved in a number of ways

Some examples:

  1. Using the micros() function.
    This returns the value of a counter which is in microsecond units and which is incremented every 4 or 8 microseconds (see below)

They say

Returns the number of microseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution of eight microseconds.

  1. Here is a 2011 SE EE question which should be useful - Arduino: better microsecond resolution than micros()? Answers cover the direct use of the hardware timers.

  1. You can use the delayMicroseconds() function which delays all actions for the defined period. While limiting this may be useful in some simple applications.

  2. You can write your own loop with known time per loop. This would allow you to perform various simple functions while you wait.

Russell McMahon
  • 147,325
  • 18
  • 210
  • 386
  • @Dave Tweed - thanks - for some reason I assumed that using ( & ) inside [...] would break the system, but obviously that's not the case. – Russell McMahon Feb 03 '17 at 03:04
2

Yes Arduino is capable for producing pulse.

This code will work for you.

Code :

const int kPinPulse = 8; // You can select any pin of arduino
const int kPinSW = 9;    //This switch will work as command

void setup()
{
   pinMode(kPinPulse, OUTPUT);
   pinMode(kPinSW, INPUT);      
}

void loop()
{
   if(digitalRead(kPinSW) == LOW) //When Switch pressed Command Sent
   {
      digitalWrite(kPinPulse, HIGH); // start your pulse
      delayMicroseconds(200);        // It's provide your time interval of 200 microseconds
      digitalWrite(kPinPulse, LOW);  // end your pulse
      while(digitalRead(kPinSW) == LOW); 
   }     
}

NOTE: Here, I have taken a Switch on Pin number 9, this will work as command to sent a pulse of 200 microseconds i.e. when switch is pressed 200uS pulse will be generated.

karanrp
  • 245
  • 3
  • 12
  • 2
    Just two remarks. 1) this will produce a serie of small pulses towards ground; why don't you wait for a command as the OP wrote in his image? 2) you delayed for 100 microseconds. Why, since the OP asked for a 200us interval? I know, it is really easy to modify it, but.. Why bothering to write a different interval? As a side note, moreover, note that the digitalWrite functions are not instantaneous. If you remove the delay, you will note that the pulse will be almost 14us wide (17us if you add a delay of 0). So.. This will need to be taken into account when trimming the function – frarugi87 Feb 02 '17 at 09:34
  • @frarugi87...Okk done edition. – karanrp Feb 02 '17 at 10:06