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 loop!!!! please help!!!!

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



Joined: 05 Jun 2005
Posts: 10

View user's profile Send private message

interrupt loop!!!! please help!!!!
PostPosted: Mon Jul 11, 2005 3:27 am     Reply with quote

i use a pic 18f252 and when i use interrupt my pic enter in loop.

my fuses are:

#fuses HS,NOWDT,NOPROTECT,NOLVP

my clock and hardware:

#use delay(clock=40000000)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
#use rs232(baud=115200 , xmit=PIN_C6,rcv=PIN_C7)



my initialization are:

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
//setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,20,16); //Ogni un milli secondo
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT2);
enable_interrupts(INT_TIMER2);
enable_interrupts(global);


and finaly the interrupt:


---------------------------------------------------------------------------------
#INT_TIMER2 //Controllo Tastiera
TIMER2_isr() {
TASTIERA();
}

---------------------------------------------------------------------------------

//CLEAR
#int_EXT //Clear
void int_EXT_isr(void)
{
output_low(POWER);
lcd_putc("\f");
lcd_putc("CLEAR IS DOWN \n");
delay_ms(300);
lcd_putc("\f");
output_high(POWER);
}

---------------------------------------------------------------------------------

//ON
#int_EXT2
void int_EXT2_isr(void)
{
//POWER_ON()
lcd_putc("\f");
lcd_putc("ON IS DOWN \n");
delay_ms(300);
lcd_putc("\f");

}
---------------------------------------------------------------------------------


but the pic enter in loop over the interrupt .... (reboot forever ...)
Please what i have done wrong? tanks.
valemike
Guest







PostPosted: Mon Jul 11, 2005 6:14 am     Reply with quote

You say you loop forever in the interrupt. How is your RB0 (int_ext) interrupt set up? You don't seem to have it edge triggered (H_TO_L or L_TO_H). If it is level triggered, and the pin stays at that level, then you will surely keep re-entering that interrupt. Then again, edge-triggered might be the default and my conclusion would be wrong then.
Ttelmah
Guest







PostPosted: Mon Jul 11, 2005 9:12 am     Reply with quote

The hardware only supports edge triggered interrupts, so this is not the problem. However the big question is 'what is in the routine 'tastiera()'. Also how are INT_EXT, and EXT2 triggered?.
There is a problem in the fuse statement, which makes me worry about the hardware. 'HS' is selected as the oscillator mode, and the clock rate is specified at 40MHz. The HS oscillator supports 25MHz _maximum_. To run at 40MHz, requires either using a 10MHz crystal, with H4, or an external crystal, with EC, or EC_IO.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 11, 2005 9:51 am     Reply with quote

What does your main() function look like. Did you include the forever loop?
Acktung



Joined: 05 Jun 2005
Posts: 10

View user's profile Send private message

mmm
PostPosted: Mon Jul 11, 2005 10:37 am     Reply with quote

ok ... i have a 40MHz crystal .... so the fouse became?

but ... now the firmware run good ... the serial, the delay etc ... mmmm mmmm mmmm strange!
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jul 11, 2005 10:50 am     Reply with quote

Quote:
ok ... i have a 40MHz crystal .... so the fouse became?
A 40MHz crystal will not work (according to the specifications). You may be lucky to see part of the chip functioning but you will get unpredictable errors as well...

As Ttelmah already told you, use either:
1) An external clock driver at 40MHz and set the fuse to EC or EC_IO.
2) use a 10MHz crystal and set the H4 fuse which will enable the internal 4x PLL clock multiplier.
Acktung



Joined: 05 Jun 2005
Posts: 10

View user's profile Send private message

PostPosted: Mon Jul 11, 2005 12:00 pm     Reply with quote

i am very, very, very .... but really very luky ... i have 50 pic18f252 and all run correctly, i use i2c, rs232, lcd display ... an all work perfectly ... ... but my question is not over the crystal ... (if i am luky is good, for me ... the inportant is that all work!) ... but the question is over the interrupt! ... now i test the firmware whit a 10 Mhz cristal ... and a test the interrupt ... it possible that this 40 mhz generate only this problem? .... ... now i am at home and i test it quicly ... i post the solution ...
Acktung



