Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

PIC16F877A Freezing problem...!!!!

Status
Not open for further replies.

K.S.S

Newbie level 2
Joined
Jan 12, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
Hi All


I have been working on a project involving a handheld controller controlling a bank of resistors. The 877A in the controller is responsible for taking in the values according to the keys pressed and displaying these values on LCD screen. IT works fine initially but after incrementing or decrementing the values by few KWatt values the 877A freezes due to which the display freezes and the keys do not function.

Why does this happen???? Please povide a solution to this problem. I was wondering if the PIC is freezing due to debouncing. I tried making some changes in the kepad driver software but it still freezes. Please let me know where did I go wong in the coding. I am using the CCS compiler

kb_direct.c

Code:
//Button assignments
#define button_adjd PIN_A0
#define button_adju PIN_A1
#define button_accept PIN_A2
#define button_100s PIN_A3
#define button_10s PIN_A4
#define button_1s PIN_A5
#define button_qstop PIN_E0
#define button_sstop PIN_E1
#define button_revert PIN_E2



// prototypes

int16 get_key(void);
int16 get_keyX(void);
int16 keytemp=0;

int8 dbcounter=0;
int8 T_valid=0;
// implementations

void kb_init(void)
{
keytemp=0;
}

int16 get_key(void)
{
int16 a=0;

int8 T_valid=100;
int i=0;

if ((input(button_adjd)==1))
{
dbcounter=0;
for ( i=0;i<255;i++)
{
dbcounter= dbcounter+1;
}
if (dbcounter>T_valid)
{
a+=1;
} 
} 

if ((input(button_adju)==1))
{
dbcounter=0;
for ( i=0;i<255;i++)
{
dbcounter= dbcounter+1;
}
if (dbcounter>T_valid)
{
a+=2;
} 
}







//if (input(button_adjd)==1) a+=1;
//if (input(button_adju)==1) a+=2;
if (input(button_accept)==1) a+=4;
if (input(button_100s)==1) a+=8;
if (input(button_10s)==1) a+=16;
if (input(button_1s)==1) a+=32;
if (input(button_qstop)==1) a+=64;
if (input(button_sstop)==1) a+=128;
if (input(button_revert)==1) a+=256;

// 1 = adjd
// 2 = adju
// 4 = accept
// 8 = 100s
// 16 = 10s
// 32 = 1s
// 64 = qstop
// 128 = sstop
// 256 = revert
if (keytemp==a)
{
return(0);
}
else
{
if (a>keytemp)
{
keytemp=a;
return(a);
}
if (a==0)
{
keytemp=0;
return(0);
}
}
}


int16 get_keyX(void)
{
int16 a=0;

if (input(button_adjd)==1) a=1;
if (input(button_adju)==1) a=2;
if (input(button_100s)==1) a=4;
if (input(button_10s)==1) a=5;
if (input(button_1s)==1) a=6;
if (input(button_accept)==1) a=3;
if (input(button_revert)==1) a=9;
if (input(button_sstop)==1) a=8;
if (input(button_qstop)==1) a=7;
// 1 = adjd
// 2 = adju
// 3 = accept
// 4 = 100s
// 5 = 10s
// 6 = 1s
// 7 = qstop
// 8 = sstop
// 9 = revert
if (keytemp==a)
{
return(0);
}
else
{
keytemp=a;
return(a);
}
}



In the main program, the function int16 get_key(void) is called to get the value of the key pressed.
It is also showing the error "A #device is required before this line"
 
Last edited by a moderator:

Hi, it sounds to be that the micro in going into a state that it cannot handle because of an arithmetic action that it does not like
 

Thanks. But I cannot figure out why is it getting stuck. The PIC freezes at random steps but only while incrementing and decrementing. There is no definite pattern in its freezing...!!
 

I have experienced microcontrollers freezing and malfunctioning due to hardware issues, but they were mostly dsPICs. However, the same principles should apply.

Make sure the power lines are properly regulated, filtered and decoupled.

'Isolate' the reset/master clear pin from the +V line using a diode, and connect a decoupling capacitor and, if necessary, a "bulk" capacitor as well from the reset/master clear pin to ground.

Keep your connections from the oscillator to the PIC short. Select appropriate capacitors to use from the oscillator pins to ground.

Hope this helps.
Tahmid.
 

Thanks Tahmid. Thousands of my circuits are running without any problem with PIC micro controllers. But only one design is having this problem. I've checked what is happening here.The customer was using just a 100mA 6-0-6 transformer(instead of 600mA/9-0-9 Transformer) to power up the circuit. But there was a 7812 before 78L05. and 78L05 was powered through a current limiting resistor. When the line voltage goes low, there is no sufficient voltage to drive the MCU. May be this is the main reason for MCU Freezing in this case.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top