avr tiny 3216 wake with interrupt pin

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

Im trying to figure out the wake / interrupt on the AVRtiny 1.   My interrupts are working for the Hall effect sensor, But when the system goes to sleep I would like the AVR to wake when the Hall effect changes or the wake pin is clicked.  Can anyone give me some direction?   

 

I am running the ARV at 1mhz at 3v.  running milliamps is 4 and sleep is 1.8.  I would like to get the sleep mA closer to .7, any advice lowering my sleep amperage would be appreciated.

 

// wake pin 

#define PC0_INTERRUPT PORTC.INTFLAGS & PIN0_bm
#define PC0_CLEAR_INTERRUPT_FLAG PORTC.INTFLAGS &= PIN0_bm
#define PC0_LOW !(PORTC.IN & PIN0_bm)

#define F_CPU 3333333UL  //sleep function
 

//RTC ISR //////////////////////////////////////////////////////
ISR(RTC_CNT_vect)
{
RTC.INTFLAGS = RTC_OVF_bm;
}

 

void setup()
{

PORTC.DIR &= ~PIN0_bm; //seta PA7 to input DISPLAY button
PORTC.PIN0CTRL |=PORT_PULLUPEN_bm;
PORTC.PIN0CTRL |=PORT_ISC_FALLING_gc; // enables pull up and configures interrupt for PA7
}

 

void loop() { 

    ISR(PORTC_PORT_vect){
      if(PC0_INTERRUPT){wakeDisplay();PORTC.INTFLAGS &= PIN0_bm;}  //PC0_CLEAR_INTERRUPT_FLAG DISPLAY   PORTA.OUT ^=PIN4_bm;
      if(PC1_INTERRUPT){pulseCounter();PORTC.INTFLAGS &= PIN1_bm;}  //PC1_CLEAR_INTERRUPT_FLAG HALL
      }
}

 

    // SLEEP SETUP
          void sleep2()
          {
            //Configure pins: ////////////////////////////////////////
            
            // Set all pins to low power mode:
            for (uint8_t i = 0; i < 8; i++) {
              *((uint8_t *)&PORTA + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
            }
          
            for (uint8_t i = 0; i < 8; i++) {
              *((uint8_t *)&PORTB + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
            } 
          
            //RTC INIT: //////////////////////////////////////////////
          
            while (RTC.STATUS > 0) {} // Wait for all register to be synchronized
          
            RTC.PER = 1024*10; //10 secs between wakes.
            RTC.INTCTRL = 0 << RTC_CMP_bp
            | 1 << RTC_OVF_bp; //Overflow interrupt.
            
            RTC.CTRLA = RTC_PRESCALER_DIV1_gc //NO Prescaler
            | 1 << RTC_RTCEN_bp         //Enable RTC
            | 1 << RTC_RUNSTDBY_bp;     //Run in standby
          
            RTC.CLKSEL = RTC_CLKSEL_INT1K_gc; // 32KHz divided by 32, i.e run at 1.024kHz
          
            _delay_ms(6000); //Consumes high power for 6secs before going into eternal sleep (to see a change in measurement on the DMM).
            
            //Enable interrupts //////////////////////////////////////
            sei();
            
            //Main loop: /////////////////////////////////////////////
            while (1) {
              set_sleep_mode(SLEEP_MODE_STANDBY);
              sleep_enable();
              sleep_cpu(); //Go into sleep
              
              //On awakening
              _delay_ms(2000); //Stay still for power measurement with DMM.
            }
          }
 

 

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

I have never done a sleeping app so not good at good advice. However have you looked at the data sheet 11.3.2.1 Sleep Modes?

 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Hello,  yes, but I have not figured out where to put the sleep disabled command,  I expect it comes before the setup(void) since the command runs from sleep mode but I’m not certain how to make it fire

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

Your code seems Arduino style (ie no Main) so is this an Arduino board?

 

In which case I guess that the sleep command should be in the "loop" which is the Arduino thing for main.

 

It seems to me that the Sleep stuff is never executed because Arduino goes from Setup to Loop and stays there for ever.

 

But I could be very wrong, I'm even worse in Arduino land. sad

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

any advice lowering my sleep amperage would be appreciated

A schematic is needed, since even one pull resistor up/down could draw several mA  

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

I pasted parts of my large code.  Yes there are many things missing here, but they should not be necessary to help with what I expect is a small snippet at the beginning or end of the code.

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

  I would like to get the sleep mA closer to .7, any advice lowering my sleep amperage would be appreciated.

Your schematic will need to include the hall part number as well. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Since this looks like Arduino, have you looked at Arduino samples for wake from sleep mode?

I found this with a quick search: https://thekurks.net/blog/2018/1... but I'm sure there are dozens of these examples to choose from.

I would suggest you write a simple sleep/wake with pin change interrupt sketch, once you have that working, then add to your bigger project.

If you have problems with that, post the complete sketch that demos the problem for help, otherwise you will get a LOT of back and forth posts that will be confusing as the complete issue is unknown.

Good luck

Jim

 

 

FF = PI > S.E.T

 

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

Only pins Px2 and Px6 are asynchronous, so to wake from a pin interrupt when CLK_PER is not running you have restrictions on all the other pins. You are using falling edge for the pin interrupt which will not work when CLK_PER is not running (standby). So you use level or bothedges which can wake from any sleep mode, including powerdown which in this case is probably what you want if you are after power saving and the pins (or pit) is all you require to wake.

 

For power saving with pins, you can run through all the pins in early code to set them all to INPUT_DISABLE. This is better than pullups because it always works and has the same power saving without the possibility you are now sourcing power on one of your pins via the pullup. This also means any pin used as an input will have to be taken out of INPUT_DISABLE when used or initialized, but it also means all unused pins are already taken care of in early code and you do not have to deal with them again. If using c++ (via arduino I guess), there would be a possibility pins being init via global constructor so if your own init sequence to disable inputs happen later, then you would lose the pin input (you will know if it happens, and either init the pin yourself or move your input disable init code to a section that runs before the c++ global constructors). I somehow doubt they are initializing any pins via global constructor.

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

 Thanks Guys, this give me plenty of details I can search for. 

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

bobioknight wrote:
Only pins Px2 and Px6 are asynchronous, so to wake from a pin interrupt when CLK_PER is not running you have restrictions on all the other pins. You are using falling edge for the pin interrupt which will not work when CLK_PER is not running (standby). So you use level or bothedges which can wake from any sleep mode, including powerdown which in this case is probably what you want if you are after power saving and the pins (or pit) is all you require to wake.

 

This bit of wisdom worked wonders.  Thanks for this info.