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 CCS Technical Support

Pic12F683 Rebooting over and over Please Help!

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



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

Pic12F683 Rebooting over and over Please Help!
PostPosted: Mon Nov 12, 2007 12:57 am     Reply with quote

Everything seems to be working fine but after receiving data then sending the response back out the PIC seems to reboot again and again! Worked fine for days on my breadboard!

Can anyone look at my code and tell me if they see any problem?

Code:


#include <12F683.h>
#device adc=8
#define TOUCH_DEVICE   PIN_A2
#fuses NOWDT,INTRC_IO, NOCPD, NOPROTECT, NOMCLR, NOPUT, NOBROWNOUT, NOIESO, NOFCMEN
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8,STREAM=COM_A)
#use rs232(baud=9600,parity=N,xmit=PIN_A4,rcv=PIN_A5,bits=8,STREAM=COM_B)
#rom 0x7FF = {0x3400}

#include<1wire.c>
#include<ds1820.c>
#include <string.h>

void main()
{
   float temperature;
   char string_a[4];
   char string_b[10];
   int command;

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
delay_ms(1000);

while(1) {

fgets(string_a, COM_A);
command = string_a[1];
   
   if (command == 19)
   {
      temperature = read();
      fprintf(COM_A, "I%3.1f\r", temperature);
   } else {
      fprintf(COM_B, string_a);
      fgets(string_b, COM_B);
      fprintf(COM_A, string_b);   
   }
}

}



This project must ship out for beta testing today! Please help!

Thanks in advance,

Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 1:34 am     Reply with quote

Quote:

char string_a[4];
char string_b[10];

fgets(string_a, COM_A);
fgets(string_b, COM_B);

See this post about writing past the end of an array with gets():
http://www.ccsinfo.com/forum/viewtopic.php?t=25983&start=3

Also post your compiler version.
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 1:49 am     Reply with quote

PCWH Compiler
IDE 3.43
PCB 3.205
PCM 3.205
PCH 3.205

char string_a[20];
char string_b[40];

Let me see if this works

Thanks,

Scott
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 1:54 am     Reply with quote

No Luck!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 2:40 am     Reply with quote

Comment out lines of code to see where the problem is.
First comment out the line that calls the DS1820 driver. Put in a new
line that loads a constant value into the 'temperature' variable.

See if the 'reset' problem goes away.

Quote:

while(1) {

fgets(string_a, COM_A);
command = string_a[1];

if (command == 19)
{
// temperature = read(); // Comment out this line
temperature = 24.5; // Add this line

fprintf(COM_A, "I%3.1f\r", temperature);
} else {
fprintf(COM_B, string_a);
fgets(string_b, COM_B);
fprintf(COM_A, string_b);
}
}

}



Also read this thread about random resets:
http://www.ccsinfo.com/forum/viewtopic.php?t=27638&start=4
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 3:55 am     Reply with quote

Sending data over RS232 means the RS232 driver will draw a relative large current, depending on circuit design this might have all kind of side effects. The links provided by PCM Programmer are a good starting point.

As a side note, compiler version v3.205 is an unstable version. The v3.2xx compiler releases became more or less stable at version 3.220. Though it is unlikely that your compiler version is causing the resets it is known to have other problems that you will run into sooner or later.
Hint: A free version of the PCB compiler is supplied with MPLAB.
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 8:46 am     Reply with quote

I have tried your method and tested the following and it works! That is without the second port.

Code:

while(1) {

fgets(string_a, COM_A);
command = string_a[1];

if (command == 19)
{
// temperature = read(); // Comment out this line
temperature = 24.5; // Add this line
fprintf(COM_A, "I%3.1f\r", temperature);
} else {
//fprintf(COM_B, string_a);
//fgets(string_b, COM_B);
//fprintf(COM_A, string_b);
fprintf(COM_A, "Test\r");
}
}

}


It is working but as soon as I try to use the second 232 port it stops working.

Thanks,

Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 12:30 pm     Reply with quote

You're using two software UARTs. Each line of code that uses a soft
UART has to be fully completed before the program advances to the
next line of code.

When your program is sending RS232 characters with this line,
Quote:
fprintf(COM_A, "I%3.1f\r", temperature);

then it can't advance to this line until it's done:
Quote:
fgets(string_b, COM_B);


But, what if characters are coming into COM_B during that time ?
One or more of the characters will be missed. You also may get
garbled data, since the fgets() line may start execution in the middle
of a character. A data bit could be interpreted as a "start" bit.
(Because the start bit was missed while the fprintf() was in progress).
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Mon Nov 12, 2007 3:57 pm     Reply with quote

The user will request data from either ibutton or equipment on 232 port two. The handhelds should never connect to both at the same time!

Well I will have to take that back if it can be done it will be done by some user!

Maybe adding a small delay?

Scott
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