This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

watchdog timer

Other Parts Discussed in Thread: TMS470MF06607, HALCOGEN

hi,

i want to use the watchdog timer in my code. is there any reference code is avialable for it.

now i am trying to use the watchdog timer in the DCAN . when ever my code get blocked i want to reset my code.

can any one give me the sample reference code for the watchdog timer.

regards

Arun kumar.N

  • Hi Arun,
    If you go the HalCoGen->Help->Help Topics->Examples there is an example_dwwd.c with instructions on setting up a window watchdog.
  • hi sir,
    i saw that example. i am using TMS470HDK . in the tms470mf06607 microcontroller, for watchdog timer only few function are there.
    what are the function they are used in the example, that function are not there. so can you please give the referrence code for TMS470MF06607 microcontroller.


    regareds
    Arun kumar.N
  • Hi Arun,

      You just use the HalCoGen to enable the DWD. In the below example, I configure the DWD window to be 10ms. Within 10ms you must write a WD key to avoid a watchdog reset.

      In your code all you need to do is to call the rtiReloadDWD() within 10ms. That is all you need. 

     

  • hi sir,

    what ever you saidto me , i did the same. but i dont know how to give the WDKEY value to avoid the immediate reset. i tried in my code for 500ms , 1 sec, & 2sec . but my code was reset immediately . can you please tell me how to calculate that WDKEY value. from the datasheet i understand the downcounter value is start from WDKEY = E5A1 , to WDKEY = A35C is it corect or not sir . what is limitation of the DWD timer .( upto which time i can avoid the watchdog timer reset ) .
    can u please tell me how to set the watchdog timer WDKEY value sir.


    regards
    Arun kumar.N
  • Hi Arun,
    Did you write the WDKEY yourself or you call the rtiReloadDWD() API?

    You said "downcounter value is start from WDKEY = E5A1 , to WDKEY = A35C is it corect or not sir ." Here the WDKEY should be 0xE51A followed by 0xA35C. However, you wrote E5A1, not E51A. This is why I want to know if you call the API or you wrote these two values to the RTIWDKEY register.
  • hi sir,

    i call the rtiReloadDWD()API function , in the rtinotification() function. In that rtinotification only i changed that out value .

    In my code i tried to after 5sec only reset want to be occur. but its reseted immediately.
    for your reference i attached my code downside .

    program:

    sys_main.c

    #include "sys_common.h"
    #include "system.h"
    #include "rti.h"
    #include "het.h"
    #include "esm.h"
    #include "can.h"

    uint8 tx_data[8] = {'A','R','U','N'};
    uint8 i=0;
    void main()
    {
    _enable_IRQ();
    rtiInit();
    canInit();
    i=0;
    while(i<5)
    {
    canTransmit(canREG1, canMESSAGE_BOX1, tx_data);
    i++;
    }
    rtiEnableDWD(); // if i am putting stop pointer here means the can data is transmitted. other wise its
    } // keep on reseted.


    notification.c

    void rtiNotification(uint32 notification)
    {
    rtiReloadDWD();
    }



    rti.c


    void rtiEnableDWD(void)
    {
    rtiREG1->DWDPRLD = 0x0000bebbU;
    rtiREG1->DWDCTRL = 0xA98559DAU;

    rtiREG1->WDKEY = 0xE51AU;5
    rtiREG1->WDKEY = 0xD192U; // i changed this value for avoid the reset for 5 sec
    }



    void rtiReloadDWD(void)
    {
    rtiREG1->WDKEY = 0xE51AU;
    rtiREG1->WDKEY = 0xD192U; // i changed this value for avoid the reset for 5 sec
    }



    what are the mistakes i did it here. i dont know sir. can u please let it to me know.


    regards
    Arun kumar.N
  • Hi,

      There are two major issues.

      1. Why are you changing the code inside rtiEnableDWD() API? You altered the WDKEY from the right key (E51A followed by A35C) to the wrong key (E51A followed by D192). When you call rtiEnableDWD(), it first enables the WD function because of the rtiREG1->DWDCTRL = 0xA98559DAU instruction. Afterward, you write a wrong key that immediately trigger a reset.

      2. The WD is meant to generate a reset, not an interrupt. When a WD reset happens, it will never go to the rtiNotification(). The rtiNotification() is an handler for the RTI interrupt. 

  • hi sir,

    now i change in my code. what ever th value is generated by the holcogen i did not change that WDKEY value.
    but now also its rested immediately .

    In my code for checking purpose i enable DCAN1 . here in the loop i transmit the DCAN1 data five times . after transmitting five times i am used that rtiEnableDWD() API function.

    In the HOLCOGEN i enable DWD and in the watch window i am putting the value 5000 ms ( 5sec ) .

    so after transmit the DCAN data five times , my program want to wait upto 5sec. but its not waiting . its reseted suddenly .

    can u please tell me , any thing i want to do extra from my program side , or HOLCOGEN side .

    program
    #include "sys_common.h"
    #include "system.h"
    #include "rti.h"
    #include "het.h"
    #include "esm.h"
    #include "can.h"

    uint8 tx_data[8] = {'A','R','U','N'};
    uint8 i , tx_ptr;
    uint32 tx_done;
    void main()
    {
    _enable_IRQ();
    canInit();
    canEnableErrorNotification(canREG1);

    for(i=0; i<5; i++)
    {
    canTransmit(canREG1, canMESSAGE_BOX1, tx_data);
    while(tx_done == 0){};
    tx_done=0;
    }
    rtiEnableDWD(); // ENABLE THE DWD
    }


    void canMessageNotification(canBASE_t *node, uint32 messageBox) // in the main i declare this function and command in the
    { // notification.c
    if((node == canREG1) && (messageBox == 1))
    {
    tx_done =1;
    }
    }


    rti.c

    void rtiEnableDWD(void)
    {
    rtiREG1->DWDPRLD = 0x0000bebbU;
    rtiREG1->DWDCTRL = 0xA98559DAU;

    rtiREG1->WDKEY = 0xE51AU;
    rtiREG1->WDKEY = 0xA35CU;
    }

    regards
    Arun kumar.N
  • Hi,
    I think the problem is that you only loop for five times. After you transmit the CAN five times, you no longer call rtiEnableDWD(). The WD counter will eventually expire to generate reset.
  • hi,

    actually the DCAN transmision is not more than 1 sec . if i am transmit only one time also , the reset happens suddenly .
    because of reset its keep on transmittiing . in the DWD watch window i put the value 5000(ms).
    if i transmit only one time means at the first time it want to be transmit , after five sec only it want to transmit again because of the DWD reset.
    but its keep on transmit with out any time interval.

    can you please give one small reference code . and tell me the procedures i want to do in the halcogen . its little bit help full to me to understand that DWD .


    REGARDS
    Arun kumar.N
  • Hi,
    The moment you enable the WD the WD counter starts down counting. Before the counter counts to zero you must write a WD key so the counter is reloaded from its preload value. So what happens is that you enable the WD and now the counter is counting. You then start the CAN transmission. Let's say it takes 0.5 second to transmit the the CAN. After 0.5s, you call the rtiEnableDWD() which will write the WD key to reload the WD counter. Everything is fine so far. But what about 5 seconds later. You have no more call to the rtiEnableDWD(). This is what it resets. Once it resets, the CPU starts from beginning again. It will eventually enter the main() function and start the WD counter and then transmit the CAN again. But again you code has only one time call to the rtiEnableDWD(). After 5 seconds it will reset again and you are repeating the this process forever.

    You can create a periodic timer like every 4 seconds or any timer value that is less 5 seconds. In your timer interrupt you can write the WD key so the WD reset will not happen.
  • hi sir,

    sorry sir, i cannot understand what you are telling.
    after CAN transmission i enable the DWD. so after DCAN transmit the data , it comes to the watchdog timer . here i enable the watchdog timer. The watchdog timer value is 5 sec . now my code was stopped in the while(1) loop . so my code was stop here. after 5sec , DWD counter reach zero , and it will reset my code means again my code will start from the beginning means then its correct .
    but here after CAN transmit ( 0.5 sec) , its again reset the code . with out complete the 5sec how it will reset the code.

    ques 2 : sir, i make my own scheduler . in the main i enable the DWD . After enable every drivers my code is entered in the while(1) loop
    [ scheduler loop ] . each and every one second i reload the DWD value . so when ever my code will block then only DWD will reset my
    code, and again it will start from the main() . but here also its keep on reset my code .
    i did not change any WDKEY value . so what is the problem i did't know .

    can you please tell me the sollution for this problem.


    regards
    Arun kumar.N
  • Hi,

     First of all, can you use the scope to monitor the nRST pin and can you confirm that for the first time you get a reset 5 seconds after the CAN message and after the device is reset it repeats the CAN message but in this time the reset is fire immediately after the message.

     The reason I'm asking is because I think there is a bug in the halCoGen.  Please tell me if below is what you configured with 5000ms entered for the window and the RTICLK=80MHz. If this is your setup then the HalCoGen will write 0xbebb to the DWDPRLD register. Here is the problem. Per the DWD userguide, the DWDPRLD field is only 12bits, not 16bit. This means that when you try to write 0xbebb to the register, only the 0xebb is written. With 0xebb or (3771 decimal value), it translates to a window of 3711*8192*12.5ns which is about 0.3second. After you transmit the CAN, it should take about 0.3s to reset, not 5s. 

  • hi sir,

    yes sir, i got what mistake i did it here. now my code generate proper reset after the particulare time. i check my code in the scheduler also its working good. thanks for your help sir.

    regards
    Arun kumar.N