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

Please Help - Stuck in Port B Interrupt

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



Joined: 06 Feb 2010
Posts: 2

View user's profile Send private message

Please Help - Stuck in Port B Interrupt
PostPosted: Sat Feb 06, 2010 11:45 pm     Reply with quote

Hi, can someone please help me with a problem I am having.
Please find below the code I have been working on. I am capturing 2 pins changing from high to low using ports RB5 & RB4 and INT_RB.

I have put a 'printf' debug line in the Port B ISR which is showing me that I am in a contentious loop.

CCS V4.093
Target PIC Microcontroller = PIC16F648A
Standard Run Mode
Target voltage = 5V
Target oscillator speed = 20Mhz Crystal

Code:

#include <16F648A.h>
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, NOPUT
#use delay(clock=20M)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, stream=PC)

int wgnd_buffer[4];
long wgnd_timeout;
short wgnd_timer2_started;
int c;

#INT_RB
void RB_ISR()
{
   if (!input(PIN_B5))            // Wiegand Data 1 PIN goes Low
   {
       wgnd_timeout = 0;
      shift_left(wgnd_buffer,4,1);
      printf("1");
      wgnd_timeout = 0;
      wgnd_timer2_started = 1;
   }

   if (!input(PIN_B4))            // Wiegand Data 0 PIN goes low
   {
       wgnd_timeout = 0;
      shift_left(wgnd_buffer,4,0);
      printf("0");
      wgnd_timeout = 0;
      wgnd_timer2_started = 1;      
    }   
//   printf("  xx  ";
   c = input_b();
   clear_interrupt(INT_RB);
}

#INT_TIMER2                     // Timer 2 ISR
void Timer2_ISR()               // 1 ms  Timer - Used for timeout & Wiegand send timing
{
   if (wgnd_timer2_started == 1)
      wgnd_timeout++;            // Increment Timer for Wiegand Timeout

   if (wgnd_timeout >= 1000)      // 200ms Wiegand "End Transmission" Timeout
   {
      printf("  %X,%X,%X,%X",wgnd_buffer[3],wgnd_buffer[2],wgnd_buffer[1],wgnd_buffer[0]);   
      wgnd_buffer[0] = 0;
      wgnd_buffer[1] = 0;
      wgnd_buffer[2] = 0;
      wgnd_buffer[3] = 0;
      wgnd_timeout = 0;
      wgnd_timer2_started = 0;
      printf("  %X,%X,%X,%X,\r\n",wgnd_buffer[3],wgnd_buffer[2],wgnd_buffer[1],wgnd_buffer[0]);   
   }
   clear_interrupt(int_timer2);
}

/*
int1 check_Parity(unsigned int8 index,unsigned int32 wgnd_buffer)
{
   int1 pResult   =0;
   unsigned int8 i=0;

   for (i=index; i<index>>16) & 0xFF;
               printf(bputc,"\r\nSite Code = %U ** ID Code = %LU \r\n",siteCode,idCode);
               wiegandData = 0;
}
*/

void main()
{
   port_b_pullups(TRUE);
   delay_us(200);                    // Allow time to pull-up port b to +5v
   setup_timer_2(T2_DIV_BY_16,0x63,2);      // Setup Timer 2 - 1ms
   c = input_b();
   clear_interrupt(INT_RB);
   clear_interrupt(INT_TIMER2);
   enable_interrupts(INT_RB);
    enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);       
   while(true);
   {
      
   }
   
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 07, 2010 1:30 am     Reply with quote

Quote:
enable_interrupts(INT_RB);

Troubleshoot your code. Comment out the enable line for the Timer2
interrupts. This will remove all the #int_timer2 code from the program.
See if you still get the problem. If you still get the problem, then keep
on removing code until you don't.

Quote:

I am capturing 2 pins changing from high to low using ports RB5 & RB4
and INT_RB.

What is the frequency of the signals on pins RB4 and RB5 ?
Guest








PostPosted: Sun Feb 07, 2010 2:27 am     Reply with quote

I have commented all of the code out except the following. I have also disconnected the RB4 & RB5 lines so they should both be high because of the internal pullups.
Still I am stuck in the PortB Inturrupt loop with "test" streaming out the RS232 port.

Code:

#include <16F648A.h>
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, NOPUT
#use delay(clock=20M)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, stream=PC)

int wgnd_buffer[4];
long wgnd_timeout;
short wgnd_timer2_started;
int c;

#INT_RB
void RB_ISR()
{
   printf("test");
   c = input_b();
   clear_interrupt(INT_RB);
}

Code:

void main()
{
   port_b_pullups(TRUE);
   delay_us(200);                    // Allow time to pull-up port b to +5v
//   setup_timer_2(T2_DIV_BY_16,0x63,2);      // Setup Timer 2 - 1ms
   c = input_b();
//   clear_interrupt(INT_TIMER2);
   enable_interrupts(INT_RB);
//    enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);       
   while(true);
   {
      
   }
   
}
Ttelmah
Guest







PostPosted: Sun Feb 07, 2010 3:37 am     Reply with quote

Realistically, I have to say you have a hardware problem.
In your code, the 'clear_interrupts(INT_RB)' is unnecessary, but won't cause any harm.
I'd expect the code to print once on wake up, since the inputs will probably be low, when power is first applied, and will then go high, when you turn on the pull-ups. Hence the interrupt will trigger, and print. Since it is repeating, it implies one of several things:
1) There is still a signal attached to one of the RB4 to RB7 pins.
2) Your board has a noise problem, either leading to it resetting, or triggering the inputs. Remember that the pull up's are only a few uA.
3) MCLR is floating.
4) The supply itself is not stable.

Best Wishes
nathan_m



Joined: 06 Feb 2010
Posts: 2

View user's profile Send private message

PostPosted: Sun Feb 07, 2010 4:06 am     Reply with quote

Thank you for your suggestions. It will give me a place to start. I will let you know how it goes.
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