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

interrupt on certain pins H2W

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

interrupt on certain pins H2W
PostPosted: Wed Dec 18, 2013 3:25 am     Reply with quote

Hello! I made a program that suppose to use two interrupt pins H2W
Everything work, but the interrupt function responds with a certain delay. I mean when I press the button I need to hold it on about 1 sec to obtain isr reaction.
the code:
Code:

#include <16f1508.h>
#fuses INTRC_IO,NOMCLR,NOWDT
#use delay(clock=16M)

#define inc_butt pin_a5
#define dec_butt pin_a4
#define confirm_butt pin_c5
#define led_r pin_c3
#define led_w pin_c4
#define relay_SB pin_c6
#define T1 pin_b7
#define T2 pin_b7

unsigned int16 ms=2000;

#INT_RA
void isr()                           
{
   delay_ms(10);//to prevent debounce of button
   if(!input(inc_butt))
      output_toggle(relay_sb);
   if(!input(dec_butt))
      output_toggle(relay_sb);
   
   clear_interrupt(INT_RA5_H2L|INT_RA4_H2L);
}


void main()
{
ENABLE_INTERRUPTS(INT_RA5_H2L|INT_RA4_H2L);
ENABLE_INTERRUPTS(GLOBAL);
clear_interrupt(INT_RA5_H2L|INT_RA4_H2L);
   while (true)
   {
      output_low(led_r);
      delay_ms(MS);
      output_high(led_r);
      delay_ms(MS);
   }
}

Does anyone see something wrong?
_________________
A person who never made a mistake never tried anything new.
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Wed Dec 18, 2013 3:39 am     Reply with quote

Yes, your delay in the interrupt. When you compile you will have a warning "interrupts disabled to prevent re-entrancy" or similar, meaning while in delay routine interrupts will not work.

Regards
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Wed Dec 18, 2013 7:30 am     Reply with quote

Ok if I have delay inside interrupt function, this apparently is a problem (because of the latency). In other hand, if I remove that delay I got button debounce, that cause re-entrance interrupt. Is there solution on my problem anyway?
_________________
A person who never made a mistake never tried anything new.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Dec 18, 2013 8:20 am     Reply with quote

You could try using one of the hardware timers to deal with the debounce.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Dec 18, 2013 8:36 am     Reply with quote

Or you can do the entire operation using a 'tick' interrupt instead of the edge interrupt.

As you have found, buttons/keys don't give nice edges, so using the edge interrupt is often pointless. Instead read the inputs in a tick at (say) 100Hz. If they are 'made' for two successive ticks, then accept as a input.

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9228
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Dec 18, 2013 8:48 am     Reply with quote

Here's an 'inline' debounce code segment
...
#define LT PIN_B1 ;pin with switch

while (!input(LT) ) ; //wait if low
delay_ms(20); //debounce delay
while (input(LT) ) ;//wait if hi
delay_ms(20); //debounce delay
...

may be 'rude and crude' but it does work.
reversing the order of the whiles,change if looking for h2l or l2h .

hth
jay
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Thu Dec 19, 2013 1:34 pm     Reply with quote

Thank you guys! What did good job for me was the modifying of the hardware. I put capacitor parallel to the button, then I removed the delay inside the interrupt function and everything got better and steady as well. So, software delay might work well either, but I don't want to have any disturbance into the switch cycle. It would violate the timing (may be insignificantly) of the cycle.
Thank you again!
_________________
A person who never made a mistake never tried anything new.
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