Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

using an interrupt just for wakeup

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR
View previous topic :: View next topic  
Author Message
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Thu Jun 30, 2016 7:13 am    Post subject: using an interrupt just for wakeup Reply with quote

Hi

i want to use int0 of atmega64 just for wakeing up microcontroller from powerdown mode by an external signal. also i dont want to do any instruction in interrupt isr. i want to know if i dont use "on int0 int0_isr" what will happen?

i want to dont go to any interrupt service routine and dont save any register to save time, is it possible?

Regards

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 702

poland.gif
PostPosted: Thu Jun 30, 2016 10:57 am    Post subject: Reply with quote

Atmega64 is a oldboy I think.
Only Low level on interrupt pin can wake micro from powerdown.
Maybe change to something equivalent and new will be better idea.
For example look how I`v made dimmer for stairs to truck Razz
If you open the door then two steps are slowly highlited.
I use PCINT with nosave to wake up micro.

Code:
$regfile = "attiny13a.dat"
$crystal = 1200000
$hwstack = 10
$swstack = 9
$framesize = 9

Config Submode = New

Config Portb = &B000110 : Portb = &B001000

Sw1 Alias Pinb.3

Config Timer0 = Timer , Prescale = 8 , Compare A = Disconnect , Compare B = Disconnect , Clear Timer = 1
Enable Compare0a : On Compare0a Int0_isr Nosave : Compare0a = 180

Dim P1 As Byte
Dim P2 As Byte
Dim Licznik As Byte
Dim Speed As Byte
Dim Mark As Byte


Pcmsk = &B001000
Enable Pcint0 : On Pcint0 Pcint_isr Nosave


Enable Interrupts

Sub Calc_speed(byval Pwm As Byte)

 Speed = 127 - Pwm
  Shift Speed , Left , 1

End Sub

Do



  If Speed = 0 Then                                        

     If Sw1 = 0 Then                                'if switch pressed

       If P1 < 100 Then                                     'if PWM LED1 <100% then
        Incr P1                                             'slowly rise
         Call Calc_speed(p1)                                'calc speed for state of PWM LED1
       Else                                                 'if PWM LED1 is 100% then
        If P2 < 100 Then
         Incr P2                                            'slowly rise second LED
          Call Calc_speed(p2)
        End If
       End If

     Else                                                   'if switch is released
                                                             'if PWM > 0 then decrase slowly
       If P1 > 0 Then
        Decr P1                                             'and if PWM is 0 then..
       Else

          Config Powermode = Powerdown                      'go to sleep here

          '** MICRO SLEEP HERE AND AFTER WAKE UP BEGIN FROM THAT POINT **


       End If

       If P2 > 0 Then Decr P2
        Call Calc_speed(p1)                                 'calculate for both

     End If

  End If

Loop
End

Int0_isr:

  $asm
  PUSH R16
  PUSH R20
  PUSH R24
  PUSH R26
  !in R24, sreg
  PUSH  R24
  $end Asm

  Incr Licznik
   If Licznik = 100 Then Licznik = 1
   If Licznik > P1 Then Reset Portb.1 Else Set Portb.1
   If Licznik > P2 Then Reset Portb.2 Else Set Portb.2

    If Speed > 0 Then Decr Speed
  '          Tuned with NoSave Tool

  $asm
  POP  R24
  !out sreg, r24
  POP R26
  POP R24
  POP R20
  POP R16
  $end Asm

Return

Pcint_isr:

  'this only wake micro so no instructions here

Return
 
Back to top
View user's profile Visit poster's website
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Thu Jun 30, 2016 12:21 pm    Post subject: Reply with quote

thank you

but, forget atmega64 and other hardware recomandation, please say me obviousely my answer.

my question:
if i use below instruction:

config int0=rising(/falling/change)
enable int0

do

loop
end

what will happen after trigering int0 pin?

Regards
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 702

poland.gif
PostPosted: Thu Jun 30, 2016 1:12 pm    Post subject: Reply with quote

I think you can save a lot of time by due test yourself instead asking for direct answears on forum Razz
Yes, I test it for you because this cost me 1min only
Code:
$regfile = "m64def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32

Config Portd.4 = Output : Led Alias Portd.4

Portd.0 = 1                                                 ' pullup on INT0

Config Int0 = Low Level
Enable Int0 : On Int0 Int0_isr Nosave
Enable Interrupts

Do

 Config Powermode = Powerdown

  Set Led

Loop
End

Int0_isr:
Return


and I can confirm that this int wake from Powerdown. Are U satisfied ? Very Happy
Back to top
View user's profile Visit poster's website
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Thu Jun 30, 2016 1:43 pm    Post subject: Reply with quote

EDC wrote:


and I can confirm that this int wake from Powerdown. Are U satisfied ? Very Happy


No Razz Razz Razz
i tested it befor!

again: consider your edited program:
Code:

$regfile = "m64def.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 32

Config Portd.4 = Output : Led Alias Portd.4

Portd.0 = 1                                                 ' pullup on INT0

Config Int0 = Low Level
Enable Interrupts

Do

 Config Powermode = Powerdown

  Set Led

Loop
End
 


i tested this program also, it wake microcontroller on from powerdown, but i want to know whether bascom compile this code to assembly!
i think it never jamp to 0 and no push and no pull happen for proccesing interrupt isr, is it true?
and also i want to know is there any problem with using this type of interrupt without any subroutine? and to be sure from no overflow or other problems.

thanks a lot
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 702

poland.gif
PostPosted: Thu Jun 30, 2016 1:55 pm    Post subject: Reply with quote

You can watch asm code generated by opn OBJ file in Atmel Studio..but I want save your time again Very Happy
Code:
16:16:       Do
17:      
18:        Config Powermode = Powerdown
000000DA: B775     IN        R23, $35            Load an I/O Location to Register
000000DC: 7C73     ANDI      R23, $C3            Add without Carry
000000DE: 6370     ORI       R23, $30            Logical OR with Immediate
000000E0: BF75     OUT       $35, R23            Store Register to I/O Location
000000E2: 9588     SLEEP                         This instruction sets the circuit in sleep mode defined by the MCU Control Register
19:      
20:         Set Led
000000E4: 9A94     SBI       $12, 4              Set Bit in I/O Register
21:      
22:       Loop
000000E6: 940C     JMP       $00DA               Jump
23:       End
000000EA: 94F8     BCLR      7                   Bit Clear in SREG
000000EC: CFFF     RJMP      $-0000 (00EC)       Relative Jump
24:      
25:       Int0_isr:
26:       Return
000000EE: 9518     RETI                          Return from Interrupt
 


So I think yo cannot enable interrupt without vector for it. And when ISR is executed then hardware clear Int flag.
If you use Nosave then you must carry if any of registers is used. In none of them - no problem Very Happy


Last edited by EDC on Thu Jun 30, 2016 2:04 pm; edited 1 time in total
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Thu Jun 30, 2016 2:04 pm    Post subject: Reply with quote

if an int occurs and there is no vector defined, there is only a RETI.
the vector table contains either RETI or a jump to the ISR.

_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 702

poland.gif
PostPosted: Thu Jun 30, 2016 2:15 pm    Post subject: Reply with quote

Yes but most important thing is that only LOW LEVEL can wake up from Powerdown and I think uC not execute any next command till pin goes high. But I`m not shure about that Very Happy
Back to top
View user's profile Visit poster's website
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Thu Jun 30, 2016 5:16 pm    Post subject: Reply with quote

