ATTiny timers

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All, for the attiny85 it has two timers, if i make a program to loop through files, and i had a function that counted out an hour and turned of the circuit, would i need to use two timers?, or can i just use one and the timer function wouldn't really affect the music play?. And, if i had an interupt on a pin, waiting for a signal, would that pin/interupt need a second timer?

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You don't give much detail, but the answer is "probably not", that is, you probably wouldn't need two timers.  A single timer can perform many different timing functions with the right programming.  Go into greater detail.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll try it with one for the time being!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Set up one timer to do basic timing, say 10mS, then count the number of overflows to measure any time interval you need. 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

when the attiny85 plays a music file, it uses the timer interrupt to process a byte and sent it to the speaker as an analog signal?, also, if it does can i use the same interrupt to count?, can a 2nd interrupt be set up on the same timer?, and what would be less demand on the chip, using a 2nd timer or doing an occasional compare of say (OldUL < NewUL)?

AND, is a pin interrupt separate from the timer interrupt?

thanks heaps! 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do everything with the same Timer interrupt.
A PIN-CHANGE interrupt is different. Useful for high speed electronic hardware.
.
If you are monitoring a human operated button, it is best to do this with your regular Timer interrupt. e.g. read button(s) every 10ms. If it reads the same value for 5 consecutive periods, it is a "good" value.
.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How is the byte processing for the data from a sd card converted into analog signal and shunted out being triggered?, by a separate interrupt?, or by one i set?, and if i set the interrupt for it, then the timing for the interrupt is set?, and if the interrupt is set, then i would have to use an integer to work out milliseconds as the interrupt for music is 50ul !?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Playing PCM from an SD card is often (but not always) done using PWM. If you use an 8 bit timer then you can get 256 steps of PWM (OCR=0.. 255). The samples are likely 8kHz so you want to make 8000 changes of OCR per second. So the temptation might be to run  the timer so it overflows 8000 times but you want this Base frequency out of audio range so I would run the timer at 4 times 8kHz the reload OCR on every 4th overflow. So say you arrange to clock the AVR at 8MHz and you have 256 steps of PWM then you might run the timer at 8MHz / 256 = 31.25kHz overflows. So the timer period is 32ms. Hopefully you can also do whatever other work is to done as multiples of 32ms. If not then go wild and use a 2nd timer.