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

whats wrong with this interrupt ???

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







whats wrong with this interrupt ???
PostPosted: Sat Sep 27, 2008 10:53 am     Reply with quote

Its not working and I have spent so much time to find out whats wrong in my code. I use pic16f690.
I am trying to move my robot forward and when he gets interrupt in A2 - high- he should stop all engines for a while. Instead, he does nothing.
Please help me find what is wrong here. (probably not the hardware)
Code:

#include <16F690.h>       
#fuses XT,NOWDT,NOPROTECT,put
#use delay(clock=8000000)
#include <stdlib.h>
#define RAND_MAX 2

#int_ext
void int_ext_isr()
{
 output_low(PIN_C2);
 output_low(PIN_C5);
 delay_ms(6000);
}
 
 
void main() {

enable_interrupts(global);
enable_interrupts(INT_EXT);
ext_int_edge( L_TO_H );

output_high(pin_b6);  //TURN ON THE LED FOR A WHILE
delay_ms(5000);
output_low(pin_b6);
 
   while(1)
   {
        output_high(PIN_C2);//go straight
        output_low(PIN_C3);
        output_high(PIN_C5);
        output_low(PIN_C4);
       
        output_high(pin_b6); //BLINK A LED
        delay_ms(300);
        output_low(pin_b6);
        delay_ms(300);
   }
   
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 27, 2008 12:21 pm     Reply with quote

Quote:
Instead, he does nothing.

Does this mean that the motors don't run ? Does it mean that the
program doesn't do anything ? If so, you should first make a simple
program that blinks an LED. See the following sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=34785&start=3
This will prove if your hardware works.

If the program does something, but it's just that the interrupt doesn't
work, then answer these questions:

1. What are the voltage levels of the signal on pin A2 ? Post the voltages
of the high and the low levels.

2. What is the Vdd Voltage of your PIC ?

3. What's your compiler version ?
ron
Guest







its not my first time..
PostPosted: Sat Sep 27, 2008 5:28 pm     Reply with quote

OK this is not my first time with pic or hardware.
hardware is working great. No blink is needed.
The robot goes straight and when interrupt is on high he does nothing.
But, interrupt get 5V and I have checked it.

It's for sure the code.
I don't think it relevant all other details... the code isn't good.
Someone can correct my code? Please ?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Sep 27, 2008 6:46 pm     Reply with quote

Code:
#fuses XT,NOWDT,NOPROTECT,put
#use delay(clock=8000000)
The XT fuse does not support 8MHz, use HS instead. An often made beginner's error...
Quote:
I don't think it relevant all other details... the code isn't good.
I don't see other obvious errors in the shown code, so if the above fix doesn't solve your problem I think all questions of PCM Programmer _are_ relevant.
ron
Guest







PostPosted: Sun Sep 28, 2008 12:27 am     Reply with quote

I was working with the XT fuse all time and other things I did worked just fine.

Someone told me something about debounce.... ???
Does the way I do interrupt is good ? I think that something simple is missing here...

I don't have to tell the chip something about the pin A2 ? a condition ? How does he know that this is the pin ?
Ttelmah
Guest







PostPosted: Sun Sep 28, 2008 2:42 am     Reply with quote

INT_EXT, _is_ pin A2.
You don't have to tell the compiler anything else, other than declare the handler, and enable the interrupts.
However, see below...

Obvious other comment, are you _sure_ the pin is actually going up/down. Have you got a pull-down resistor on it?.
Normal practice, would be to have the switch, pull the pin _down_ (not up), and enable the internal pull-up resistor in the chip.

Some comments though:
1) Set the interrupt 'direction', _before_ enabling the interrupt, and clear the interrupt. When you change the interrupt direction, you can get a 'spurious' interrupt.
2) Look at the data sheet. Is there anything else 'using' this pin?.

setup_comparators(NC_NC_NC_NC);
setup_timer1(T1_DISABLED);

3) Correct the oscillator fuse. You may well find that with XT selected, the chip becomes unreliable starting up, or sometimes runs on an undertone frequency.

I suspect you will find it is the comparator that is actually causing the problem.

Best Wishes
Ttelmah
Guest







PostPosted: Sun Sep 28, 2008 3:02 am     Reply with quote

As a further comment, on the 'debounce' question, it doesn't really apply to a situation like this. The problem is that since switches can give 'noisy' makes, you can get multiple triggers. If you were using it for a key, you would then see perhaps two or three keystrokes. On the key, you can also get bounce, when the key is released, leading to further unwanted actions.
In your case, once the first 'edge' is seen, the handler won't respond to anything else fo 6 seconds, so any 'bounce' can be ignored.

Best Wishes
Guest








PostPosted: Sun Sep 28, 2008 9:30 am     Reply with quote

thank you very much i will try all of this.

to let you know the capacitor between a2 to ground helps a lot.

you said :
setup_comparators(NC_NC_NC_NC);

the compiler says this is error....
Ttelmah
Guest







PostPosted: Sun Sep 28, 2008 10:47 am     Reply with quote

Shouldn't have an 's'. Just 'setup_comparator'.

Best Wishes
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Sun Sep 28, 2008 5:54 pm     Reply with quote

As a general comment, your intended code will leave the ISR sitting in a 6000ms delay loop.

This is generally not a good idea within ISR's. They should swiftly handle external (asynchronous) events, not clog the system up for several seconds.
Consider using a state machine or similar with flag variables if you need to such handle long time intervals.
Guest








PostPosted: Mon Sep 29, 2008 11:51 am     Reply with quote

how do i clean interrupts?
i know i have to clean the flag bits INTF and RABIF , but how do i do this ????
thanx.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Sep 29, 2008 12:32 pm     Reply with quote

Please post new questions in a new thread.

If you use the CCS interrupt dispatcher, the compiler will clear the interrupt flag for you. The PORTA Change Interrupt Flag (RABIF) is a bit special in that you also have to clear the 'mismatch' condition by reading from (or writing to) PORTA.
See this thread for an RA interrupt example.
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