thanks a lot EDC
thanks a lot Mark

Quote:
PostPosted: Thu Jun 30, 2016 2:15 pm Post subject:
Yes but most important thing is that only LOW LEVEL can wake up from Powerdown and I think uC not execute any next command till pin goes high. But I`m not shure about that Very Happy


from datasheet:

Note that recognition of falling or rising edge interrupts
on INT7:4 requires the presence of an I/O clock, described in “Clock Systems and
their Distribution” on page 35. Low level interrupts and the edge interrupt on INT3:0 are
detected asynchronously. This implies that these interrupts can be used for waking the
part also from sleep modes other than Idle mode. The I/O clock is halted in all sleep
modes except Idle mode.
Note that if a level triggered interrupt is used for wake-up from Power-down mode, the
changed level must be held for some time to wake up the MCU. This makes the MCU
less sensitive to noise.

so int0-3 can wakeup uc from powerdown in atmega64

Regards
Back to top
View user's profile
karlos

Bascom Member



Joined: 03 Apr 2015
Posts: 107

PostPosted: Thu Jun 30, 2016 6:01 pm    Post subject: Reply with quote

EDC wrote:
You can watch asm code generated by opn OBJ file in Atmel Studio..but I want save your time again Very Happy
Code:
16:16:       Do
17:      
18:        Config Powermode = Powerdown
000000DA: B775     IN        R23, $35            Load an I/O Location to Register
000000DC: 7C73     ANDI      R23, $C3            Add without Carry
000000DE: 6370     ORI       R23, $30            Logical OR with Immediate
000000E0: BF75     OUT       $35, R23            Store Register to I/O Location
000000E2: 9588     SLEEP                         This instruction sets the circuit in sleep mode defined by the MCU Control Register
19:      
20:         Set Led
000000E4: 9A94     SBI       $12, 4              Set Bit in I/O Register
21:      
22:       Loop
000000E6: 940C     JMP       $00DA               Jump
23:       End
000000EA: 94F8     BCLR      7                   Bit Clear in SREG
000000EC: CFFF     RJMP      $-0000 (00EC)       Relative Jump
24:      
25:       Int0_isr:
26:       Return
000000EE: 9518     RETI                          Return from Interrupt
 


So I think yo cannot enable interrupt without vector for it. And when ISR is executed then hardware clear Int flag.
If you use Nosave then you must carry if any of registers is used. In none of them - no problem Very Happy


sorry, i dont work with atmel studio up now, i install atmel stdio 6 and try to open one of my .obj files and the following error occur:
Error in updatimg the Debug Levels
why this error happen?
how can i open my obj file like what you put here?

Regards
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum