Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Watchdog Atmega328

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

Bascom Member



Joined: 14 Apr 2007
Posts: 21

netherlands.gif
PostPosted: Mon Apr 13, 2020 9:55 am    Post subject: Watchdog Atmega328 Reply with quote

Hey,

The maximum time "Watchdog" is 8 sec. (Atmega328).
Want to use "Watchdog" to get an Atmega329p out of "Sleep Mode" after 60 sec.
Is this possible?

Balou.

(BASCOM-AVR version : 2.0.8.2 )

_________________
Bascom-AVR 2.0.8.1
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2112

netherlands.gif
PostPosted: Mon Apr 13, 2020 11:04 am    Post subject: Reply with quote

Why with the watchdog? can't you use a regular timer.
_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
balou

Bascom Member



Joined: 14 Apr 2007
Posts: 21

netherlands.gif
PostPosted: Mon Apr 13, 2020 11:50 am    Post subject: Reply with quote

Evert,

I want the Atmega328p 60 sec. put to sleep.
And then wake up the program without external interrupt.

Balou

_________________
Bascom-AVR 2.0.8.1
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 692

poland.gif
PostPosted: Mon Apr 13, 2020 3:10 pm    Post subject: Reply with quote

Yes it is possible in that uC because you can ENABLE WDT (Watchdog Interrupt). It means that after 8s of sleep Watchdog, instead reset uC, at firs will jump into Watchdog Interrupt. Then you can Reset Watchdog, count some variable for +8s and VERY IMPORTANT - ENABLE WDT INTERRUPT AGAIN! Then you can Sleep uC again till 60s Very Happy

Below you have example on Mega328P (UNO) that will flash LED every 10sec.
For safety purpose WDT should not be reenabled in its own interrupt routine because if main program hang then those interrupts will be forever instead reset.

Code:
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 16
$framesize = 64


Config Portb.5 = Output : Led Alias Portb.5

Dim Sleep_cnt As Byte

Config Watchdog = 1024                                      ' ~1s"

Start Watchdog

On Wdt Wdt_isr Nosave

Enable Interrupts

Do

 If Sleep_cnt = 0 Then
  Sleep_cnt = 10                                            '10x ~1s

    Set Led : Waitms 50 : Reset Led                            'flash

 Else
   Decr Sleep_cnt
 End If

   Enable Wdt
    Config Powermode = Powerdown                            '->uC will go to sleep here

  'here uC will start after wake up

Loop

Wdt_isr:
 'dont enable Wdt here
Return

 
Back to top
View user's profile Visit poster's website
balou

Bascom Member



Joined: 14 Apr 2007
Posts: 21

netherlands.gif
PostPosted: Mon Apr 13, 2020 6:37 pm    Post subject: Reply with quote

Thank EDC,

It works.

Balou.

_________________
Bascom-AVR 2.0.8.1
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5060
Location: Holland

blank.gif
PostPosted: Wed Apr 15, 2020 7:18 pm    Post subject: Reply with quote

good example EDC.
I like it.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-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