PIC 16f887 question

Thread Starter

RG23

Joined Dec 6, 2010
304
I am using PIC 16f887.

When I enter the code in MPLAB it builds successfully.

In the view tab there is Memory Usage Gauge

Total program memory shown is 8192 and data memory is 368

Consumed program memory is 2197 and data memory is 0

The code is very big at the moment

When I put a few more instructions in my code the controller stops working

Is there any limit to the number of subroutines or to the number of instructions I can use with PIC16f887

If you have any idea please let me know

Thanks
 

#12

Joined Nov 30, 2010
18,224
I think you'd do better in another department. There is a section on microprocessors about 5 lines down from "chat".
 

Thread Starter

RG23

Joined Dec 6, 2010
304
@I think you'd do better in another department

I am not clear with what you said..

@There is a section on microprocessors about 5 lines down from "chat".

Where??????
 

Markd77

Joined Sep 7, 2009
2,806
When you get to 2048 instructions calls stop working properly so you have to start changing PCLATH to get calls to work above that.
 

Thread Starter

RG23

Joined Dec 6, 2010
304
@When you get to 2048 instructions calls stop working properly so you have to start changing PCLATH to get calls to work above that


How do I do that?
Is there any example you know of the same?????

Thanks
 

t06afre

Joined May 11, 2009
5,934
Are you using C, Basic or assembler. If you are using C or Basic. It could be that your code is limited to 2Kbytes. And you have overlooked some compiler warning about this. However if you use assembler The PLATH setting may be worth looking into.
 

#12

Joined Nov 30, 2010
18,224
There is a page called "all about circuits forum". It has 15 departments listed. I think the 5th or 6th one down attracts more traffic about your question.

Look at the top of this page where it says, "Welcome RG23". Look to the left side of that line and click on "all about circuits forum" to get to the page with all the departments.

You might get more people that know about your needs by posting a question in the Programmers corner" or "Embedded systems and microcontrollers". More people watching will get you more ideas, faster.
 

Thread Starter

RG23

Joined Dec 6, 2010
304
@However if you use assembler The PLATH setting may be worth looking into

I am using assembler

I am not sure about the PCLATH settings though

If you have any idea do let me know
 

Alberto

Joined Nov 7, 2008
169
Since you are using a lot of subroutines there is a high chance that you run out of stack space during execution. Keep the gosub within the stack capability of your MCU (If I remember correctly is less then 10 for your pic device)

Cheers

Alberto
 

debjit625

Joined Apr 17, 2010
790
RG23 said:
Is there any limit to the number of subroutines
Normally PIC16Fxxx have 8-level deep hardware stack.This stack is not used for passing parameters of function rather this is a hardware stack which stores 13 bits value of PC (ProgramCounter) whenever you use a CALL instruction or an interrupt cause a branch.So the limit is 8 i.e.. you can call functions or subroutines 8 times in a series.Some compilers use different technique to overcome this,but in your case you are using assembler.

You didnt post your code,their may be some other problem which is causing this.

By the way,other guys are asking you to post this in :
http://forum.allaboutcircuits.com/forumdisplay.php?f=17

Good Luck
 

Thread Starter

RG23

Joined Dec 6, 2010
304
@Keep the gosub within the stack capability of your MCU (If I remember correctly is less then 10 for your pic device)

Do you mean the max no of subroutines I can use is 10??
 

#12

Joined Nov 30, 2010
18,224
Click on red triangle in top right corner...................................................................................................over here^

Ask bosses to move you.
 

SgtWookie

Joined Jul 17, 2007
22,230
@Keep the gosub within the stack capability of your MCU (If I remember correctly is less then 10 for your pic device)

Do you mean the max no of subroutines I can use is 10??
No, that means calling routines from other routines, or recursively calling the same routine, or "nested" calls.
 

Thread Starter

RG23

Joined Dec 6, 2010
304
When executing a CALL or GOTO, the low 11-bits are
loaded directly from the instruction opcode. The high
2-bits are loaded from bits 3 and 4 of the PCLATH reg-
ister. It is a good practice to pre-load PCLATH with the
high byte of the routine’s address before executing the
routine. This can be done as follows:
.
.
movlw HIGH Table ;load high 8-bit
movwf PCLATH ;address of Table into PCLATH
call Routine ;execute Call instruction
__________________________________________________________

i read the above content

tried to implement it but didn't work
 

Markd77

Joined Sep 7, 2009
2,806
I've never actually had to do it, but the method in the second link from SgtWookie looks very easy to use and maintain. Just find the biggest and least used calls.
 

Markd77

Joined Sep 7, 2009
2,806
.
movlw HIGH Table ;load high 8-bit
movwf PCLATH ;address of Table into PCLATH
call Routine ;execute Call instruction
__________________________________________________________

i read the above content

tried to implement it but didn't work
One problem with this method is that you have to add it to every call which makes the code messy and slows every call down. Also if the routine uses the value in the W register then you have to rework it. The other method you can choose which calls are affected and it doesn't mess up W.
 
Top