Pages: [1]   Go Down
Author Topic: Ports on the Arduino Mega Pins 22-53  (Read 808 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 85
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I need to turn digital pins 22-53 on the mega 2560 on and off really (really) fast. No inputs being processed just switching on Mux's how do I manipulate the ports to do this? I cannot find a good example.

Thank you
Logged

Offline Offline
Sr. Member
****
Karma: 9
Posts: 254
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have a look on here: http://arduino.cc/en/Hacking/PinMapping2560
This gives you the port letter that corresponds to the pin on the Arduino board (be careful the pin number on the chip is different from the board)
You can then write to that port to set the pins
For example PortB 0,1,2,3 are digital pins 53,52,51,50 respectively
Code:
PORTB=B00001111; //To turn them all ON (NOTE: this also sets PORT: B4-B7 LOW)
PORTB=B00000000; //To turn them all OFF (again sets B4-7 LOW)
PORTB|=B00001111; //To Turn them all ON, but not changing B4-7 (slightly slower but generally better practice)
PORTB&=B11110000; //To Turn them all OFF, not changing B4-7
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17305
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This one is helpful also:

https://spreadsheets.google.com/pub?key=rtHw_R6eVL140KS9_G8GPkA&gid=0

Lefty
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is also a Fast Digital Write library which claims to be much, much faster than the standard Arduino digitalWrite while providing a similar level of abstraction from the underlying hardware ports.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 85
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty,

I don't understand the spreadsheet I cannot find digital pins 22-53 on it.

Thanks

Bill
Logged

Germany
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
just sun
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

just look in the first column.
there are the arduino digital-pin numbers.
if you have find the number - for example Digital-Pin 7 you can follow the line and find that this arduino pin is on Port C 7
sunny greetings stefan
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17305
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lefty,

I don't understand the spreadsheet I cannot find digital pins 22-53 on it.

Thanks

Bill

Column one labeled Digital Pin has the 'Arduino' pin numbers going down the column. Find the row of the Arduino pin number you are interested in and the Port column of the same row will show the AVR port/pin number.

Lefty
Logged

Pages: [1]   Go Up
Jump to: