# DigitalWrite & DigitalRead and Delay in ns

**URL:** <https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765>\
**Category:** 3rd Party Boards\
**Created:** [October 21, 2024, 6:59pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765 "2024-10-21T18:59:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 6:59pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/1 "2024-10-21T18:59:49Z")

</div>

Hello everyone,

I have an Arduino UNO R4, and the fastest digitalWrite or DigitalRead or Delay  
are in us (microsecond)

I'm looking for a single chip if possible (not an complete dev. Board) that I can program with Arduino IDE, and achieve a DigitalWrite / DigitalRead/ Delay in ns (nanosecond) without using direct port manipulation as for ATMega328p can do.

Also if possible the uC should be as small as possible no need for more than 8 ports all digital no analog.

Is this possible?

My task is to write a 1 to port and a 0 the fastest (in nanosecond) I can get from the uC.

The future project will be draw around the uC , and Arduino IDE possibility.

Let me know if you did program or have any experience with Arduino IDE and some uC with the ns timing in mind.

All kindly comments are welcome.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [October 21, 2024, 7:15pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/2 "2024-10-21T19:15:31Z")

</div>

- Nanoseconds ? 🤔  
Not going to happen.

- What exactly are you needing this for ?

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [October 21, 2024, 7:15pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/3 "2024-10-21T19:15:39Z")

</div>

> [@jackcable2002](#):
>
> My task is to write a 1 to port and a 0 the fastest (in nanosecond) I can get from the uC.

Care to reword that? I think you said, "my task is to write a 1 to a pin, and then as soon as possible after that, write a 0 to the same pin". Is that correct? So you're trying to create a short high pulse, on a signal that's primarily low? If so, how short do you need/how long can you tolerate?

Even with an Arduino Uno, I think that works out to about 125 ns, with back-to-back pin writes, working directly in the IDE.

> without using direct port manipulation as for ATMega328p can do.

Which you seem to not want to do. Why not?

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 7:55pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/4 "2024-10-21T19:55:34Z")

</div>

Thank you LarryD

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:03pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/5 "2024-10-21T20:03:16Z")

</div>

Hello camsysca

sure my description of my project is not well details, the project consist of programming an parallel EEprom and to get the datasheet timing accurate the uC  
need to put a 1 or 0 and back to previous state to simplify  
to be able to write to the eeprom write pin and to control in the mean time the OE (output enable) pin.  
all the timing are at the minimum 100ns to 1000ns Max.  
so I'm looking to write a pulse of 4us and also a pulse of 600ns.  
please see the timing pic.  
Thanks again for your comments.

 ![owon we-oe](https://europe1.discourse-cdn.com/arduino/original/4X/a/d/9/ad9949191f80572cae254387fa30e5555196b1a1.png)

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:14pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/7 "2024-10-21T20:14:07Z")

</div>

HI Delta\_G  
can you elaborate about the code if possible.

Thanks

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:17pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/9 "2024-10-21T20:17:25Z")

</div>

> [@Delta\_G](#):
>
> RA4M1

and all this is possible with the current Arduino IDE?

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:19pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/12 "2024-10-21T20:19:13Z")

</div>

Is this the only solution, or is there a smaller uC like around 20 pins total , I'm thinking.

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:24pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/14 "2024-10-21T20:24:26Z")

</div>

I tested an ATMega328P , with direct port pulse and it's fast around 64ns  
but cannot send 1 pulse of 4us and in the middle of that pulse send to another pin pulse of 620ns.  
all I got was 1 pulse of 4us start to end , and then another pulse of 64ns but not  
both at the same time.  
like the oscilloscope pic.

---

<div class="post-metadata">

**Author:** ![johnerrington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnerrington/32/340106_2.png) [@johnerrington](https://forum.arduino.cc/u/johnerrington)\
**Post date:** [October 21, 2024, 8:29pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/17 "2024-10-21T20:29:27Z")

</div>

Have you considered handling the timing with simple digital IC's?

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:31pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/18 "2024-10-21T20:31:44Z")

