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_rb not working correctly

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



Joined: 06 Feb 2008
Posts: 240
Location: Chester

View user's profile Send private message

#int_rb not working correctly
PostPosted: Thu Aug 23, 2012 4:21 am     Reply with quote

Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 5:09 am     Reply with quote

You _must_ (repeat _must_) read port B, inside the RB handler. Read the data sheet.....

Register 9-1 note at the end of the table.

You can just read the bit you are using, not the whole port.

It is reading the port, that clears the 'mismatch' condition. Unless this is done, RB will trigger for ever.

Best Wishes
carl



Joined: 06 Feb 2008
Posts: 240
Location: Chester

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 5:14 am     Reply with quote

Sorry Ttelmah,

Just found the answer and changed the code and I think it is working.
Code:

/////// MASTER PROGRAM ////////

#include <18F4550.H>

#fuses EC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOUSBDIV, NOPBADEN, NOVREGEN
//#fuses ECPLL, PLL1, CPUDIV1, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP, NOPBADEN, NOVREGEN
#use delay(clock=48000000)
#use standard_io(a)     
#use fast_io(c)     
#use standard_io(d)
#use standard_io(e)
#use standard_io(b)

#define TRIS_VAL (0b00000000) //BO = SPI MASTER (SDO) = INPUT. B1 = SPI MASTER (CLK) = OUTPUT
#define TIC_CHECK2             PIN_B2  //LED ILLUMINATION (LED_PIN6) //
int tic;

#int_rb
void detect_rb_change() {
int8 c;
  tic = 1;
  output_high(TIC_CHECK2);
c = input_b();
}

void main (){
int c;

SETUP_ADC_PORTS(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_psp(PSP_DISABLED);
setup_ccp1(CCP_OFF);
set_tris_c(TRIS_VAL);

   port_b_pullups(TRUE);
   delay_us(10);  // Allow time for them to pull-up to +5v
   c = input_b();    // Clear mismatch condition
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);
 
while (true){
 

   if (tic) {
        output_low(TIC_CHECK2);
tic =0;
}       
}       
}   


THanks
Carl
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 7:46 am     Reply with quote

Just a few comments:

Yes, the interrupt does have to be cleared 'every time', but the compiler does this for you. Unless you specify the option 'NOCLEAR' in the interrupt handler declaration, the compiler secretly adds the clear instruction.

However your 'clear_interrupt' line does nothing!.
Problem is that INT_RB, (as with some of the other 'hardware event' interrupts permanently triggers, _until the hardware event is cleared_. So (for example), an INT_RDA handler, _must_ read the received character, otherwise the 'clear interrupt' instruction is executed, and the interrupt immediately sets again...
So, to clear the INT_RB, if it was triggered at the start of the program, requires you to read port B (to clear the condition), and then clear the interrupt. Not reading the port, means that if the interrupt was set, it'll immediately set again....

Standard interrupts that have 'hardware requirements' like this are:

INT_RB
INT_RDA
INT_TBE
INT_SSP

On more sophisticated chips, there are others.

In these cases, the hardware event, must be dealt with, before the interrupt can be cleared.


Best Wishes
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