Menu

help on timer1

Help
2011-03-03
2013-05-30
  • Nobody/Anonymous

    here is the code so far, will this work? do i need to set the offset only once or every cycle? and will this be accurate or do i need to adjust for instruction cycle times?
    #chip 12F683, 18
    #config MCLRE=off, WDT=off

    on interrupt Timer1Overflow call IncCounter

    InitTimer1 ExtOsc, PS1_8
    dim full as byte
    dim min as byte
    dim sec as byte
    dim hr as byte
    full = 0
    wait 2 s

    ClearTimer 1
    TMR1L = 0 'Need to do this according to the PIC datasheet
        TMR1H = 36
        TMR1L = 13 'should be 10hz
    StartTimer 1

    main:

    goto main

    Sub IncCounter
    full=full+1
    if full = 10 then sec=sec+1

    if sec = 60 then
    min= min+1
    sec=0
    end if

    if min= 60 then
    hr=hr+1
    min=0
    end if

    if hr=25 then hr=0

    end sub

     
  • gcha44

    gcha44 - 2011-03-04

    Hi ,
    Yes you must reload TMR1H and TMR1L with their value in your sub IncCounter or else clock will be false

    and instead of

    "if full=10 then sec=sec+1"

    you may write

    if full=10 then
        sec=sec+1
        full=0
    end if

    otherwise full will increase to 255 then will stop ! Its value will never be =10

    regards
    GC

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.