sleep modes and external interrupts

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

i am using a mega 16.

i want my controller to be in idle sleep mode till an external interrupt is trigerred (edge trigerred).

can i use INT0/INT1 for it? becoz its given in the data sheet that these can trigger interrupts only by low level signal when controller is in idle mode.

and what is the c function for sleep instructio?

Last Edited: Mon. Jan 14, 2008 - 11:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You should be OK for Idle mode.

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

vicky3413 wrote:
and what is the c function for sleep instructio?

Different for each C compiler.

If it happens to be GCC then take a look at (and the user manual of course!)

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

guys i wanted to use my mega16 in sleep mode.so i got an idea of making a water tank level controller.
in this i am using two level indications.one at the top and one at the bottom.
the transition from high to low signal on the lower level indicator (no water at bottom to conduct signal) generates an interrupt through INT0.
through the corresponding isr it turns on the bit controlling the pump

the transition from low to high on the high level indicator(tank full) generates an interrupt through INT1 .through the corresponding isr it turns off the bit controlling the pump.

1)But the problem here is I am not sure whether wen no water is present at a particular pin(floating).will it indicate a zero to my avr or not.

2)and also the avrstudio isn't simulating it properly.it stops in between.

//overhead tank water level controller
//d2 output for relay to the pump
//INT0 low level interrupt
//INT1 high level interrupt

#include
#include
#include
 
 
ISR(INT0_vect)
   {
      PORTD|=(1<<0); //make pin high
	  
	  
    } 
 
ISR(INT1_vect)
   {
     PORTD &=~(1<<0); //make pin low
	 
	
	}
 
int main(void)
 {
  
  DDRD|=(1<<0);
  
  MCUCR|=(1<<SE);            //enabling sleep mode
  
  MCUCR&=~(1<<SM0)&~(1<<SM1)&~(1<<SM2); //selecting idle mode
  
  MCUCR|=(1<<ISC01);//falling edge interrupt sense on INT0
  
  MCUCR|=(1<<ISC11)|(1<<ISC10);//rising edge interrupt sense on INT1
  
  GICR|=(1<<INT0)|(1<<INT1); //interrupt enable
  
  sei();           //enable global interrupt
  
  for( ;;)
    {
      void sleep();
    }
 }  
  
  

8)

Last Edited: Mon. Jan 14, 2008 - 11:51 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
1)But the problem here is I am not sure whether wen no water is present at a particular pin(floating).will it indicate a zero to my avr or not.

Avoid floating pins for input, whether you use interrupts or not. Use a resistor to pull the pin up or down when the switch is open. That way you'll always have a well defined logic signal at the pin. The simplest solution is to have the switch pull the input low, in which case you can enable the internal pull-up to keep the input in high state when the switch is open.

If you use some sort of mechanical switches for level detection, be aware of switch bounce. A lot of useful information about interrupts can be found in this thread:
https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=55347

Edit: You set the SM0, SM1 and SM2 bits. That should give extended standby mode - not idle. In extended standby, edge interrupts won't wake the MCU from sleep. Idle mode should work however.

Last Edited: Mon. Jan 14, 2008 - 07:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
2)and also the avrstudio isn't simulating it properly.it stops in between.
Please look up the "Stimuli and logging" section of the Help for Simulator. You'll need to create a stimuli file.

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

vicky,

don't forget to run a filter before accepting an input level. I mean something like the debounce routine for mechanical switches or buttons.

This must be done after each time the controller awakes from an interrupt in order to recognize if the ExtInt reason was a real input or noise.

Michael

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

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

thanks knutbr,i have corrected the sleep mode,(i am fond of setting bits (1<<XYZ) :) )

if i set my interrupt pin directions as output would it solve my floating pin problem?

thanks michael ,nanovate, i ll try ur suggestions and getback with results

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

Setting to output would eliminate floating pins, but you wouldn't be able to read the state of the level switches. Any problems with using pull-ups? When the switch is closed there will flow a small current through the pull-up (see the datasheet for figures), but when the switch is open there won't be any extra current drain. So, if you design the circuit so that the switches are normally open, the current consumption shouldn't increase too much. Enabling an internal pull-up requires an extra line of code - that's it.