Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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

londoner

Newbie level 4
Joined
Jul 6, 2019
Messages
5
Helped
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
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?
 

andre_teprom

Super Moderator
Joined
Nov 7, 2006
Messages
9,107
Helped
1131
Reputation
2,280
Reaction score
1,101
Trophy points
1,403
Location
Brazil
Activity points
52,970
_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, .
 

londoner

Newbie level 4
Joined
Jul 6, 2019
Messages
5
Helped
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
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.
 

betwixt

Super Moderator
Joined
Jul 4, 2009
Messages
14,049
Helped
4661
Reputation
9,336
Reaction score
4,399
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
120,106
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.
 

londoner

Newbie level 4
Joined
Jul 6, 2019
Messages
5
Helped
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
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?

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?
 

andre_teprom

Super Moderator
Joined
Nov 7, 2006
Messages
9,107
Helped
1131
Reputation
2,280
Reaction score
1,101
Trophy points
1,403
Location
Brazil
Activity points
52,970

londoner

Newbie level 4
Joined
Jul 6, 2019
Messages
5
Helped
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
Are you sure that the compiler supports this syntax?

Code:
_FWDT(WDT_OFF);
According to Microchip's datasheet (View attachment 154359), 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.
 

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,146
Helped
356
Reputation
712
Reaction score
352
Trophy points
83
Activity points
12,436
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
 

londoner

Newbie level 4
Joined
Jul 6, 2019
Messages
5
Helped
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
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.
 

Toggle Sidebar

Welcome to EDABoard.com

Sponsor

Sponsor

Design Fast


X
Top