changing interrupt rates

This is a discussion on changing interrupt rates within the C Programming forums, part of the General Programming Boards category; i have a program that causes an LED on an 8051 controller to blink 5 times a second. here is ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    7

    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?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    A guess:
    Code:
    Timer3_Init ( (10 * SYSCLK) / 48);
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    7
    thank you.

    any guess on the effect of changing just the last number on the original interrupt?

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    Timer3_Init ( SYSCLK / 12 * 5 / 2 );
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    7
    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

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    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.

    [edit]Also, here appears to be a more specific forum.
    Last edited by Dave_Sinkula; 11-14-2005 at 05:21 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Feb 2011
    Posts
    1
    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer within a Struct
    By Bladactania in forum C Programming
    Replies: 11
    Last Post: 04-03-2009, 11:20 PM
  2. DOS, Serial, and Touch Screen
    By jon_nc17 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 01-08-2003, 04:59 PM
  3. interrupt question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-08-2002, 09:25 PM
  4. interrupt handler functions in Visual C++ 6.0
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-07-2002, 07:06 PM
  5. Sound card interrupt problems
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-05-2001, 04:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21