Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What would cause a pic to reset? Help me troubleshoot.

Status
Not open for further replies.

NewGeek

New Member
I have a bit of code that I have been going over and over again to find a problem. Im sure the logic is correct. Every time it gets to a particular point in the program, it resets.


I am controlling an LCD, and using a switch to toggle through screens. The first screen is a "hello" screen, and I programmed it intentionally so that once you toggle off the first hello screen, you cannot toggle back to it.
After a point in the program, it takes me back to hello, this is how I know the PIC is resetting.

I thought it might be the Watchdog timer, but I put this line at the beginning to disable:

__config _HS_OSC & _WDT_OFF & _PWRTE_ON

This is a PIC16F84a
What are some common things to look for when the pic is resetting itself?

Thanks
 
OK I just searched the archives and found somebody else with a similar problem, and we were even using the same code: Nigel's LCD routines!

SO it has something to with PCL and Tables exceeding a 256k limit. So I did some experimenting....
I dont really understand tables and PCL yet, so I just shortened the length of the messages I was displaying....Now the program runs as it should.

Shouldnt I be able to display up to 16 characters across? How do I alter the code to make this happen?

So if anyone wants to give me the quick & easy guide to PCL and tables Id love to hear it. Meanwhile, I'll be off reading my datasheet.
 
Does your program loop back to itself at the bottom of the code, or just run out of assembly commands? The processor doesn't know to "stop", it will continue to execute all the following command space and will eventually reset (not sure what causes the eventual reset, but just don't let it go there)
 
NewGeek said:
OK I just searched the archives and found somebody else with a similar problem, and we were even using the same code: Nigel's LCD routines!

SO it has something to with PCL and Tables exceeding a 256k limit. So I did some experimenting....
I dont really understand tables and PCL yet, so I just shortened the length of the messages I was displaying....Now the program runs as it should.

Shouldnt I be able to display up to 16 characters across? How do I alter the code to make this happen?

So if anyone wants to give me the quick & easy guide to PCL and tables Id love to hear it. Meanwhile, I'll be off reading my datasheet.

You will notice that my LCD routines often tend to place the tables at the beginning of the program, this is to ensure that they don't cross a 256 byte boundary, that's probably the simplest way to avoid the problem. Otherwise you need to set PCLATH correctly befoe calling the table.
 
Actually, your code has the tables at the very end. Probably because its so short that it doesnt matter ("Hello Ready...").

I will try moving the tables to the beginning, but can you explain to me what is happening through these tables and why it causes reset.
I dont really understand the use of PCL. The datasheet explains it as the lower bits of PC.
PCLATH is something different and not writable, correct? I dont understand what it is for either.

I understand that through each call to the table you are adding to PCL. But Im still missing something.
If PCL is connected to PC, then the further down my table is in the program, the less characters I can produce, is that correct? Wouldnt this mean that Im limited to a total of 255 total characters in the entire program? That cant be right.


Could I simply call a little subroutine before each table that resets PCL to zero? Would this affect the counter for the rest of the program though?

Thanks for all your help, Im learning a lot.
 
NewGeek said:
Actually, your code has the tables at the very end. Probably because its so short that it doesnt matter ("Hello Ready...").

I will try moving the tables to the beginning, but can you explain to me what is happening through these tables and why it causes reset.
I dont really understand the use of PCL. The datasheet explains it as the lower bits of PC.
PCLATH is something different and not writable, correct? I dont understand what it is for either.

I understand that through each call to the table you are adding to PCL. But Im still missing something.
If PCL is connected to PC, then the further down my table is in the program, the less characters I can produce, is that correct? Wouldnt this mean that Im limited to a total of 255 total characters in the entire program? That cant be right.


Could I simply call a little subroutine before each table that resets PCL to zero? Would this affect the counter for the rest of the program though?

Thanks for all your help, Im learning a lot.

PCL (sorry, my mistake mentioning PCLATH) is only an 8 bit counter, so can only cover 256 bytes - the extra bits are accessed seperately, but are taken care of by the processor during normal operation. However, this manual method of creating a table by adding directly to PCL can only span a maximum of 255 bytes, and MUST NOT go over a 256 byte boundary - if it does the jump will fail, actually going back to a low address in the current 256 byte space.

For an example, assume your program counter is at address 250, and you add 10 to PCL, you would expect it to jump to address 260, but it would jump to address 4 (260-256) - which will certainly make things work differently!.

My very short tutorials place the tables at the end, because it doesn't matter, but the longer ones move them to the front to avoid this problem, and I think some even manipulate the extra PCL bits and have the tables at the very top 256 bytes of memory.
 
Since each character is on a separate line in the program, and thus each character increases PCL by 1, does this mean that my whole program can only contain a max of 255 characters if I put the tables at the beginning?

This would mean that with a 16x2 display, I could only have 8 different message screens (assuming each screen used all 32 character spaces).
Please correct me if Im wrong!


How do you change the value of PCL without affecting the PC for rest of the program?
 
No, you can cross table boundries and use the entire program memory for a table (if you wanted to).
PCL only holds the 8 LSB for the program counter address (256 positions).
The remaining MSB are in PCLATH.

Search the piclist, it contains code examples for stringtables.
I'd post my code for it, but I had a harddrive crash this week and it's gone.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top