trouble using interrupt in atmega328p INT0

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello everyone,

 

I'm using external interrupt INT0 which is falling edge triggered and i'm displaying no. of triggers on LCD but as soon as I trigger it my LCD gets blank.

The interrupt subroutine of the code that I have written is as below,

ISR (INT0_vect)
{
	my_freq++;
	lcd_gotoxy(1,1);
	b = my_freq%10;
	c = my_freq/10;
	d = c%10;
	c = c/10;
	b = b + 48;
	c = c + 48;
	d = d + 48;
	lcdData(c);
	lcdData(d);
	lcdData(b);
}

here my_freq is the variable which I want to display on LCD and before that I'm converting it to ASCII.

 

and the code which I have written works nicely on Proteus but I have trouble using it on Arduino Uno (but I have used Atmel Studio for coding).

 

I have used internal pull up resistor too. The ckt that i have used is below and the power supply connection and any other connection are not shown for simplicity. 

 

and the part of code for initializing interrupt is as below

        PORTD = 1<<2;
	EICRA = 1<<ISC01;
	EIMSK = (1<<INT0);
	sei();

 

 

This topic has a solution.
Last Edited: Thu. Dec 15, 2016 - 05:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Switches bounce. That is why you never put a button on an INTn pin (except, maybe, to wake the AVR from sleep). The way to read button states is to sense the state regularly in a timer interrupt. When a button has been seen in a fixed state for a number of interrupts (may 5 lots of 10ms say?) then you can consider it to have stopped bouncing and reached a stable state.

 

BTW does your LCD library really not have an lcd_puts() kind of function? if it did you could just itoa() the my_freq value and then lcd_puts() the result rather than all those % and / operations.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried giving pulses through pulse generator but the problem is still the same.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you have the LCD stuff in the interrupt anyway? You should never put such "heavy" work in an ISR(). In the ISR do nothing but increment the count. Use the slow loop in main() to show this to the end user from time to time. Human's are a bit notorious for not needing an update every fraction of a second. In fact if you try to give them much more than about 5 or 10 updates per second there little brains won't be able to cope anyway. One side effect of this is that to the human brain a fast changing LCD will just look "blurred" anyway. Oh and most cheap STN LCD displays have a liquid crystal that takes about 200ms to switch state anyway so even if the human brain doesn't blur things the LCD liquid will anyway!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You never floating a MCU Pin.

Please PULL UP PD2 Pin with 10k Resistor.

শূন্য  - The ZeRo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think atmega328 have internal pull up.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Pull UP.....  Only if you enable the internal pull up on the port pin, did you?

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You never floating a MCU Pin.

If he has a pulse generator attached to the pin, then the pin is not floating.

Regards,
Steve A.

The Board helps those that help themselves.