Pages: [1]   Go Down
Author Topic: pin port differences between Arduino boards.  (Read 1116 times)
0 Members and 1 Guest are viewing this topic.
North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 53
Posts: 1786
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,
Just have a few questions about the internals of the different boards.

Does the MEGA 1280, MEGA 2560, MEGA ADK have the same port register layouts?
and the same question for the Uno revisions.

Also does anybody know how much EEPROM is taken up by the core?

I want to try and create a more efficient set of functions replicating the 'pinMode', 'digitalRead', 'digitalWrite', etc...
This will allow me to at least remove some arrays listed below and remove the PROGMEM access overhead.

This is only an experiment but I'll have big memory savings and speed increases if it works.

Code:
//From Arduino.h

extern const uint16_t PROGMEM port_to_mode_PGM[];
extern const uint16_t PROGMEM port_to_input_PGM[];
extern const uint16_t PROGMEM port_to_output_PGM[];
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];

Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Does the MEGA 1280, MEGA 2560, MEGA ADK have the same port register layouts?
and the same question for the Uno revisions.

As far as I know, the layouts are by processor family.  A quick search at Google...
https://www.google.com/search?q=atmel+1280+2560
...indicates that the 1280 and 2560 have the same datasheet so they are in the same family.  Which means the MEGA 1280, MEGA 2560, MEGA ADK all have the same pin to port/bit mapping.  The same is true for the Uno revisions.

Quote
Also does anybody know how much EEPROM is taken up by the core?

The core does not use the EEPROM.  I believe there are plans to use the end of the EEPROM for network configuration on future boards.

Quote
I want to try and create a more efficient set of functions replicating the 'pinMode', 'digitalRead', 'digitalWrite', etc...
This will allow me to at least remove some arrays listed below and remove the PROGMEM access overhead.

Do you mean something like this...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267553811
http://code.google.com/p/digitalwritefast/
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 53
Posts: 1786
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply, I am still learning about arduino, but as these macros below are used by 'pinMode' and stuff, does this not mean the use EEPROM?

Code:
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )

Also those arrays I posted above use the PROGMEM  keyword.

The digitalWriteFast looks great, in fact it was a really great read. I need to test it and see how much runtime code is generated to do its final port manipulation. My plans will hopefully shave a few more instructions off into compile time. But it may have already knocked these ideas on their head.

Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply, I am still learning about arduino, but as these macros below are used by 'pinMode' and stuff, does this not mean the use EEPROM?

They use Flash (section of memory where code is stored).

Quote
Also those arrays I posted above use the PROGMEM  keyword.

PROGMEM tells the linker to place the declaration exclusively in Flash.
 
Quote
The digitalWriteFast looks great, in fact it was a really great read. I need to test it and see how much runtime code is generated to do its final port manipulation.

One machine instruction if the pin and value are constants and the port is in "low" memory.  I think it's three (six if interrupts are disabled) machine instructions if the port is in "high" memory (only applicable to the 1280 family).  If pin is a variable the "old" function is used.  I have no idea how it handles a variable value.

Teensyduino has a variation that really squeezes the best possible speed out of the functions.

Quote
My plans will hopefully shave a few more instructions off into compile time. But it may have already knocked these ideas on their head.

I wish you the best of luck!  I'm a big fan of tweaking the core.
Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10442
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just for completeness the microcontroller has 3 (or possibly 4 if you count the fuses) memories.  RAM, EEPROM and FLASH

The EEPROM can be written byte-by-byte but the FLASH is only programmable/erasable in blocks (otherwise they are similar conceptually, hence the confusion.  Its the individual addressing for erase than marks EEPROM out.  That and being slow to write and having more limited wear life.
Logged

[ I won't respond to messages, use the forum please ]

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 53
Posts: 1786
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Cheers mate, yeah, I just had mixed up the names.
Logged


Pages: [1]   Go Up
Jump to: