CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

bank access, globals and fast ISR

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Joyce
Guest







bank access, globals and fast ISR
PostPosted: Fri May 14, 2004 3:18 pm     Reply with quote

Folks,

Here is the problem:

I have a global varible that is shared between a fast ISR and the main line. The variable is set in the main line to know the ISR when to send a byte over SPI bus. The code looks something like this:

char TxBuffer[32];
char TxIndex;
char StartTxFlag;
char BytesToSend;

#INT_EXT FAST
void CPLD_RW_Byte_Isr(void)
{
#asm
MOVFF FSR0L,fsr0l_save
MOVFF FSR0H,fsr0h_save

MOVFF INDF0,indf0_save
#endasm
if (input(CPLD_RW))
{

}
else
{
if (input(CPLD_MODE))
{
if (StartTxFlag == START)
{
CpldCSOn();
spi_write(TxBuffer[TxIndex]);
CpldCSOff();

TxIndex++;
if (TxIndex >= BytesToSend)
{
StartTxFlag = STOP;
TxIndex = 0;
}

}
else
{
CpldCSOn();
CpldCSOff();
}
}
else
{
CpldCSOn();
CpldCSOff();
}
}

#asm
MOVFF fsr0l_save,FSR0L
MOVFF fsr0h_save,FSR0H
MOVFF indf0_save,INDF0
#endasm
}

The function that starts the transmission:
void TxMsg(void)
{
int8 i=0;
TxBuffer[i++] = 0x11;
TxBuffer[i++] = 0x22;
StartTxFlag = START;
}

As a detail the interrupt is periodic and is serviced in 2 ways: when there is nothing to be sent the interrupt is cleared. When the data in TxBuffer is valid I should put a byte on the SPI in less than 6.5 us.

Now here is the problem: sometimes when the StartTxFlag is read in the ISR it returns the value different than START. I tracked this problem down to the point that when the read is made I'm on the wrong bank. At least this is what is think. All the variables StartTxFlag, TxBuffer, TxIndex are placed 01E and 0A7 (Bank 0).
After studing the assembly I figured that only 3 registers are touched by ISR and I save them. Should I do something else at the beginning of the ISR ?
How do I force a read from Bank 0 ? I thought that the compiler does this automatically if I have a "#device *=16" in place.

Any ideas ?
Do I need a

#asm
MOVLB 0
#endasm

in my ISR ?

Thanks a lot.
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Mon May 17, 2004 7:57 am     Reply with quote

You should use the "code" formatting button when posting code. It makes it much easier to read. There is no way to know what bank you will be in when the interupt occurs. I can't recall if this is one of the registers that are pushed to the stack but you will have to set the bank from within the interupt.

You should also look at making these functions inline. Use #inline and see how it compiles diferently.

CpldCSOn();
CpldCSOff();
Joyce
Guest







PostPosted: Mon May 17, 2004 8:18 am     Reply with quote

Thanks Neutone for the tip on formatting the code. I didn't notest there is such a button.

These 2 functions:
CpldCSOn();
CpldCSOff();

are just macros that are equivalent with output_high(pin) and output_low(pin).
Joyce
Guest







PostPosted: Mon May 17, 2004 8:24 am     Reply with quote

I'll just post it again....this time with the wright format.

-----
Code:

char TxBuffer[32];
char TxIndex;
char StartTxFlag;
char BytesToSend;

#INT_EXT FAST
void CPLD_RW_Byte_Isr(void)
{
#asm
    MOVFF FSR0L,fsr0l_save
    MOVFF FSR0H,fsr0h_save
    MOVFF INDF0,indf0_save
#endasm

    if (input(CPLD_RW))
   {

   }
   else
   {
        if (input(CPLD_MODE))
       {
           if (StartTxFlag == START)
          {
               CpldCSOn();
               spi_write(TxBuffer[TxIndex]);
               CpldCSOff();

               TxIndex++;
               if (TxIndex >= BytesToSend)
               {
                    StartTxFlag = STOP;
                    TxIndex = 0;
                }

            }
            else
            {
                 CpldCSOn();
                 CpldCSOff();
             }

      }
      else
     {
           CpldCSOn();
           CpldCSOff();
      }
}

#asm
MOVFF fsr0l_save,FSR0L
MOVFF fsr0h_save,FSR0H
MOVFF indf0_save,INDF0
#endasm
}

The function that starts the transmission:
void TxMsg(void)
{
int8 i=0;
TxBuffer[i++] = 0x11;
TxBuffer[i++] = 0x22;
StartTxFlag = START;
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 17, 2004 8:31 am     Reply with quote

Which compiler version are you using?

I'm using PCH v3.187 and I too had a bank switching problem in my fast interrupt last week. I took the quick approach for solving by moving my variable to bank 0.

Right now it looks like I'm having another bank switching issue, will keep you informed.
Joyce
Guest







PostPosted: Mon May 17, 2004 11:09 am     Reply with quote

I'm using PCH 3.186 with a 18F452 part.

I had some problems with the my fast Isr. To solve the problem I located all the variables used by Isr in bank 0.
First instruction to be executed by the Isr is

MOVLB 0

So far it looks good.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group