|
|
View previous topic :: View next topic |
Author |
Message |
AtakaN
Joined: 01 Aug 2012 Posts: 4
|
dspic 33FJ128MC802 restart itself automatically, WHY ? |
Posted: Wed Aug 01, 2012 5:43 am |
|
|
Hi guys, I'm trying to execute the dspic 33FJ128MC802 over the uart to receive pic's string on the screen of the pc though I ain't succeeded yet unfortunately.
In order to get the occurred-error-time (sequence-duration) I'm trying to make the pic count second to second. When the number reaches at one-exact number, I see 'the pic restarts itself automatically without any reason'. Do you have any idea why happens this action on my mcu ?
My current written code is below...
Code: |
#include <33FJ128MC802.h>
#device *=16 //16 bits pointer
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#FUSES NOJTAG //JTAG disabled
#fuses FRC //Internal Fast RC osilatör
#fuses NOWRTB //Boot block not write protected
#fuses NOPROTECT //boot bloğu kod korumasız, okuma korumasız
#fuses CKSNOFSM //clock değiştirme etkin değil
#fuses NOWDT //No Watch Dog Timer
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
//#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES NOWINDIS //Watch Dog Timer in Window mode
#FUSES NOCPD //No EE protection
#FUSES NOPUT //No Power Up Timer
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES FCMEN //Fail-safe clock monitor disabled
#FUSES NORBS
#FUSES NOBSS
#use delay(clock=7372800) // Internal FRC clock of 7.37 Mhz is used
#USE RS232 (BAUD=9600, XMIT=PIN_B7, RCV=PIN_B8, parity=N, bits=8, stop=1)
//#word POS1CNT = 0x01E4
//#word RPINR14 = 0x069C //QEI1 birimi için gerekli olan sinyallerin hangi uçlara bağlanacağını belirten registerlar
//#word RPINR15 = 0x069E
//#word QEI1CON = 0x01E0
//#word TMR1 = 0x0100
#define System_OK Pin_B4
#define set_clock 7958
unsigned int16 deger;
unsigned int16 sayac;
unsigned int16 saniye;
#int_Timer1
void Timer1_isr(void)
{
//clear_interrupt(int_Timer1);
//disable_interrupts(int_Timer1);
//disable_interrupts(INTR_GLOBAL);
set_timer1(set_clock);
sayac++;
if(sayac == 4)
{
sayac = 0;
saniye++;
printf("\n\rSaniye %lu \n", saniye);
}
//enable_interrupts(int_Timer1);
//enable_interrupts(INTR_GLOBAL);
//printf("\n\rSayac degeri %lu \n", sayac);
//printf("\n\rSayac degeri %lu \n", saniye);
//return;
}
#int_OSCFAIL
void OSCFAIL_isr(void)
{
printf("\n\rOSC Failed\n");
}
void main()
{
SETUP_WDT(WDT_OFF);
setup_timer1(TMR_INTERNAL|TMR_DIV_BY_8); //div_by 1-8-64-128
set_timer1(set_clock); //250ms overflow time * 4 = 1 sec
enable_interrupts(int_Timer1);
enable_interrupts(INTR_GLOBAL);
output_high(System_OK);
sayac=0;
saniye=0;
while(TRUE) ;
return;
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Wed Aug 01, 2012 8:21 am |
|
|
1) Get rid of:
#device *=16 //16 bits pointer
Pointless, does nothing on the PIC18, or 24.....
2) Try increasing the stack size. Commonest cause for PIC24 problems is that the default stack is set to small so you get a stack overflow, and a reboot.
#BUILD(stack=0x300)
default is 0x100
Best Wishes |
|
|
AtakaN
Joined: 01 Aug 2012 Posts: 4
|
|
Posted: Thu Aug 02, 2012 12:13 am |
|
|
hi ...
Thanks Ttelmah for your reply. I've just performed your recommended changes on my program however I couldn't succeed.
When I increased the value of stack, the capacity of ram goes up to %5 from %1.
In addition, for the stack size is
Code: | #BUILD(stack=0x600) |
ram-size %10.
According to above code (at the beginning of the program code), the counter counts till 267 then restarting action is carried out at this value always (so rarely 266).
You think, is this problem caused by the compiler of CCS C ? (not execute the registries sufficiently ?)
My compiler is ccs c - PCWHD - v4.130
Thank in advance |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19524
|
|
Posted: Thu Aug 02, 2012 2:00 am |
|
|
You need to add a test at the start of the code, and find out what the restart_cause is.
The stack was the first place to begin, because the default is almost always too small. It is 'OK' if you never use interrupts, and only very simple printf statements, for small programs, but for 99% of code does need to go up.
Of course it uses RAM. That is where the stack is stored. However no point in making it too large. 0x200, is OK for most code, and just a few programs need 0x300. Anything larger is unlikely to be needed. I suggested 300, since this was larger than you _would_ need, and allowed this to be ruled out.
You need to find out what is triggering the reset.
Generically though, get rid of the printing in the ISR. This is never good practice, and does use more space on the stack (one reason I considered this to be a possibility). Just set a flag when your count is reached, and have the main code do the printing when this is seen.
Though at one second intervals, with nothing else happening, this should work, it is worth avoiding.
If you 'must' print in the ISR, then use buffered print code.
Best Wishes |
|
|
AtakaN
Joined: 01 Aug 2012 Posts: 4
|
|
Posted: Fri Aug 03, 2012 3:27 am |
|
|
hi again, after some investigations, i understand, my problem is not a software or get ccs c (mplab) carried out. I try to blink a led, however my mcu is again restarted ! ... as far as I succeed to measure, the restart process occurs in 2 minutes. I dont know where is the wrong ? even I see the restart as long as the mcu is connected as recommended (recording to dsPIC33FJ32MC302/304, dsPIC33FJ64MCX02/X04 AND dsPIC33FJ128MCX02/X04 microchip datasheet - DS70291F-page 22) |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|