</div>

here's my try

```arduino
void setup() {
 
  DDRB = 0b00000100;
}

void loop() {
 
  PORTB = 0b00000100;
  PORTB = 0b00000000;
 }

```

I will need to research more code examples on this forum and learn from it.

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:36pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/20 "2024-10-21T20:36:52Z")

</div>

MM74HC221 work great, but looking to expand with a uC , to control the address,data, controls pin of the Parallel EEPROM.

---

<div class="post-metadata">

**Author:** ![b707](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/b707/32/854321_2.png) [@b707](https://forum.arduino.cc/u/b707)\
**Post date:** [October 21, 2024, 8:38pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/21 "2024-10-21T20:38:20Z")

</div>

> [@jackcable2002](#):
>
> the project consist of programming an parallel EEprom and to get the datasheet timing accurate

Are you sure you understood the datasheet correctly? It is very rare that working with logic signals requires such precision of pulses

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:38pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/22 "2024-10-21T20:38:47Z")

</div>

this is was is left on my directory, but I understand your comment about taking Pin high then...

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:49pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/23 "2024-10-21T20:49:41Z")

</div>

Hi b707  
here's the AT28C16 EEPROM datasheet Timing for WE,OE  
This chip datasheet dated from 1998, so it's been well used by many company.

 ![at28c16-0](https://europe1.discourse-cdn.com/arduino/original/4X/6/f/b/6fb976c02815c8cbd7d5fb1d71a2bbae0513d94a.jpeg)  
 ![at28c16-1](https://europe1.discourse-cdn.com/arduino/original/4X/2/0/d/20def23ceed8e664ee2a472e55bdd8beb39c9042.jpeg)

according to this chart the timing is at least 100ns ~ to 1000ns Max.  
that's mean to write properly I'm looking for 300ns~700ns around but less than 1000ns.

I'm sure there's a solution

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 8:52pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/24 "2024-10-21T20:52:24Z")

</div>

MM74HC221 and it's work ok  
but looking to use a uC to control address, data, control pin also

---

<div class="post-metadata">

**Author:** ![b707](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/b707/32/854321_2.png) [@b707](https://forum.arduino.cc/u/b707)\
**Post date:** [October 21, 2024, 8:54pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/25 "2024-10-21T20:54:03Z")

</div>

> [@jackcable2002](#):
>
> according to this chart the timing is at least 100ns ~ to 1000ns Max.

This related to WE|CE writing pulse only.

Sorry, but your code in #18 does not show anything in common with the described protocol. How do you suppose they can help you if you yourself have not even started the work?

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 9:00pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/26 "2024-10-21T21:00:26Z")

</div>

Dear b707  
This is why I'm here asking for guidance but not reprimand  
Let me thank you for your time.

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [October 21, 2024, 9:06pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/27 "2024-10-21T21:06:32Z")

</div>

Let's see. 11 address lines, 8 data lines, WE, OE, CE. Sounds to me like you need 20 useful signals, 8 bidirectional and 12 output. Ideal for a '328. The timing won't be much of a problem, given what I said before. Draw yourself a sketch with 5 relevant lines(WE,CE,OE,A0,D0; the rest of the addresses and data lines will be concurrent), and map out the timing needed. Presume direct port pin writing, use \_NOP to stretch timing between logic changes if necessary.  
Good luck!  
edit. Need more fingers. 11+3+8 = 22. can't be done with a '328. Sorry!

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [October 21, 2024, 9:09pm UTC](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765/28 "2024-10-21T21:09:31Z")

</div>

I assumed that a 328 will be short of pin's.  
But I was looking to another uC with more pin's but not 100 for sure  
but small as it can fit.  
Thanks camsysca

[Next page](https://forum.arduino.cc/t/digitalwrite-digitalread-and-delay-in-ns/1313765.md?page=2)
