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 interrupts only once

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








#int_RB interrupts only once
PostPosted: Tue Dec 15, 2009 4:15 pm     Reply with quote

Hi!

I'm using "EX PBUTT" example without any success.

I do not want to post many lines on code I've been working on lately... used simple yet known example.

The problem I'm having is: When constant ON OFF change from external circuit is on 'port b pin' 4 to or 7 interrupt fires only once at the very start and then program goes to while loop.


Defining change on 'port b pin' 4 to 7 : I've tried button 5V switching and switching between PIC internal pull ups and pic ground.


My target:

At the very moment Logical 1 (+5V) is on port b pin 4-7 interrupt fires.
fires to execute if statement and change some variables and flags.

My question nr 1:

If almost but not exact same time 2 (coinciding) Logical 1s are on port b .
Will interrupt work as only 1 Logical 1 is on ?

My question nr 2:

How long it will take to execute if (really complex and large ) statement ?
OK or really(exponentially) long ?
Code:

#include <18F45K20.h>

#define LOWTOHIGH TRUE
#define HIGHTOLOW FALSE

short int dbutton4, dbutton5, dbutton6, dbutton7;

//-----------------------------------

#INT_RB
void detect_rb_change(void)
{

   int current;
   static int last=0;

   set_tris_b(0x00);
   current=input_b();

   printf("Current on %u",current);
   

   #if LOWTOHIGH
   if ((!bit_test(last,4))&&(bit_test(current,4))) {dbutton4=1;}
   if ((!bit_test(last,5))&&(bit_test(current,5))) {dbutton5=1;}
   if (!(!bit_test(last,6))&&(bit_test(current,6))) {dbutton6=1;}
   if ((!bit_test(last,7))&&(bit_test(current,7))) {dbutton7=1;}
   #elif HIGHTOLOW
   if ((!bit_test(current,4))&&(bit_test(last,4))) {dbutton4=1;}
   if ((!bit_test(current,5))&&(bit_test(last,5))) {dbutton5=1;}
   if ((!bit_test(current,6))&&(bit_test(last,6))) {dbutton6=1;}
   if ((!bit_test(current,7))&&(bit_test(last,7))) {dbutton7=1;}
   #endif

   last=current;

}

//----------------------------------------------

void main() {
   clear_delta();

   enable_interrupts(INT_RB);
   enable_interrupts(GLOBAL);

   output_low(PIN_B0);
   while (TRUE) {
      if(dbutton6) {
        output_high(PIN_B0);
        dbutton4=FALSE;
      }
      if(dbutton7) {
        output_low(PIN_B0);
        dbutton5=FALSE;
      }
   }
}

Thank you in advance.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 15, 2009 4:47 pm     Reply with quote

Do you have push-buttons on pins B4 to B7, or some kind of signals ?
If they are signals, describe them completely:

1. Frequency
2. Duty cycle
3. Rectangular waveform or sinewave ?
4. Voltage levels (high and low)
5. Clean or noisy ?

Post your #fuses statement, #use delay() statement, and your
compiler version.

Quote:
set_tris_b(0x00);
current=input_b();

Here, you are setting the TRIS to all output pins. That's wrong, but
it won't have any effect, because you're not using #fast i/o mode
(unless you secretly are, and didn't show it).

Make sure you post your compiler version, because certain bugs that
involve setting up the IOCB register in the "K" series PICs were only
very recently fixed.
MiniMe



Joined: 17 Nov 2009
Posts: 50

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 1:03 am     Reply with quote

Hi !

You were absolutely correct. It was a bug, because the problem is gone by changing pic mcu.

How to fix this bug wthout changing compiler version ?

Can i find this bug on smaller PIC18 K20 ?


Thank you, you saved big amount of my time !
Guest








PostPosted: Sat Jan 23, 2010 8:05 am     Reply with quote

Now I've got latest compiler and still I'm having problems with RB interrupt.
Device is 18F45K20. Program code is example EX_PBUTT.

Program code is working with different device 18F4550 and 18F4520.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 24, 2010 2:13 pm     Reply with quote

The 18F45K20 has some bugs in the start-up code for the analog pins
and the comparator pins. It also has a problem in the code that enables
interrupt-on-change interrupts. Add the lines shown in bold below.
The changes shown will probably make it work.
Quote:


#byte IOCB = 0xF7D
#byte ANSEL = 0xF7E
#byte ANSELH = 0xF7F


void main() {

clear_delta();

enable_interrupts(INT_RB);

setup_comparator(NC_NC_NC_NC);
IOCB = 0xF0;
ANSEL = 0;
ANSELH = 0;

enable_interrupts(GLOBAL);
MiniMe



Joined: 17 Nov 2009
Posts: 50

View user's profile Send private message

PostPosted: Tue Jun 08, 2010 9:02 am     Reply with quote

PCM programmer, Thank you !



By using Your solution, my problem is solved.
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