Timing problem in At tiny 13

zerostar

Member
Hi,

How to calculate the time correctly when programming At tiny 13?

I want to delay 4s in 9.6mHz At tiny 13, What is the time should I use?

Also, the delay time is changing and not keep as constant when testing, any reason for that?

Thanks.!
 
To get exact timing sources on an AVR Controller, you should use a Timer that generates Interrupts.
At 9,6MHz and a 8 Bit Timer You had to use a Prescaler for the Timer - I think 1024 goes OK.
When the Count's of an Overflow Register ( RAM Variable ), thats countet up in every Interrupt routine achieves his goal value, you can set a flag, or do some action you want.
To get exact 4 Seconds, you have to preload the TCNT register of the used Timer.
To check the Timing you can simulate your Code in AVR Studio 4.xx or 5.xx. So You can check if Your calculations are right.
 
I assume that you are using avr-gcc and avr-libc. For software delay there is the delay-function:
https://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

But, like wkrug said, it is better to use the timer/counters. I would use compare match -interrupt instead of overflow -interrupt. Compare interrupt gives more accurate timing.
 
i know how to programme attiny13 by arduino,
however, the delay time is not right.

I want to delay 4s in 9.8mHz MCU, so that : 4000/9.8=408.1ms,(am i right?)

but it doesnt work
 
I am a little confused what exactly is the problem.. are you using timer/counter or the delay-function?

Did you watch the video all the way through? Maybe you have a similar problem that the guy had in the video.. Arduino IDE assumes 9.6 Mhz clock, but the Attiny is actually running at the default 1 Mhz.

Direct link to the right spot in the video: https://www.youtube.com/watch?feature=player_detailpage&v=p-fieBPj9Ng#t=414s
 
Opps... this is exactly my problem,thank!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…