|
|
View previous topic :: View next topic |
Author |
Message |
carl
Joined: 06 Feb 2008 Posts: 240 Location: Chester
|
#int_rb not working correctly |
Posted: Thu Aug 23, 2012 4:21 am |
|
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Aug 23, 2012 5:09 am |
|
|
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
|
|
Posted: Thu Aug 23, 2012 5:14 am |
|
|
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: 19552
|
|
Posted: Thu Aug 23, 2012 7:46 am |
|
|
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 |
|
|
|
|
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
|