# changing interrupt rates

• 11-12-2005
rexnprogress
changing interrupt rates
i have a program that causes an LED on an 8051 controller to blink 5 times a second. here is what controlls the timer interrupt:

Code:

`Timer3_Init (SYSCLK / 12 / 10);`
using a system clock at 12 mHz, the timer will create interrupts at a 10Hz rate. How would i make it interrupt every 1/4 of a second?
• 11-12-2005
Dave_Sinkula
A guess:
Code:

`Timer3_Init ( (10 * SYSCLK) / 48);`
• 11-12-2005
rexnprogress
thank you.

any guess on the effect of changing just the last number on the original interrupt?
• 11-12-2005
Dave_Sinkula
Code:

`Timer3_Init ( SYSCLK / 12 * 5 / 2 );`
• 11-14-2005
rexnprogress
if you cant tell im totally new to C. i can find my way through C+, but this is all screwy so im going to have to disassemble existing code (with help from whoever wants to) to figure it out. and im using a silicon labs 8051fx20 IDE

im working with timers and interrupts to make a traffic light simulation. i want to alter some existing code to suit my needs.

ive changed the intial timing of the interrupt from 5 times a second:
Code:

`Timer3_Init (SYSCLK / 12 / 10);`
to
Code:

`Timer3_Init (SYSCLK / 12 / 12);`
in order to hopefully get 4 times a second (if 10 = 5 times a sec, then 50 = 1 sec, 50/4 = 12.5).

i am hoping i can use a delay or sleep function and just put it how many ms i want it to wait(to bypass all the machine cycle and timer overflow stuff), but i dont know if i can with the IDE.

i need to use the LED on the board (P1.6) as the green light, and use a series of while loops to switch the ports on and off.
ie: main street will use P1.0, P1.1, and P1.6 for the red, yellow and green respectively. side street uses P1.2, P1.3, and P1.4.

[psuedo]
Code:

```while (delay <= 25000)     turn P1.6 on     turn P1.2 on while (delay >= 25001)     turn P1.6 off     turn P1.1 on while (delay >= 29001)     turn P1.0 on     turn P1.1 off     turn P1.2 off     turn P1.4 on while (delay >= 54001)     turn P1.4 off     turn P1.3 on if (delay > 58000)     clear delay     restart delay```
[/pseudo]

if its possible to do what i want, how could i restart the delay and create an infinite loop?
if i cant use delay, then im stuck with machine timers and overflows...ugh

any insight is much appreciated
• 11-14-2005
Dave_Sinkula
Go through the app notes. Try to find something on using the timer interrupts. Read up on whatever vendor documentation you can find about your Timer3_Init() function and its friends.

Also, here appears to be a more specific forum.
• 02-16-2011
liakofan
I am also very new at this and try to learn,

what if i want to change the interrupts of the LED each time i press a button....

i insert in the code: if ( p3,6 == 0 ) Timer3_Init (SYSCLK / 12 / 14);

else

Timer3_Init (SYSCLK / 12 / 10);

but it does not work......

i know it is very easy, can anyone help?