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 
 Forum index » DIY Hardware and Software » Microcontrollers and Programmable Logic
need help undertanding AVR /ARDUINO timers and interrupts!
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
loss1234



Joined: Jul 24, 2007
Posts: 1536
Location: nyc
Audio files: 41

PostPosted: Thu Feb 10, 2011 11:50 am    Post subject: need help undertanding AVR /ARDUINO timers and interrupts! Reply with quote  Mark this post and the followings unread

hello there


I have been working with Arduino for a couple weeks now

I can get it to do some simple things but much is still a mystery


I am trying to make a program that reads from an ANALOG INPUT for let's say ONE second and dumps what it reads into an ARRAY.


the problem is this

though I know how to read from the analog pins, put the data from them into a function called VAL, I do not know how to do any such thing in regards to TIME...and since an array would fill up far too quickly if done all at once, I thought that maybe the array could read what is on the PIN every second or every-time some kind of event took place ( an overflow?)

but this would take me understanding how to use the clock, the timer, the interrupts?etc


so....where to start? any advice? hints, etc?

i get the feeling that to do anything powerful with an Arduino/PIC you have to understand arrays and timers....


thanks so much

_________________
-------------------------------------------- check out various dan music at: http://www.myspace.com/lossnyc
http://www.myspace.com/snazelle
http://www.soundclick.com/lossnyc.htm http://www.indie911.com/dan-snazelle
Back to top
View user's profile Send private message
Skellz



Joined: Dec 31, 2008
Posts: 18
Location: Ireland

PostPosted: Mon Feb 14, 2011 5:24 pm    Post subject: Reply with quote  Mark this post and the followings unread

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261124850 Arduino forum post

http://www.uchobby.com/ Very in depth tutorial, site is down at the moment

http://interface.khm.de/forums.html/lab/experiments/arduino-realtime-audio-processing/

ProtoStack Tutorials
http://www.protostack.com/blog/2010/06/introduction-to-io-registers/
http://www.protostack.com/blog/2010/09/timer-interrupts-on-an-atmega168/#more-235
http://www.protostack.com/blog/2010/09/external-interrupts-on-an-atmega168/#more-209

Ok here is a probably inaccurate explanation as i only just started my self.
The arduino has 3 timers and each timer has several settings that have to be set up for the task at hand. Timers can be set up to trigger special sections of code called interrupt service routines. When the trigger happens arduino stops what it is doing and runs through the interrupt service routine then returns to where it was in the program when the trigger happened.

So if you wanted to sample audio you would set up your timer to trigger an interrupt service routine at audio rate, eg 8khz and place an analogRead() in the service routine, if you wanted to play back audio you would place an analogWrite() or place code that would send the audio to a dac in the interrupt service routine.

Now here is the easy part
The settings for the timers are held in special registers. Each register has 8 bits and usually each bit is a setting for the timer. So you have to change the state of each bit individually, in C you can use the bitwise operators to manipulate individual bits http://en.wikipedia.org/wiki/Bitwise_operation

And just to add to the confusion, there are avr specific commands for manipulating register bits.
Im pretty sure cbi means clear bit and sbi means set bit

sbi(ADMUX,REFS0);
cbi(ADMUX,REFS1);


Also check out the data sheet from atmel it has a description of the registers. The uchobby link also has a very detailed description of the registers your interested in.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: State Machine
Page 1 of 1 [2 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 » Microcontrollers and Programmable Logic
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