• AVR Freaks

Hot!Pic18F47K42 Timer1 as a WDT

Author
dj_dan23
Starting Member
  • Total Posts : 52
  • Reward points : 0
  • Joined: 2014/12/03 17:25:22
  • Location: 0
  • Status: offline
2019/02/27 21:40:31 (permalink)
0

Pic18F47K42 Timer1 as a WDT

Hi!!! all. I would like to know what is the best way to reset the time1 before going to the ISR.
I have a Chronodot RTC that output 1hz feed to the PIC for the SDCard data logger section. 
I would like to be sure that this 1hz is running, so I use Timer1 with a time of 1.2 sec with a
ISR that will give an error if the timer1 ever goes to interrupt, meaning that the 1hz didn't arrive.
So I need to reset the Timer1 with my 1hz input, before it goes interrupt. Then restart it for
the next 1hz.
To me it seems like a WDT for my 1hz.
The only thing that I miss is the way to reset and restart the Timer1 at each 1hz input.
PIC18F47K42 and MPLAB X IDE 5.10 and XC8 2.00.
Thanks for your help.
 
 
 
#1

6 Replies Related Threads

    qhb
    Superb Member
    • Total Posts : 9998
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Pic18F47K42 Timer1 as a WDT 2019/02/27 21:53:47 (permalink)
    0
    HOW have you fed the 1 Hz signal to the PIC?
    Is it connected to an interrupt pin?
     

    Nearly there...
    #2
    Mysil
    Super Member
    • Total Posts : 3325
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: Pic18F47K42 Timer1 as a WDT 2019/02/27 23:37:48 (permalink)
    +1 (1)
    Hi,
    If Timer1 is clocked by internal Instruction Clock FOSC/4, or a clock signal that is synchronized with FOSC/2,
    then:
        TMR1H = RestoreValue >> 8;
        TMR1L = RestoreValue & 0x00FF;
    when RTCC update have been processed.
     
    Note that buffered timer Read / Write mode RD16 should be enabled.
     
    Edit:  This sentence in Datasheet  DS40001919C-page 307,  section 21.5    is wrong:
            When a write request of the TMRxL register is
            requested, the TMRxH buffer register is simultaneously
            updated with the contents of the TMRxH register.
    Sentence should rather be:
            When a write request of the TMRxL register is
            requested, the TMRxH  register is simultaneously
            updated with the contents of the TMRxH buffer register.
            The new value for TMRxH must be preloaded into the
            TMRxH buffer register prior to the write request for the TMRxL
            register. This provides the user with the ability to write
            all 16 bits to the TMRxL:TMRxH register pair at the
            same time.
     
        Mysil
     
    post edited by Mysil - 2019/02/28 00:04:05
    #3
    AMAK
    Super Member
    • Total Posts : 51
    • Reward points : 0
    • Joined: 2014/08/05 10:45:57
    • Location: 0
    • Status: offline
    Re: Pic18F47K42 Timer1 as a WDT 2019/02/28 09:05:16 (permalink)
    0
    I would recommend using the Timer2 for this application. The Timer2 has a built in hardware limiter which can reset the timer automatically if your 1Hz signal is alive or generate an interrupt if that signal doesn't arrive. 
    #4
    dj_dan23
    Starting Member
    • Total Posts : 52
    • Reward points : 0
    • Joined: 2014/12/03 17:25:22
    • Location: 0
    • Status: offline
    Re: Pic18F47K42 Timer1 as a WDT 2019/02/28 11:07:45 (permalink)
    0
    Thanks for your response.
    Yes I have interrupt for the 1hz = "void __interrupt(irq(8),high_priority) Ext_ISR(void)"
    on RB0 , and the Timer1 = "void __interrupt(irq(TMR1),high_priority) T1_ISR(void)"
    working. But I don't know how to reset and restart the Timer1 if I receive the 1hz.
     
    By the way, do you know where I can find the IRQ name list, cause I must use irq (8).
    I tried "TMR1" and it worked , but haven't been able to do the same with INT0. Smile: Smile
     
    I look to the next reply telling to use TIMER2, could be a good choice too. But for now
    I will study this one. Thanks again.
    #5
    jack@kksound
    code tags!
    • Total Posts : 3188
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: Pic18F47K42 Timer1 as a WDT 2019/02/28 11:20:09 (permalink)
    +1 (1)
    Read the sections on the timer2 in the datasheet paying particular attention to this: 22.5.3 EDGE-TRIGGERED HARDWARE LIMIT MODE. You would set the PPS input for timer2 to the input pin where your 1hz signal appears and select the T2INPPS mode, see REGISTER 22-2: TxRST: TIMER2 EXTERNAL RESET SIGNAL SELECTION REGISTER. Set timer2 for the required interval (1.2 s) and configure the timer2 interrupt to do whatever you need to do if the 1hz signal is not received. REGISTER 22-6: TxHLT: TIMERx HARDWARE LIMIT CONTROL REGISTER lists the settings to select the hardware limit mode of operation (you want the free run mode with external hardware reset).
    #6
    dj_dan23
    Starting Member
    • Total Posts : 52
    • Reward points : 0
    • Joined: 2014/12/03 17:25:22
    • Location: 0
    • Status: offline
    Re: Pic18F47K42 Timer1 as a WDT 2019/02/28 19:28:40 (permalink)
    0
    I just take a look and it seems quite what I want to do. So tomorrow I will try this setup.
    22.5.3 Edge-Triggered Hardware limit mode (Figure 22-6) look perfect. wink: wink
    Thanks for the tip. Nice to have you guys.
    #7
    Jump to:
    © 2019 APG vNext Commercial Version 4.5