Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 16 bit timer 30 mins delay

Status
Not open for further replies.

sammey_geek

Junior Member level 1
Joined
May 22, 2013
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,395
hi..i am working on attiny88.... i want to turn off light after 30 mins....for that i am using a 16 bit timer... and system clock is 4Mhz.....for 4Mhz= 1/4000000 =0.00025 ms. so it takes 0.00025 ms per tick.... for 65535*0.00025 = 16.383 s. the max delay is 16.383 sec....how could i get 30 mins of delay...can anyone explain me with code.....




thank you,
 

Is there a prescaler on the clock? If you divide the clock by 128 for example, your max delay is now 65535*0.00025*128 = ~2097 seconds or almost 35 minutes. Look to see if your timer has a prescaler on the clock input and play around with the divisor and timer values to get the correct timing. I use PICs so i can't comment on what is available in your chip.
 

The ATtiny88 offers a clock prescaler which divides the system clock frequency by 8, 64, 256 or 1024 before input to Timer0 or Timer1.

Reference: ATtiny48/88 Datasheet, Section: 13.1 Internal Clock Source, Page: 117
13.1 Internal Clock Source

The Timer/Counter can be clocked directly by the system clock (by setting the CSn[2:0] = 1).
This provides the fastest operation, with a maximum Timer/Counter clock frequency equal to
system clock frequency (fCLK_I/O). Alternatively, one of four taps from the prescaler can be used
as a clock source. The prescaled clock has a frequency of either fCLK_I/O/8, fCLK_I/O/64,
fCLK_I/O/256, or fCLK_I/O/1024.

AVR Timers – An Introduction


BigDog
 
hi..tanx for reply.....

1024 is the maximum prescaler divisor..though i use it..i wont get required delay.....is there any other way to get 30 mins of delay??
 

your max delay is now 65535*0.00025*128 = ~2097 seconds or almost 35 minutes
2097 sec or 2097 ms?

1/4MHz = 0.00000025 Sec = 0.00025 ms = 0.25 us

F_CPU = 4 MHz
Prescalar = 1024
Timer is 8 bit

4MHz/1024 = 3906.25 Hz

Timer interrupt occurs every 0.065536 sec

Increment a counter every interrupt.
When Interrupt is 27466 time will be 30 minutes.
 
Last edited:
You're right. I just noticed my time units were inconsistent in my post above. If you can't decrease your system clock, you'll need to use a second register to keep track of how many times the 16 bit timer rolls over.

Bigdogguru states that your prescaler options are 8, 64, 256, and 1024 for the ATTiny44/88. If you use a prescale of 1024, that means for every 1024 ticks of your 4 MHz system clock will increment your timer by 1. So for every tick of the timer, that equals 1/4Mhz * 1024 or 256uS. The maximum delay through the 16 bit timer is 65535 * 256uS or ~16.78 seconds. So instead of running the full range of the timer, select a convienent value like 8 seconds. Now your 16 bit counter only has to count up to 31,250 (8 seconds/256uS). I guess you can pre-load the timer with 65,535-31,250 and track the interrupt as it rolls over. Now you have a timer that runs for 8 seconds. Use a second register to count to how many 8 second intervals have passed. Since there 1800 seconds in 30 minutes, the second register needs to count to 225.

I used nice, round numbers to make the math easier but the concept can be used to set your delay. I'm sure it's not exact as there are incruction cycles that are not accounted for but it should be pretty close.
 
In brief, just add one or more registers as extended counters to get any required delay time.
 

hi.....tanx to u all..... it worked.....like spudboy488 said...i intialised timer for 4Mhz and interrupt trigger at 8 sec....and in isr i incremented counter to 225..... it gave 30 mins delay......Bingo :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top