+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Newbie level 4
    Points: 37, Level: 1

    Join Date
    Jul 2019
    Posts
    5
    Helped
    0 / 0
    Points
    37
    Level
    1

    dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    I have a simple code for blinking LEDs in dsPIC30F2010. I am using MPLABX v5.20 and XC16 v1.36.

    I notice the dsPIC restarts at approximately 20seconds. Please, what could be the cause? I have tried on different boards and same result.

    Here is my code:

    Code C - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    #include <xc.h>
    #include <libpic30.h>
    #include <p30F2010.h>
     
    _FOSC(CSW_FSCM_OFF & XT_PLL16);
    _FWDT(WDT_OFF);
    _FBORPOR(MCLR_DIS & PWRT_OFF & PBOR_ON & BORV_27 & RST_PWMPIN & PWMxH_ACT_HI & PWMxL_ACT_HI);
    _FGS(CODE_PROT_OFF);
     
    void main( void ) 
    {
        TRISEbits.TRISE4 = 0;
        TRISEbits.TRISE5 = 0;
      
        _LATE4 = 1;
        _LATE5 = 1;                          //used this to know when there is restart
         __delay32(2400000);
      
        _LATE5 = 0;
      
        while( 1 )
        {
                 __delay32(2400000);
                _LATE4 = 1 - _LATE4;
                _LATE5 = 1 - _LATE5;          //toggle LEDs
        } 
    }

    Xtal is 6MHz external. Is there something I need to turn off or on in the SFRs?

  2. #2
    Super Moderator
    Points: 29,553, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,820
    Helped
    1114 / 1114
    Points
    29,553
    Level
    41
    Blog Entries
    9

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    _LATE5 = 1 - _LATE5; //toggle LED s
    Although at first glance this should work, surely doing a logical inversion by an algebraic operation is not the usual way of toggling a bit. Consider instead of doing a toogle, just forcing to a fixed value, .
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )



    •   AltAdvertisement

        
       

  3. #3
    Newbie level 4
    Points: 37, Level: 1

    Join Date
    Jul 2019
    Posts
    5
    Helped
    0 / 0
    Points
    37
    Level
    1

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    Code:
    _LATE5 = 1 - _LATE5;          //toggle LED s
    Although at first glance this should work, surely doing a logical inversion by an algebraic operation is not the usual way of toggling a bit. Consider instead of doing a toogle, just forcing to a fixed value, .
    I tried all stuff. I just changed it to below as suggested. The restart still happens exactly 20 seconds. It is frustrating.

    Code:
        __delay32(2400000);
                _LATE4 = 0;
                _LATE5 = 1;
                __delay32(2400000);
                
                 _LATE4 = 1;
                 _LATE5 = 0;
    I also changed the void main() to int main() with a return 0; still no show.

    I still wonder if there is a register or something else I need to set. The uniformity of interval of the restart is exact, Meaning something internal or by default is resetting.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 80,586, Level: 69
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    13,205
    Helped
    4410 / 4410
    Points
    80,586
    Level
    69

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    I'm not that familiar with dsPIC30 series code but a restart at fixed intervals regardless of the coding strongly suggests a watchdog issue. I assume the line "_FWDT(WDT_OFF);" turns it off, is there another control for the watchdog, maybe in the device config that needs attention?

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  5. #5
    Super Moderator
    Points: 258,547, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,137
    Helped
    13722 / 13722
    Points
    258,547
    Level
    100

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    Besides code review, you should also learn to read reset reason register.


    2 members found this post helpful.

  6. #6
    Newbie level 4
    Points: 37, Level: 1

    Join Date
    Jul 2019
    Posts
    5
    Helped
    0 / 0
    Points
    37
    Level
    1

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    Quote Originally Posted by betwixt View Post
    I'm not that familiar with dsPIC30 series code but a restart at fixed intervals regardless of the coding strongly suggests a watchdog issue. I assume the line "_FWDT(WDT_OFF);" turns it off, is there another control for the watchdog, maybe in the device config that needs attention?

    Brian.
    Strangely, the WDT was the culprit. It remains enabled despite turning it off in the config and confirming that on the programmer config bits too.

    Apply CLRWDT stopped the reset.

    Could a bad chip be the cause or errata issue or something I don't know yet?

    Quote Originally Posted by FvM View Post
    Besides code review, you should also learn to read reset reason register.
    Since I don't have any readout attached yet to the dsPIC30F, I was able to use LED pattern to confirm the cause of reset via the WDTO bit of RCON. Please, is there anyway RCONbits check can be integrated in code to resolve issues automatically besides development test?



  7. #7
    Super Moderator
    Points: 29,553, Level: 41
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,820
    Helped
    1114 / 1114
    Points
    29,553
    Level
    41
    Blog Entries
    9

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    MPLABX v5.20 and XC16 v1.36
    Are you sure that the compiler supports this syntax?

    Code:
    _FWDT(WDT_OFF);
    According to Microchip's datasheet (MPLAB XC16 C Compiler Users Guide DS50002071H.pdf), the correct one for 16-bits microcontrollers seems like being rather that:

    Code:
    #pragma config WDT=OFF
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  8. #8
    Newbie level 4
    Points: 37, Level: 1

    Join Date
    Jul 2019
    Posts
    5
    Helped
    0 / 0
    Points
    37
    Level
    1

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    Quote Originally Posted by andre_teprom View Post
    Are you sure that the compiler supports this syntax?

    Code:
    _FWDT(WDT_OFF);
    According to Microchip's datasheet (MPLAB XC16 C Compiler Users Guide DS50002071H.pdf), the correct one for 16-bits microcontrollers seems like being rather that:

    Code:
    #pragma config WDT=OFF
    Thanks,
    I tried the new config as below with no success. The reset was ongoing unless I use CLRWDT. I believe the chip is bad. I will be receiving new dsPIC from my supplier soon to confirm if it is chip level failure.

    Code:
    #pragma config FWPSB = WDTPSB_10        // WDT Prescaler B (1:10)
    #pragma config FWPSA = WDTPSA_512       // WDT Prescaler A (1:512)
    #pragma config WDT = WDT_OFF            // Watchdog Timer (Disabled)
    The prescaler A and B setting explains the >10seconds reset interval I was getting. Strange indeed! Let's assume it is chip partial failure.

    I am running at 6MHz and PLL_16 which should be 24 MIPS Tcy = 41.6ns. That means 1 sec delay should be __delay32(24000000) but __delay32(2400000) was the correct value on the physical chip against my math.



  9. #9
    Advanced Member level 4
    Points: 7,740, Level: 20

    Join Date
    Jan 2015
    Posts
    1,086
    Helped
    345 / 345
    Points
    7,740
    Level
    20

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    The answer, as so often happens, is in the data sheet. The last paragraph of Section 19.4.2 says that, if you turn off the config bit, then the WDT is controlled by software with the SWDTEN bit. Make sure this is bit is 0.
    Susan


    1 members found this post helpful.

  10. #10
    Newbie level 4
    Points: 37, Level: 1

    Join Date
    Jul 2019
    Posts
    5
    Helped
    0 / 0
    Points
    37
    Level
    1

    Re: dsPIC30F2010 - 30 I/SP restarts at interval of 20seconds for no known reason

    Quote Originally Posted by Aussie Susan View Post
    The answer, as so often happens, is in the data sheet. The last paragraph of Section 19.4.2 says that, if you turn off the config bit, then the WDT is controlled by software with the SWDTEN bit. Make sure this is bit is 0.
    Susan
    I appreciate your input. This is a useful pointer. However, my test code got that bit cleared as depicted below:

    Code:
     //read RCON bits for reset conditions
        if(RCONbits.WDTO)
        {
            _LATE4 = 0;
            _LATE5 = 0;
            __delay32(9600000);
             
        }
         RCON = 0x0000;
    I believe clearing the entire RCON bits does the job of ensuring SWDTEN = 0.
    Update will be made when I receive new dsPIC chips, as I have agreed my dsPIC chip is faulty. It will be interesting to find out.



--[[ ]]--