CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Unexpected Restart of 18F45K22

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aviarunash



Joined: 15 Nov 2018
Posts: 5

View user's profile Send private message

Unexpected Restart of 18F45K22
PostPosted: Thu Nov 15, 2018 9:39 pm     Reply with quote

Hi All,

I am using 18F45K22, with two uart enabled (compiler 5.008). Have an external 20Mhz Crystal. The below are the fuse settings. The problem is that, when I use more delays or add an additional code somewhere in the program the controller restarts which does not make any sense.
For eg, when I assign a value to a variable in between somewhere, it restarts.
I am not sure why this is happening, please give me some suggestions on what might be causing the trouble.

Code:

#include <18F45K22.h>
#include <stdlib.h>

#fuses HSH,NOPLLEN,NOWDT,PUT,NOBROWNOUT,NOLVP,MCLR,NOIESO,NOPBADEN,NOFCMEN,NOSTVREN,NOXINST,NODEBUG   #use delay(clock=20000000,CRYSTAL=20M)

#use rs232(baud=9600,parity=N,xmit=PIN_C6, rcv=PIN_C7,bits=8,stream=STU,errors)
#use rs232(baud=9600,parity=N,xmit=PIN_D6, rcv=PIN_D7,bits=8,stream=DEIC,errors)
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Nov 16, 2018 2:27 am     Reply with quote

First, you should have STVREN enabled. Do this, and add a test at the start of your code for 'RESTART_CAUSE'. This will help tell you why the chip is resetting.
Look at your listing file. How big is the stack?. Has all the sounds possibly that you are using too many stack levels.
Then 5.008, was a 'beta' compiler version at best. It had issues, particularly with disabling global interrupts when it shouldn't.
Other things that can cause resets are things like having interrupts enabled without a handler present, and (obviously) hardware issues.
aviarunash



Joined: 15 Nov 2018
Posts: 5

View user's profile Send private message

PostPosted: Sat Nov 17, 2018 3:53 am     Reply with quote

Thank you for your reply.
I have enabled the fuse STVREN as you said. But still the problem exists. Haven't left any interrupts without handler. Just have the two UART interrupts. This is my main routine.

Code:

 set_tris_a(0x01);
   set_tris_d(0xF0);
   set_tris_b(0x06);
   set_tris_c(0xC0);

   setup_comparator(NC_NC_NC_NC);
   setup_dac(DAC_OFF);
   setup_adc(ADC_OFF);
   setup_adc_ports(NO_ANALOGS);
   setup_wdt(WDT_OFF);



  enable_interrupts(INT_RDA);
  enable_interrupts(INT_RDA2);
  enable_interrupts(GLOBAL);
aviarunash



Joined: 15 Nov 2018
Posts: 5

View user's profile Send private message

PostPosted: Sat Nov 17, 2018 3:55 am     Reply with quote

Regarding Stack Size:

ROM used: 2496 bytes (8%)
Largest free fragment is 30268
RAM used: 110 (7%) at main() level
130 (8%) worst case
Stack used: 4 locations (3 in main + 1 for interrupts)
Stack size: 30
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 17, 2018 4:19 am     Reply with quote

Scratch and main variable corruption (in vs. 5.008):
http://www.ccsinfo.com/forum/viewtopic.php?t=51455&highlight=008
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Sat Nov 17, 2018 12:42 pm     Reply with quote

Well remembered/found PCM_programmer. I remember 5.008, was still a 'beta' for me, since it had problems. Around 5.018, was the first I considered to be reasonably usable.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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