Joined: 05 Jun 2005
Posts: 10

View user's profile Send private message

MMMM I HAVE TESTED!
PostPosted: Mon Jul 11, 2005 1:06 pm     Reply with quote

now the mai init is:

setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
//setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,20,16); //Ogni un milli secondo
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
ext_int_edge( 2, L_TO_H); // Set up PIC18 EXT2
ext_int_edge( L_TO_H ); // Sets up EXT
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT2);
enable_interrupts(INT_TIMER2);
enable_interrupts(global);


in the .h file there are:

#include <18F252.h>
//#fuses HS,PUT,BROWNOUT,NOWDT

#use delay(clock=4000000)


i have sobstitute my 40Mhz cristal whit a 4Mhz cristal ... ...
but ... the interrupt don't work!

someone have one idea ?


(with the 4 mhz cristal the current is at 0.004 amps ... and with a 40mhz the urrent is at 0.022 amps)
Ttelmah
Guest







PostPosted: Mon Jul 11, 2005 3:06 pm     Reply with quote

What is in Tastiera()...
There have been other users who have had 40MHz crystals 'work' on these chips, but most (all...), have ended up with erratic problems on the chips.

Best Wishes
ckielstra



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

View user's profile Send private message

PostPosted: Mon Jul 11, 2005 4:26 pm     Reply with quote

So, with a 4MHz crystal it still isn't working? Then the problem must be somewhere else.

You really have to give us more to work with. In the start of this thread you said your program was constantly rebooting, is this still the case? How do you know your program is rebooting? How do you know one of the interrupts is causing your problems? Etc.

Also, Mark asked you about what is more in your main() function. Especially we want to know if you have added a way to make sure your program never ends. Normally this is done with an endless loop. Without this precaution your program will execute the sleep instruction that the compiler places at the end of main() and your program stops.

And yes, what is in Tastiera().....?
Acktung



Joined: 05 Jun 2005
Posts: 10

View user's profile Send private message

OK. ... more details ...
PostPosted: Mon Jul 11, 2005 5:20 pm     Reply with quote

this is the tastiera funtions:

void TASTIERA()
{
carattere_premuto = ' ';
SET_TASTIERA();
while (spam < 10)
{
INPUT_COLONNE();
spam++;
CLOCK_TASTIERA();
}

}


and the other :

void SET_TASTIERA()
{
output_low(RESET);
delay_ms(5);
output_high(RESET);
delay_ms(5);
output_low(RESET);
spam=0;
}


void CLOCK_TASTIERA()
{
output_low(CLK);
delay_ms(5);
output_high(CLK);
delay_ms(5); //Tempo per far salire la tensione
delay_ms(5);
output_low(CLK);
}


....


I don't think that the problem is in the code ... if simply comment the code internal of the interrupts function and i leave the main as it is ... the thing doesn't work the same.

i have made a test. I have disablet the interrupt of the timer it is i have left the others two whose funtions however they don't recall anything. the two interrupts have to go when the pin became hight (i have put a resistor of pull-down) ...

making to start the firmware the problem occurs the same ... but in theoretical line however the program didn't even have to enter in the interrupt ... in fact anybody have pressed the button (the pin became hight).

I precise again that if i comment the two function the program works perfectly.

/* <============= in this point

#int_EXT
void int_EXT_isr(void)
{

}

#int_EXT2
void int_EXT2_isr(void)
{

}

*/ <============= in this point

What do you know, as soon as do enter the interrupt i owe reset some flags?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 11, 2005 8:11 pm     Reply with quote

Don't do this
Code:
/* <============= in this point

#int_EXT
void int_EXT_isr(void)
{

}

#int_EXT2
void int_EXT2_isr(void)
{

}

*/ <============= in this point


if you have the interrupts enabled
Code:
enable_interrupts(INT_EXT);
enable_interrupts(INT_EXT2);


Or else you will constantly get interrupted and your program will seem to stop working. I think it best if you can create a small test program that will demonstrate the problem. Keep it short as possible and post the program (copy and paste) using the "code" feature when you post.
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