Timing out DT's Blinking Led


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Timing out DT's Blinking Led

    I've been experimenting, if one could call it that, with Darryl Taylor's Interrupts and have another question.

    How could I use the Blinky Led example to execute the toggleled but time itself out after a few seconds?

    '************************************************* ****
    Example from Darryl's website:
    LED1 VAR PORTB.1

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    T1CON = $31 ; Prescaler = 8, TMR1ON
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

    Main:
    PAUSE 1
    GOTO Main

    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
    TOGGLE LED1
    @ INT_RETURN


    '************************************************* ****
    I thought at first writing a
    main:
    @ sleep
    @ nop
    goto main

    ToggleLED1:
    TOGGLE LED1
    REPEAT
    i = i +1
    UNTIL i > 10
    If i >= 10 then
    T1CON = $0
    @ INT_RETURN

    Well that through a wrench in my work, because for one it through off the led timing, makes it Slowwww... and second it just repeats itself because later I tried to add a:
    main:
    High LED1
    pause 250
    LOW LED1
    @ sleep
    @ nop
    goto main

    and I see the toggling of the led with the pause I added.

    Anyhow, I am still tinkering and haven't burn anything up yet. Thanks for any suggestions

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You could increment a couter variable in your interrupt, and just disable the interrupt after x number of counts.

    The big problem however is with Timer1. It stops working during sleep since the oscillator is shut off in sleep. You would need to setup Timer1 with an external oscillator for it to run during sleep periods.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks Bruce for your suggestion.
    The idea I was toying with was to toggle the led for a few moments then time out and go to sleep, ...I then added to the main: the high led/low led to signal that it had returned from the ToggleLed1. Then sleep....

    Thanks again for the reply.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The reason your first version is WAY slow is because Timer1 shuts down during sleep. When the WDT wakes it from sleep, you only have 1 nop and the GOTO Main instruction cycles before it goes back to sleep.

    So it takes Timer1 a really long time to increment to overflow with a prescaler of 1:8.

    Just increment a variable in the interrupt handler, and check it for a certain value in Main. When it reaches the pre-set value, disable Timer1 and go to sleep.

    You can re-enable it as needed.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts