Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 28, 2024, 11:36:08 23:36


Login with username, password and session length


Pages: [1]
Print
Author Topic: int_ext PIC18F4553  (Read 7624 times)
0 Members and 1 Guest are viewing this topic.
bird777
Newbie
*
Offline Offline

Posts: 14

Thank You
-Given: 0
-Receive: 3


« on: October 20, 2009, 12:57:48 12:57 »

Could anybody help me why do this some line the following:
The input is being pulled up and when I push the button than it pull down the input. I wanted to do that when I push the button than write out the "++" and when I leave it than write out the "__", but it do the following:
When I push the button the controller write out the "++" and when I push it again than write out the "__" only. I had have written already some prog but I can not understand why do it this?! Smiley

#int_ext
void RB0_megszakitas(void)
{
   if(!button_pressed)        // if button action and was not pressed
   {
      button_pressed = 1;    // the button is now down
      ext_int_edge(L_TO_H);   // change so interrupts on release
      printf("\r\n++\r\n");
   }
   else                       // if button action and was pressed
   {
      button_pressed = 0;   // the button is now up
      ext_int_edge(H_TO_L);   // change so interrupts on press
      printf("\r\n__\r\n");
   }
}
Logged
ALLPIC
Active Member
***
Offline Offline

Posts: 114

Thank You
-Given: 64
-Receive: 72


« Reply #1 on: October 20, 2009, 03:52:03 15:52 »

simple do some think like this......

unsigned char edge;
#int_ext
void RB0_megszakitas(void)
{
   if(edge == 1)        // if button action and was not pressed
   {
      ext_int_edge(L_TO_H);   // change so interrupts on release
      printf("\r\n++\r\n");
   }
   else                       // if button action and was pressed
   {

      ext_int_edge(H_TO_L);   // change so interrupts on press
      printf("\r\n__\r\n");
   }
}


void main(void)
{
...... do init

edge = 0;
ext_int_edge(L_TO_H);   // change so interrupts on release

make GE = 1;
}


Posted on: October 20, 2009, 04:50:24 16:50 - Automerged


sorry previous somethin missing....
simple do some think like this......

unsigned char edge;
#int_ext
void RB0_megszakitas(void)
{
   if(edge == 1)        // if button action and was not pressed
   {
      edge = 0;
      ext_int_edge(L_TO_H);   // change so interrupts on release
      printf("\r\n++\r\n");
   }
   else                       // if button action and was pressed
   {
      edge = 1;
      ext_int_edge(H_TO_L);   // change so interrupts on press
      printf("\r\n__\r\n");
   }
}


void main(void)
{
...... do init

edge = 0;
ext_int_edge(L_TO_H);   // change so interrupts on release

make GE = 1;
}
Logged
sam_des
Senior Member
****
Offline Offline

Posts: 253

Thank You
-Given: 124
-Receive: 146


« Reply #2 on: October 20, 2009, 06:41:41 18:41 »

Hello bird777,

I don't know what your program's actual purpose is, but I may suggest you that it is generally bad idea to use 'printf()' (or any other compiler's run-time library which makes call to function) in interrupt functions. printf() family functions usually use some statically allocated ram to parse their inputs. If you're using printf() in interrupt as well as in mainline, these static data may get corrupted, resulting in bugs which are hard to reproduce & correct.

That's why you must consult compiler manual to check if the function is re-entrant or not and I think printf() is not usually reentrant.

Hope that helps...

regrads,
sam_des
Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
bird777
Newbie
*
Offline Offline

Posts: 14

Thank You
-Given: 0
-Receive: 3


« Reply #3 on: October 21, 2009, 06:26:29 06:26 »

ALLPIC:
Thank you for your answer, but I do not understand what is the different between your lines and my line?! Smiley

sam_des:
Thank you, too, but here does not matter the pintf, I wrote there something only.
Logged
caveman508
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 12
-Receive: 6

READ, REAd, REad, Read


« Reply #4 on: November 10, 2009, 07:15:02 07:15 »

Hate to jump on you.

Servicing a push button with this type of Interrupt Service Routine (ISR) is just a mistake.  Think about how many times it is referred to in a single push... Did you de-bounce the switch in hardware?Huh 

I think you are not SEEING the point of what Sam is saying.

You are not listening, you are not following the rule of interrupts.  "Do very little in an interrupt"

Think about it, , how many edges does a switch make on a push or release?Huh  What is your baud rate???  How long does printf take to get a string out?Huh?  FAR LONGER than that switch will bounce ON-OFF-ON.  That my friend, is what Sam was talking about, , , Re-entrance........ big problems.

Set flags for the 'main' code to deal with.

NEVER CALL A FUNCTION IN AN INTERRUPT

NEVER

If you do, you will learn quick.  Or, , , you will be asking why it doesn't work, , , or complain it is the compilers fault.

Try the whole thing in assembly, write the whole thing and see, again, it doesn't work to do much of anything in an INTERRUPT routine.  Learn the golden rule, , just set flags, don't do anything that takes any time to speak of with respect to the rate of incoming interrupts.  The ENTIRE ISR needs to be done in less time than the expected rate of interrupts, by maybe 50%.  Otherwise, , when will the non-interrupt code run?Huh

Please listen to help,  the help given is correct, a great collection of minds from great people are here, helping you.  Your mind learns better when you are not on the defense.

Think like a chip in these cases, the devil lurks in the details.  Think like the robot you program, what does it see, how will it re-act???

Happy days

Caveman
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC