MCU BUG? Please Help

Status
Not open for further replies.

jeyes56

Member
hi, i have PIC16f877A MCU, im using a paralax rfid-rw to operate a 12v dc electromagnet, it also has a N3310 LCD Display to display some message.

my system is working fine, but have some bug.

when i plug my system, sometimes the rfrw seems not responding, i need to re-plug it few time, or re-plug it within less than 1 second (unplug for 1 sec, and plug again immediately)

what should i do, please help me
 
As we discussed in chat before you left, there are three things you should try:

1) give us a circuit diagram of how you control the electromagnet. It is important that you protect the processor from back EMF properly.
2) with the code that you wrote for the Parallax RFID-RW, do you check the value of the status byte that it returns? Status 0x01 is "OK", all others (2 to 7) are errors.
3) try a short pause in your initialisation code before you talk to the Parallax module. If it works when you replug it, there might be something going wrong at power up.
 
1.) View attachment 68627
2.) yes, i insure that i receive 0x01 before proceeding on getting the whole data.
3.)
void main(void)
{ sci_Init(9600, SCI_EIGHT); // initialize serial data bus for DS1307 RTC
init_PORTS(); // initialize ports
init_nokia(); // initialize nokia LCD
// time_set(); // set the time
initialize(); // initialize the device

int y,ads=0x0F;
int p;
while(1)
{
if(ads==0x0F)
{ RELAY=CLOSE;
show^=1;
list=0x0F;
ads=0x00;
if(show==0){idle();}
else {developer(); ads=0x08;}
}


if(BUTTON_UP)
{ showlist(1); ads=0x01;}
else if(BUTTON_DOWN)
{ showlist(2); ads=0x01;}

p=RFID_getpass();
if(p==0x01)
{ if(RFID_getdoor()==0x01)
{ RFID_getname();
RFID_okay();
}
ads=0x0B;
}
if(p==0x02)
{ RFID_error(); }

if (lcd<10)
{ lcd++; }
else
{ LCD_OFF(); }

ads++;
}
}
 
Last edited:
edeca wanted the circuit schematic, not the PCB layout..... the PCB layout is about useless for troubleshooting your problem.
 
i add some code to display to the lcd the error code which will be received first of the 5 data to receive.
i save the 5 data to data[x] and after receiving all the data,(which is, if there is error, it also sends back a 00 in all data),
i display it on the lcd.

i constantly send command to the rfrw to check the value of certain block (block 1F)
and receive it immediately,

here's the scenario A:
1.) after powering up, the paralax rfrw LED is red, meaning it is receiving command
2.) the error code displayed on lcd is 2, meaning no tag present.
3.) if i present the tag, the error code changes to 1, meaning no error,
4.) the LED or rfrw becomes green w/c means idle (note. i constantly send command to rfrw)
5.) it hangs up

scenario B:
1.) #1-3 of scenario A
2.) the system reads another memory block ( i knew it because it switches the relay in this stage)
3.) #4-5 of scenario A

scenario C:
1.) #1-2 of scenario A
2.) #4 of scenario A

scenario D:
1.) the system is working fine for a few trials (present of tag)
2.) the system hangs up, the rfrw LED is green.

scenario E:
1.) the system is working fine.
2.) no error.


the scenario's occur in random.

somebody says i need to add capacitor near the MCU supply.


@ stanfidavid
how to protect back emf? i already put diode across the supply of the relay.




i already put a bunch of delay at the beginning

void delay(void)
{ for(int x=0;x<=0xFF;x++)
{ for(int y=0;y<=0xF;y++)
{ continue; }
}
}

void main(void)
{ delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
delay();
sci_Init(9600, SCI_EIGHT); // initialize serial data bus for DS1307 RTC
init_PORTS(); // initialize ports
init_nokia(); // initialize nokia LCD
// time_set(); // set the time
initialize(); // initialize the device
.
.
.
.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…