Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#1558 PIC14: array index handling in interrupt

open
PIC14
5
2013-07-16
2009-08-19
Gál Zsolt
No

I tried to make test program for my mTouch panel which is described on the Microchip web page. Unfortunately I did not found any demo program on this page, only some snippets in pdf documents. So I started to write a program in C. During this process I had to realise, that there is something wrong around the array index. When I use indexed array both in interrupt routine and main program, the data in the array become confused. I made a solution which is very unconfortable. You can check it. This program try to display the actual reading of the sensor the maximum and the minimum values on a serial LCD panel.
I am using sdcc in PikLab.

SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Mar 22 2009) (UNIX)
gpasm-0.13.7 beta

Discussion

  • Gál Zsolt
    Gál Zsolt
    2009-08-19

    This is the C source file.

     
    Attachments
  • Gál Zsolt
    Gál Zsolt
    2009-08-27

    It is missing in my reporting that this problem is on a PIC14 device. So I don't know is this problem exist on other microcontroller or not. I am using only PIC14 devices like PIC16F628, PIC16F690, PIC16F887.
    I made some modification in the program structure to avoid using array in the interrupt routine. I removed all array variable and multiply / divide procedure. The result is a good working program. So I suggest everybody who has a plan to use array / multiply / divide procedure not to put into the interrupt service routine. It is better using a FLAG in the interrupt routine and watch this FLAG in a normal function. In case this FLAG is set or not make a deal to do the complex tasks.
    Analise the assembly code you can find the part which cause the problem. If you use any multiply operation the compiler put the STK00 STK01 STK02 variables in the procedure. When you realize it is happen with your interrupt routine you should make modification on it, because you will have a good chance for a tricky problem at running your program on a PIC.

     
  • Hi Gál,
    are you using an unsigned char or an unsigned integer index into the table / how large is the table / is the procedure that you have removed a function call / is the data pointed to 1/2/4 byte wide / could you provide a snippet of your source code?

     
  • Raphael Neider
    Raphael Neider
    2009-08-27

    We had a similar discussion on the sdcc-user list as "[Sdcc-user] Problem with interrupts." starting on 2009-05-05 (see mailing list archive at https://sourceforge.net/mailarchive/forum.php?thread_name=b321594e0905120713w1a8b91e6j1affe45fcadda29a%40mail.gmail.com&forum_name=sdcc-user ). On 2009-05-10 and 2009-05-11 I proposed workarounds, both of which are ugly but should work and are also pretty close to what the compiler would have to generate -- unfortunately the overhead is quite noticeable.

    The problem is that the PIC14 port does not save the pseudo stack locations (STKxx) during interrupts -- but does not hesitate to destroy them on the first function call from inside the interrupt handler. The workaround is to copy all ~16 pseudo stack locations to a "safe place"(TM) on interrupt handler entry and restore them at its exit.
    Sorry for the inconvenience.

    Best regards

    Raphael

     
  • Raphael Neider
    Raphael Neider
    2009-08-27

    • labels: --> pic14 target
    • milestone: --> known_bugs
    • assigned_to: nobody --> tecodev
     
  • Gál Zsolt
    Gál Zsolt
    2009-09-09

    • status: open --> closed
     
  • Maarten Brock
    Maarten Brock
    2009-09-10

    Raphael and other developers,

    Do you think this workaround is good enough to keep this bug closed? I was kind of surprised that allthough confirmed to exist and not fixed it was closed by the O/P. I would prefer to keep it open.

    Maarten

     
  • Raphael Neider
    Raphael Neider
    2009-09-13

    I think the workaround is work around a compiler bug and not *the* solution. I'd agree to keep this item open for others to find more easily.

     
  • Raphael Neider
    Raphael Neider
    2009-09-13

    • status: closed --> open
     
  • Maarten Brock
    Maarten Brock
    2011-09-18

    • summary: array index handling in interrupt --> PIC14: array index handling in interrupt
     
    • Category: --> PIC14