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 CCS Technical Support

int_global ISR not working for INT0 interrupts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dlc@frii.com



Joined: 05 Nov 2003
Posts: 23

View user's profile Send private message

int_global ISR not working for INT0 interrupts
PostPosted: Tue Feb 21, 2006 1:10 pm     Reply with quote

Hi all,

I'm trying to interrupt on receiving IR transmissions on the negative edge. I've set all I need and CCP1 to measure the pulses, I've set up the ISR and done the #int_global setup based on a CCS example that I modified a little. But it appears that I'm not getting the interrupt. I'll post the code here, it is pretty short.

I'm looking for what I've missed. I'm used to coding using Microchip's C18 which doesn't hide much from you so I may be not seeing something that is happening here. I've just added the setup_comparator() call, I've not tested that just yet...

thanks,
DLC

Code:



#include <16F628.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOCPD,NOBROWNOUT,MCLR
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1)
#use fast_io(A)
#use fast_io(B)

#define MAXBIT 13         //5 address, 7 control and one junk timing
int rise[MAXBIT];
int rW=0;
int gotOne = 0;

//save_w and save_status are at 7f and 7e which are available in ALL banks
int save_w;
#locate save_w=0x7f
int save_status;
#locate save_status=0x7e
#byte status = 3
#byte TMR1L = 0x0E
#byte TMR1H = 0x0F
#byte PIR1 = 0x0C
#byte CCPR1H = 0x16

#int_global
void isr(void)
{
   #asm
      //store current state of processor
      MOVWF save_w
      SWAPF status,W
      MOVWF save_status
      BCF   status,5                              //Set to page 0 for SFR's
      BCF   status,6
   #endasm
   
      rise[rW++] = CCPR1H;                        //save the pulse time
      if (rW == MAXBIT)
      {
         rW = 0;
   }
   gotOne = 1;
      TMR1L = 0;
      TMR1H = 0;
   
      #asm
      // restore processor and return from interrupt
      SWAPF save_status,W
      MOVWF status
      SWAPF save_w,F
      SWAPF save_w,W
      BCF PIR1,2
      #endasm 
}                               

void main()
{
   int x;
   int n=0;
   
   set_tris_B(0x03);
   set_tris_A(0x00);

   //Turn off comparator
   setup_comparator(NC_NC_NC_NC);

      setup_ccp1(CCP_CAPTURE_FE);    // Configure CCP1 to capture falling edge detection
      setup_timer_1(T1_INTERNAL);    // Start timer 1

   for (x=0;x<MAXBIT;x++)
      rise[x]=0;
      
      enable_interrupts(INT_CCP1);   // Setup interrupt on falling edge
      enable_interrupts(GLOBAL);

   printf("SONY IR decoder\n\r");
   
      while(TRUE)
   {
         delay_ms(1000);
         if (n)
         {
            output_low(PIN_A1);
            n=0;
       }
       else
       {
          output_high(PIN_A1);
          n=1;
      }
         if (gotOne)
         {
            for (x=0;x<MAXBIT;x++)
               printf("\n\r%u %u counts ",x, rise[x]);
         gotOne = 0;
      }
      }
}


_________________
--
------------------------------------
Dennis Clark dlc@frii.com
http://www.techtoystoday.com
------------------------------------
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Tue Feb 21, 2006 1:19 pm     Reply with quote

This may not be what you're hoping for, but when I wrote a program to decode a remote control's signals there was no way I could get it to work using the CCP. I tried for a long time, then went a slightly different route:
http://www.ccsinfo.com/forum/viewtopic.php?t=21290

I ended up using the external interrupt instead. I have no idea why the CCP-based code wouldn't work, but this worked the first time.

Hope this helps.
Ttelmah
Guest







PostPosted: Tue Feb 21, 2006 3:04 pm     Reply with quote

One thing leaps out.
When writing an int_global, it is _your_ responsibility to save every register that is used in the interrupt. Now your interrupt routine, is using an array access, so will be using the indirect access registers. You are not saving these...
The 'example', does not make any such access, so can get away without these extra saves.

Best Wishes
dlc@frii.com



Joined: 05 Nov 2003
Posts: 23

View user's profile Send private message

PostPosted: Tue Feb 21, 2006 3:09 pm     Reply with quote

Ttelmah wrote:
One thing leaps out.
When writing an int_global, it is _your_ responsibility to save every register that is used in the interrupt. Now your interrupt routine, is using an array access, so will be using the indirect access registers. You are not saving these...
The 'example', does not make any such access, so can get away without these extra saves.

Best Wishes


Good point - While nothing else SHOULD be using those registers, CCS may be doing something I don't know about. I'll fix that goof.

DLC
_________________
--
------------------------------------
Dennis Clark dlc@frii.com
http://www.techtoystoday.com
------------------------------------
dlc@frii.com



Joined: 05 Nov 2003
Posts: 23

View user's profile Send private message

PostPosted: Tue Feb 21, 2006 3:10 pm     Reply with quote

All,

One goof I made in the subject line: I said INT0 IRQ, I meant CCP1 IRQ.

oops,
DLC
_________________
--
------------------------------------
Dennis Clark dlc@frii.com
http://www.techtoystoday.com
------------------------------------
Ttelmah
Guest







PostPosted: Tue Feb 21, 2006 3:32 pm     Reply with quote

dlc@frii.com wrote:
Ttelmah wrote:
One thing leaps out.
When writing an int_global, it is _your_ responsibility to save every register that is used in the interrupt. Now your interrupt routine, is using an array access, so will be using the indirect access registers. You are not saving these...
The 'example', does not make any such access, so can get away without these extra saves.

Best Wishes


Good point - While nothing else SHOULD be using those registers, CCS may be doing something I don't know about. I'll fix that goof.

DLC


The rise[x] access in main, will use the indirect addressing registers as well.

Best Wishes
Guest








PostPosted: Mon Feb 27, 2006 1:14 pm     Reply with quote

newguy wrote:
This may not be what you're hoping for, but when I wrote a program to decode a remote control's signals there was no way I could get it to work using the CCP. I tried for a long time, then went a slightly different route:
http://www.ccsinfo.com/forum/viewtopic.php?t=21290

I ended up using the external interrupt instead. I have no idea why the CCP-based code wouldn't work, but this worked the first time.

Hope this helps.


As it turns out, after I fixed a couple of goofs with my wiring, and recode my ISR to handle saving variables and clean up a few more odds-n-sods things... The ISR works just fine. I added a Timer1 overflow interrupt as well to detect timeouts so that I can properly re-sync if I need to get the next command. It all works just fine now. Thanks all that helped out.

I am working with a toy remote for my 4 year old to animate one of his toys and it has a "sort of RC5" output with oddities that mean that I can't assume any particular command pulse length, it's variable. This code handles it just fine.

DLC
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