Menu

Timer1 maximum control

Help
Capaction
2011-03-24
2013-05-30
  • Capaction

    Capaction - 2011-03-24

    I have a calculation to do from timer count.
    Why  this code does not work at the DO  LOOP begining ?

    **…/…
    On Interrupt CCP1 Call PulseReceived

    T1CON = b'00001001'  "Set up timer1 PS1_1/1
    ClearTimer 1
    StartTimer 1

    Do

    LEDoff

    TimerMax:
    If TimerCount > 65500 Then "word variable Alias TMR1H,TMR1L
    LEDon
    ClearTimer 1
    wait 100 ms
    StartTimer 1
    Goto TimerMax
    End If

    …./….
    Code with calculation from TimerCount As Word Alias TMR1H,TMR1L
    and use of CCP1 Capture or Compare

    …./….

    LOOP
    **

     
  • gcha44

    gcha44 - 2011-03-24

    Hi,
    In sub  "Pulsereceived" , do you increment Timercount  ( Timercount ++) for each overflow ?

     
  • Nobody/Anonymous

    YES but Pulse received will be called when the motor runs.
    The purpose of the TimerCount  test is to put the LEDon  when the modor is not runing and clear the Timer1 to 0

    Sub PulseReceived (TimeCount As word, CapturedTime As word)
    TimeCount = CapturedTime   ' store Alias CCPR1H,CCPR1L
    Set CCP1IF = 0 ' Clear CCP Interrupt Flag
    PilotCounter += 1 ' increment
    IF PilotCounter = 5 Then PilotCounter = 1 ' ready for new revolution
    End Sub

     
  • gcha44

    gcha44 - 2011-03-25

    I don't know what value your clock has but if you don't  stop  timer1 before  Ledon  Cleartimer 1 , an interupt can occurs  and sub pulsereceived will be called again  before wait 100 ms  is achieved .

     

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.