How to use timers in microcontroller


Today 18:50
Forum: Proton Plus Compiler v3
Starter: towlerg
Views: 0
Replies: 1
Today 00:44
Forum: Proton Plus Compiler v3
Starter: davroski
Views: 0
Replies: 4
+ Reply to Thread
Results 1 to 5 of 5

Thread: How to use timers in microcontroller23 days old

  1. #1
    Member amod's Avatar
    Join Date
    Mar 2018
    Posts
    111
    Thumbs Up
    Received: 105
    Given: 5
    Total Downloaded
    10.35 MB

    1 Not allowed!

    Default How to use timers in microcontroller

    Iam new to timers.how can I use them.

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Administrator John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,699
    Thumbs Up
    Received: 126
    Given: 33
    Total Downloaded
    3.92 GB

    0 Not allowed!

    Default Re: How to use timers in microcontroller

    The first thing to do is to download the datasheet for the processor you are using.
    Next, read the section on timers many times until you understand how they work.
    When you understand this you will see that you have to set the registers in your Basic program.
    Let us know when you have read the data sheet many times until you understand how the timers are controlled.
    The datasheet is your best friend.

    Best wishes
    John

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Junior Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    30
    Thumbs Up
    Received: 2
    Given: 1
    Total Downloaded
    76.29 MB

    2 Not allowed!

    Default Re: How to use timers in microcontroller

    As I suspect you want to solve your previous program, for the pic16F886 that you plan to use, there are three timers.
    If no where else is required to use a timer, the best attempt is to use the timer0. To calculate the period, I found this site extremely useful.
    So according your clock and the calculator you might opt for a counting for a millisecond or more. I prefer more in order to use just a byte for the counter.

    So for a standard 4MHz clock

    Just set
    Code:
    Declare Xtal 4
    On_Hardware_Interrupt GoTo Isr
    Symbol TMRSET = 99           ' Setting for internal clock
    Dim flags As Byte
    Dim zeroX As flags.4         ' flag for 1 second ticking
    OPTION_REG = 5               ' The options to set timer0 with 64 prescaler
    
    ' Rest of your program here
    End
    =======================================================
    Isr:
        Context Save
        If T0IF = TRUE Then      ' the timer0 overflowed ?
            TMR0 = TMRSET        ' then reload its count
            Clear T0IF           ' remove the flag
            If ticks < 101 Then  ' when the count reach 100, it's reset to zero
                Inc ticks        ' else it'll increase
            Else
                Clear ticks      ' reset
                Set zeroX        ' it records that one second is past
            End If
        End If
    Context Restore
    So by this snippet you will have a variable automatically updated every 10 milliseconds. Also the zeroX will be set once one second is reached. if you make an use of it then once is read must be cleared.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Junior Member Giuseppe's Avatar
    Join Date
    Jul 2019
    Posts
    6
    Thumbs Up
    Received: 0
    Given: 0
    Total Downloaded
    229.33 MB

    0 Not allowed!

    Default Re: How to use timers in microcontroller

    Excellent explanation Keytapper

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,279
    Thumbs Up
    Received: 380
    Given: 137
    Total Downloaded
    1.59 GB

    0 Not allowed!

    Default Re: How to use timers in microcontroller

    Nice one Keytapper.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Problem with the Timers.Inc include
    By knight in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 22nd September 2014, 19:53
  2. how to use timers and counters
    By Zain in forum Timer Modules
    Replies: 5
    Last Post: 30th March 2013, 18:24
  3. Timers and Sound
    By pic-ignorant in forum The Lounge
    Replies: 6
    Last Post: 13th June 2010, 04:03
  4. Does Proton use certain timers internally
    By brown in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 17th February 2010, 20:01
  5. Using timers, can't figure this out
    By goodman in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 2nd November 2009, 16:01

Posting Permissions

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