Atmega32u4 Interrupt

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

Hi I have been trying and reading to get interrupts working INT6, but i just cant get it to work. Eventually it will be used to wake it from sleep but at the moment i cant get it to do anything.

#include 
#include 
#define F_CPU 7372800
#include 

ISR(INT6_vect) //Input capture two
{
   PORTD ^=_BV(PB7);
   _delay_ms(30);
}

int main(void)
{	
   DDRD |=_BV(7);
   PORTD|=_BV(7);
   PCICR |= (1 << PCIE0);
   PCMSK0 |= (1 << PCINT6);

   sei();

   for(;;)
   {
   }			
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

INT6 (PD6) has NOTHING to do with PCINT6 (PB6). So which one are you trying to use?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I want to use INT6 so i can wake up the CPU after sleep. I thought PCINT6 was INT6? I made the above program to test it so & LED changes when the Input pin changes.

I just want one Pin only to wake up the CPU say PCINT6. Is this possible?

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

Read chapter 11 of the atmega32u4 datasheet carefully. There are two different classes of external interrupts on avrs.

Firstly, there's the "INT" interrupts which can be configured to trigger on a low logic level, or a specific change in the logic level. There are 5 of these pins on the 32u4, and each has a separate ISR.

Secondly, there's the "PCI interrupt, which only triggers on when the logic level changes (hence the name "pin change interrupt"). There are 8 of these signals on the 32u4; they share a common ISR.

Table 7-2 tells you the conditions that the INT and PCI can be used to wake the 32u4 from sleep.

- S

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

Ok now that's a trick i didn't realize there was a INT6 PIN (PE6). The below code has the update to make the ISR work properly. However im working on the sleep mode now. Is that all i have to do to get it into sleep mode? The current draw still seems to high. What current levels would you expect to see in sleep mode?

#include 
#include 
#define F_CPU 7372800
#include 

void Sleep_Init()
{
   SMCR |=(1<<SM0)|(1<<SM1)|(1<<SM2); //Extended Standby
   SMCR |=(1<<SE); //Enable sleep mode
}

ISR(INT6_vect)
{
   SMCR &=~(1<<SE); //Disable sleep mode
   PORTD ^=_BV(PB7);
   _delay_ms(30);
   SMCR |=(1<<SE);  //Enable sleep mode
}

int main(void)
{   
   DDRD |=_BV(7);
   PORTD|=_BV(7);
   EICRB &=~ (1<<ISC60)|(1<<ISC61); //Active when low
   EIMSK|= (1<<INT6); //external pin interrupt enable.
   sei();
   Sleep_Init();

   for(;;)
   {
   }         
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

What current levels would you expect to see in sleep mode?

The values indicated in the datasheet.

-- How are you measuring current draw?
-- Low-level interrupts keep triggering. Recent discussion: https://www.avrfreaks.net/index.p...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I'm measuring current draw with my fluke 189, it has a uA scale if i need it. It wasn't going that low only about 5mA.
Its true about the Low-level interrupts keep triggering if you hold it low but it seems there is no option to change it due to the mode im running. For my project its not ideal either, does anyone know a way around?
I have added this ASM code to it & it seems that SMCR |=(1<<SE); doesnt put it into sleep mode but this does. __asm__ __volatile__ ("sleep" "\n\t" :: );

#include 
#include 
#define F_CPU 7372800
#include 

void Sleep_Init()
{
   SMCR |=(1<<SM0)|(1<<SM1)|(1<<SM2); //Extended Standby
   SMCR |=(1<<SE); //Enable sleep mode
   __asm__ __volatile__ ("sleep" "\n\t" :: );
}

ISR(INT6_vect)
{
   SMCR &=~(1<<SE); //Disable sleep mode
   PORTD ^=_BV(PB7);
   _delay_ms(30);
}

int main(void)
{   
   DDRD |=_BV(7);
   PORTD|=_BV(7);
   EICRB &=~ (1<<ISC60)|(1<<ISC61); //Active when low
   EIMSK|= (1<<INT6); //external pin interrupt enable.
   sei();

   for(;;)
   {
   Sleep_Init();
   }         
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Enabling Sleep in SMCR is not the same as actually going to sleep.In .asm this is how it's done.

sleep_sequence:
	ldi	temp,0x07		;enable SLEEP in
	out	smcr,temp		;POWER SAVE MODE
	sleep				;enter POWER SAVE MODE
awakened:
	out	smcr,zero		;disable POWER SAVE MODE

How C handles this I don't know.
sleep() ?

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

Quote:

I'm measuring current draw with my fluke 189, it has a uA scale if i need it. It wasn't going that low only about 5mA.

I mean: Are you measuring input power to the regulator, or to the AVR?
Quote:

The current draw still seems to high. What current levels would you expect to see in sleep mode?


Why don't you >>tell us<< what your readings are, and what you expect them to be?

What is connected to your AVR?

Quote:

Its true about the Low-level interrupts keep triggering if you hold it low but it seems there is no option to change it due to the mode im running. For my project its not ideal either, does anyone know a way around?

Did you read the thread I linked to? Or not? Low-level interrupts are discussed and pin-change mentioned.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Thanks for that Lennart im not sure how its done either its not sleep(); i tried it. I think the line i added tells the C compiler a certain part of it is asm & to use it.
Does anybody else know how if im doing it right/can answer the above question?

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

Quote:

I mean: Are you measuring input power to the regulator, or to the AVR?

Damn i meant to say after the regulator. I know the test regulator i have draws 1mA. I might look into another.

Quote:

Why don't you >>tell us<< what your readings are, and what you expect them to be?
What is connected to your AVR?

I did tell you what the current was 5mA but i thought that was too high. Using the latest code i have it down to 142.41uA. Good luck finding current levels for modes in the data sheet.

The IC is on a home made PCB with a regulator, crystal, 3 capacitors & two resistors. Nothing special.

Quote:

Did you read the thread I linked to? Or not? Low-level interrupts are discussed and pin-change mentioned.

Yes i did. When i read the data sheet for the device it tells me i can only use INT6 low level but in other parts there is mention of a pin change etc so confusing. If so how would i code that to wake it up?

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

Ok here is the code to wake it from sleep using edge triggering. It seems you can use pin change interrupt to wake the device from sleep. That was vague for me in the data sheet & no one said the golden words "yes you can" haha. You can configure more than one port to do the edge triggering but i only needed one. Just bear in mind if use more than one pin they will jump to the same vector.

#include 
#include 
#define F_CPU 7372800
#include 

void Sleep_Init()
{
   SMCR |=(1<<SM0)|(1<<SM1)|(1<<SM2); //Extended Standby
   SMCR |=(1<<SE); //Enable sleep mode
   __asm__ __volatile__ ("sleep" "\n\t" :: );
}

ISR(PCINT0_vect)
{
   SMCR &=~(1<<SE);  //Disable sleep mode
   PORTD ^=_BV(PB7); //Toggle LED (for testing)
}

int main(void)
{   
   DDRD |=_BV(7);
   PORTD|=_BV(7);
   PCMSK0 |= (1<<PCINT6); //Use PCINT6 = PB6 pin 30.
   PCICR |= (1<<PCIE0);   //Enable Pin change interrupt
   sei();

   for(;;)
   {
   Sleep_Init();
   }         
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

It seems you can use pin change interrupt to wake the device from sleep. That was vague for me in the data sheet & no one said the golden words "yes you can" haha.

??? I gave a link, and said pin-change was mentioned. the linked thread has several pin-change mentions, including one quoting the datasheet that, indeed, says "yes you can". But you told me in no uncertain terms that
Quote:

Quote:

Did you read the thread I linked to? Or not? Low-level interrupts are discussed and pin-change mentioned.

Yes i did.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

You have to spell it out for the simple folk, i said it was confusing. I knew you would have some cheap comeback like that. Im glad someone understands the fine points of the datasheets but i wanted to talk to a person.
As for the other link i didn't see anything applicable to solve the problem that he had or mine. So to me it was worthless & even more confusing. Poor guy i hope he got it in the end.
A better response would have been "Yes you can" "Heres how you do it" with a basic code example. Now i don't think that's hard if you know what you are talking about.
At the end of the day its really hard to interpret someone elses problem because language has heaps of barriers.

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

OP wrote:
Does anybody else know how if im doing it right/can answer the above question?
WHICH question ?
Quote:
It seems you can use pin change interrupt to wake the device from sleep.That was vague for me in the data sheet & no one said the golden words "yes you can" haha.

warren1 wrote:
You have to spell it out for the simple folk, i said it was confusing.

...A better response would have been "Yes you can" "Heres how you do it" with a basic code example. Now i don't think that's hard if you know what you are talking about.

mnehpets gave you the CLEAR direction where in the 'sheet to look and he indicated that it was possible, under the right conditions . You NEVER mentioned his FULL answer to your question at all :roll:. It's right there in plain English in the 'sheet . Since you read it, if that section was still confusing, you should've came back and just brought up WHAT about it you didn't get .

OP wrote:
When i read the data sheet for the device it tells me i can only use INT6 low level but in other parts there is mention of a pin change etc so confusing.
Don't just say "it's confusing...", be SPECIFIC . That column is stating that INT6, INT3-INT0 ( FIVE INTx pins ), AND pin change ( i.e. ALL of them ) . But this is EXACTLY what mnehpets wrote to you, and so it really shouldn't have been confusing AT ALL ! Also it's PLAINLY written and you shouldn't be sounding like NOBODY gave you the help needed to get the answer from the datasheet, in addition to him giving the answer ( So, answered it AND told you where in the 'sheet to find it :) ). The STRICT answer to your question would've been "yes you can. " and left it at that . But you wouldn't have learned how to find that in the 'sheet yourself .
Quote:
Good luck finding current levels for modes in the data sheet.
See sections 29 & 30, the info's in multiple places .

As for getting less current draw, read the REST of section 7, not just the sleep part . Your code shows that you didn't, as far as Imin_while_sleeping .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Offensive language removed. Further similar outburts will be reported which may result in a ban.

Thread locked - JS.

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

This is a very sad thread. Don't regulars here "get it"? This is a "happy place". Please try a bit harder. If you start to write an aggressive answer then maybe stop and think (a) will this help the OP and (b) why am I doing this - it's only a message board about programming micros after all.

Topic locked