retrolefty:
Well analog pins can be used as either analog input pins or.......
Very informative, thanks! I was not aware of the multiplexed analog inputs. In that case, it might be worth it to just use the AnalogRead() function. I Figured all analog inputs would not be accessible within the same register.
What do you know about the PWM outputs? I understand the PWM frequency is also used in the tone generator, right? This would imply that either each PWM output runs independently, or there is a multiplexed operation that "sets" PWM values one at a time.
Robin2:
I don't understand how direct port manipulation can speed up Arduino-PC comms compared with using the regular Serial comms?
The main reason I am using direct port access is because it is accessed in full. Let me show you:
With the easy method, the setup looks like this:
Computer to Arduino:
Set Pin 1 ON (3 Bytes via serial)
Set Pin 2 OFF (3 Bytes via serial)
Set Pin 3 ON (3 Bytes via serial)
Set Pin 4 ON (3 Bytes via serial)
Set Pin 5 ON (3 Bytes via serial)
Set Pin 6 OFF (3 Bytes via serial)
Set Pin 7 ON (3 Bytes via serial)
Set Pin 8 ON (3 Bytes via serial)
(24 Bytes in total)
Arduino:
Set Pin 1 ON
THEN Set Pin 2 OFF
THEN Set Pin 3 ON
THEN Set Pin 4 ON
THEN Set Pin 5 ON
THEN Set Pin 6 OFF
THEN Set Pin 7 ON
THEN Set Pin 8 ON
(Done in sequence, each one taking several cycles)
Now here is how it looks according to the method I'll be using.
Computer to Arduino:
Set these pins: 11111111
To these values:10111011
Total: 3 Bytes. Command-Mask-Values
Arduino:
Set pins like this: 10111011
(Done simultaneously)
These are obviously hypothetical examples. On the mega, the pins 1-8 occur on about 3 different registers.
But notice how much smaller the port method is. In fact, I was thinking of making unmasked write commands what would only use 2 bytes. The purpose of the mask byte is to filter out which pins I want to change and which ones I want to leave.
Some of this would almost be nice to do in Assembly.
Basically, I'm trying to give the Host computer the fastest low-level access I can. So that the software abstraction can tightly sync directly with the devices.