PIC 16f887 question

Discussion in 'General Electronics Chat' started by RG23, May 26, 2011.

  1. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    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
     
  2. #12

    Expert

    Nov 30, 2010
    16,278
    6,789
    I think you'd do better in another department. There is a section on microprocessors about 5 lines down from "chat".
     
  3. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    @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??????
     
  4. Markd77

    Senior Member

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

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    @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
     
  6. radiohead

    Active Member

    May 28, 2009
    474
    31
    This thread belongs in the Embedded Systems and Microcontrollers Forum
     
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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.
     
  8. #12

    Expert

    Nov 30, 2010
    16,278
    6,789
    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.
     
  9. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    @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
     
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  11. Alberto

    Active Member

    Nov 7, 2008
    169
    36
    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
     
  12. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    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
     
  13. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    Is there any way I can move this thread to the desired place?
     
  14. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    @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??
     
  15. #12

    Expert

    Nov 30, 2010
    16,278
    6,789
    Click on red triangle in top right corner...................................................................................................over here^

    Ask bosses to move you.
     
  16. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
  17. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    No, that means calling routines from other routines, or recursively calling the same routine, or "nested" calls.
     
  18. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    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
     
  19. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  20. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
Loading...