electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » Arduino
Working the Arduino I/O Ports in BYTE chunks
Post new topic   Reply to topic
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
State Machine
Janitor
Janitor


Joined: Apr 17, 2006
Posts: 2809
Location: New York
Audio files: 24

PostPosted: Thu Dec 20, 2012 5:57 am    Post subject: Working the Arduino I/O Ports in BYTE chunks Reply with quote  Mark this post and the followings unread

In case you need to work with more than just one PORT bit at a time, here is some good information on I/O PORT manipulation on the Arduino development platform.

http://arduino.cc/en/Reference/PortManipulation

This is also applicable to the read or write of any of the Atmega MCU hardware control registers.

For example, here is a section of code below I needed to write to control TIMER 5 of an Atmega1280 chip on the Arduino MEGA board to output a 2500 Hz, 500 ns pulse on an I/O port bit. You will need to reference the chip data sheet in order to understand what the actual data does:

// timer/counter 5 setup
TCCR5A = B00101001; // Phase and frequency correct PWM change at OCRA
TCCR5B = B00010001; // System clock Select (16 Mhz)
OCR5A = 3200; // Set to 2500 Hz
OCR5C = 4; // Init to .125 % (500 ns PW)

Hope this helps !

Happy Holidays !
Bill
Back to top
View user's profile Send private message Send e-mail
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Dec 20, 2012 6:39 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks!
Back to top
View user's profile Send private message
State Machine
Janitor
Janitor


Joined: Apr 17, 2006
Posts: 2809
Location: New York
Audio files: 24

PostPosted: Thu Dec 20, 2012 7:09 am    Post subject: Reply with quote  Mark this post and the followings unread

Your very welcome. I have seen this question come up here and there and though it was useful information. I have an example of a FIFO memory read routine I wrote and will post that as another example.

Sure beats reading in PORT bits one by one in a loop and assembling a byte in software (SLOW !!) when you can just read the FIFO a byte at a time and get on with processing the data.

Bill
Back to top
View user's profile Send private message Send e-mail
cappy2112



Joined: Dec 24, 2004
Posts: 2465
Location: San Jose, California
Audio files: 2
G2 patch files: 1

PostPosted: Mon Jan 07, 2013 9:59 pm    Post subject: Reply with quote  Mark this post and the followings unread

State Machine wrote:
Your very welcome. I have seen this question come up here and there and though it was useful information. I have an example of a FIFO memory read routine I wrote and will post that as another example.

Sure beats reading in PORT bits one by one in a loop and assembling a byte in software (SLOW !!) when you can just read the FIFO a byte at a time and get on with processing the data.

Bill


In case it's not obvious to others, the direct port I/O is much faster than digitalWrite(). I had posted some scope screenshots in an Arduino forum on another site, but I forget the actual speed differences.

_________________
Free Tibet. Release the Panchen Lama from prison. Let the Dalai Lama return to his home.
Back to top
View user's profile Send private message
State Machine
Janitor
Janitor


Joined: Apr 17, 2006
Posts: 2809
Location: New York
Audio files: 24

PostPosted: Tue Jan 08, 2013 8:17 am    Post subject: Reply with quote  Mark this post and the followings unread

Quote:


The bottom line here is that if digitalWrite() is "real time" enough and you dont care that the bits being manipulated are NOT time aligned, then use it. If speed is a requirment, then use direct port manipulation so long as the bit masking process involved, if required, while operating on single/multiple port bits does not bog your process down.

Bill
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Arduino
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use