Author Topic: Arduino - Multiple PORTs  (Read 1910 times)

0 Members and 1 Guest are viewing this topic.

Offline LeopoldoTopic starter

  • Contributor
  • Posts: 44
Arduino - Multiple PORTs
« on: August 08, 2016, 02:23:39 pm »
Hi there!
I'm working on a project that involves writing 16bit on two ports of an arduino Mega, but since it's an 8bit microcontroller, the two ports need to be written separately, one after the other. I was wondering, is there a way to write them at the exact same time? I mean, with the same clock cycle?
I don't mind if it still has to take the same number of clock cycles, as long as it can write them simultaneously.
It should run pretty fast, hence writing the two ports in different clock cycles would be a problem. Thank you in advance!!
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Arduino - Multiple PORTs
« Reply #1 on: August 08, 2016, 02:30:38 pm »
Hi there!
I'm working on a project that involves writing 16bit on two ports of an arduino Mega, but since it's an 8bit microcontroller, the two ports need to be written separately, one after the other. I was wondering, is there a way to write them at the exact same time? I mean, with the same clock cycle?
I don't mind if it still has to take the same number of clock cycles, as long as it can write them simultaneously.
It should run pretty fast, hence writing the two ports in different clock cycles would be a problem. Thank you in advance!!

 Only a single 8 bit port can be changed in a single clock instruction cycle. Are you sure this is a hard requirement. How is the receiving end to know when there has been an update to the 16 parallel bits?
« Last Edit: August 08, 2016, 02:32:32 pm by retrolefty »
 
The following users thanked this post: Leopoldo

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12864
Re: Arduino - Multiple PORTs
« Reply #2 on: August 08, 2016, 02:32:47 pm »
No.  That's what an 8 bit MCU does.  If you could transfer 16 bit of data in one instruction cycle it would be a 16 bit MCU.

In practice, if you throw out the Arduino port/pin libraries and code the output in AVR assembler, you should be able to get the timing skew down to a few clock cycles.  You cant do better without an external 16 bit latch with a separate pin strobing it.
 
The following users thanked this post: Leopoldo

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Arduino - Multiple PORTs
« Reply #3 on: August 08, 2016, 03:42:51 pm »
"wondering, is there a way to write them at the exact same time? I mean, with the same clock cycle? "

Not direct.

But yes, through some port expanders or shift registers.
================================
https://dannyelectronics.wordpress.com/
 

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Arduino - Multiple PORTs
« Reply #4 on: August 08, 2016, 07:59:39 pm »
 Or latches, like many early CPUs. Instead of using up to 24 pins for a 16 bit address bus plus an 8 bit data bus, that stuff was multiplexed with a timing signal to drive latches, Instead of using 16 lines to get 16 bits, you can use a latch, 8 lines, plus one additional as the timing signal. Latch the upper or lower 8 bits, then apply the second 8 bits to the port, timed to the destination by the signal line, when it goes high (or low, depending on the latch used, etc), you now have 16 bits present on a bus in a valid state for the receiving device to utilize.

 
 

Offline LeopoldoTopic starter

  • Contributor
  • Posts: 44
Re: Arduino - Multiple PORTs
« Reply #5 on: August 08, 2016, 09:44:22 pm »
Thank you all; I think I'll stick with arduino built-in hardware, so I'll write 2 ports one after the other;I found that the phase lag is actually quite unnoticeable.
Now...How do I mark this post as solved?  ;D
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf