pic microcontroller stack

Microcontroller Topics
Post Reply
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

pic microcontroller stack

Post by SukhdeepMankoo » Fri Sep 24, 2010 1:57 pm

Hi,
I am reading datasheet of PIC16F882. on page no 23, stack level1 ..... stack level8.
Reset Vector has address 0h
Interrupt Vector............4h

between these two vector, pic has 8 no of stacks.
how is it possible to accommodate 8 stack in 4 location? one more thing as stack is controlled by software(compiler), then why need stack in hardware side and what will be its benefit?

Thanks & Regards
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: pic microcontroller stack

Post by Neo » Fri Sep 24, 2010 9:17 pm

Hi Sukdeep,

After a long time. Didn't see you around for several months. Please visit ROBOT.LK as much as possible and share you knowledge and experience with our community. If there is anything you find interesting and like to share, please do share that in ROBOT.LK.

Regarding your question... I had a look at the datasheet.

If you take out 0 and 4, it is just 3 bytes (1, 2 and 3) between that. According to page 39, under 2.3.2 (I copied it below) you can see that each stack level is 13-bits. So it is required to have 8 x 13-bit = 13 Bytes to accommodate the State levels. So it is definitely not between 0 and 4 according to what I see.

The same description addresses your other question. Read Note 2.
The PIC16F882/883/884/886/887 devices have an 8-level x 13-bit wide hardware stack (see Figures 2-2 and 2-3). The stack space is not part of either program or data space and the Stack Pointer is not readable or writable. The PC is PUSHed onto the stack when a CALL instruction is executed or an interrupt causes a branch. The stack is POPed in the event of a RETURN, RETLW or a RETFIE instruction execution. PCLATH is not affected by a PUSH or POP operation. The stack operates as a circular buffer. This means that after the stack has been PUSHed eight times, the ninth push overwrites the value that was stored from the first push. The tenth push overwrites the second push (and so on).

Note 1: There are no Status bits to indicate stack overflow or stack underflow conditions.
Note 2: There are no instructions/mnemonics called PUSH or POP. These are actions that occur from the execution of the
CALL, RETURN, RETLW and RETFIE instructions or the vectoring to an interrupt address.
SukhdeepMankoo
Lieutenant
Lieutenant
Posts: 92
Joined: Tue Oct 27, 2009 7:50 pm

Re: pic microcontroller stack

Post by SukhdeepMankoo » Sat Sep 25, 2010 11:29 am

Thanks Neo,
I was too busy last few months and not able to check out the ROBOT.LK Community Page. With God's Grace, whatever i know about the embedded System, i am always ready to help in ROBOT.LK Community.

Now, I have not seen Hardware Stack in case of any other Controller except PIC. what will be its benefit and second thing, may i not able to call more than 8 function calls including interrupt and function included in interrupt routine?

But I have not seen any boundary regarding the calling the number of functions in case of AVR as well as on ARM.


Thanks & Regards
Sukhdeep SIngh.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: pic microcontroller stack

Post by Neo » Sat Sep 25, 2010 6:31 pm

hi, i don't think u need to consider that. It's a circular buffer that is handled by hardware.
Post Reply

Return to “Microcontrollers”