Author Topic: [Bitcloud] Using WDT as an interrupt generator  (Read 2134 times)

0 Members and 1 Guest are viewing this topic.

Offline danergoTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
[Bitcloud] Using WDT as an interrupt generator
« on: October 24, 2016, 08:36:22 pm »
Hello guys

I'm using an ATMEGA256RFR2 and regarding WDT, I stucked in a bit.
I wanted to use the Interrupt mode or the "Interrupt and System Reset Mode". (Datasheet page 218).

Bitcloud has its own WDT functions.
I setup first a callback with HAL_RegisterWdtCallback(afunction);
And then I start the WDT with HAL_StartWdt(WDT_INTERVAL_8000);

In the "afunction" I restart the WDT with HAL_StartWdt(WDT_INTERVAL_8000); again.
This is needed because as per the datasheet, in the Interrupt and System Reset Mode, the first WDT overflow will generate an interrupt, and the second one will reset the IC. But if I set again the WDIE, the next one will also generate the interrupt. And HAL_StartWdt(...) sets this WDIE in the register.

However, my chip keeps restarting itself.

Do you have any idea, what could be the reason of this?

Thank you.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: [Bitcloud] Using WDT as an interrupt generator
« Reply #1 on: October 24, 2016, 11:48:39 pm »
Do you have any idea, what could be the reason of this?
You start WDT once and for all. In the interrupt you need to call HAL_ResetWdt() to extend the timeout.
Alex
 

Offline danergoTopic starter

  • Regular Contributor
  • *
  • Posts: 111
  • Country: hu
Re: [Bitcloud] Using WDT as an interrupt generator
« Reply #2 on: October 27, 2016, 06:43:07 am »
It seems the callback is not getting executed.
Does not matter if I call HAL_StartWdt or HAL_ResetWdt in the callback, the chip restart in every 8 seconds.

Registration should be as easy as this, right?
HAL_RegisterWdtCallback(afunction);

Thanks
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11269
  • Country: us
    • Personal site
Re: [Bitcloud] Using WDT as an interrupt generator
« Reply #3 on: October 27, 2016, 08:09:06 pm »
It looks like you will actually have to change WDT code. Apparently when WDE bit is enabled in WDTCSR, then reset action is triggered on IRQ exit and manual restart does not help.
Alex
 
The following users thanked this post: danergo

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: [Bitcloud] Using WDT as an interrupt generator
« Reply #4 on: October 28, 2016, 02:49:06 pm »
Quote
I wanted to use the Interrupt mode or the "Interrupt and System Reset Mode". (Datasheet page 218).

I have never used wdt as a timer on your particular chip but have done similar things on other chips - latest being a lm3s811.

Two words of caution:
1. WDT is a very valuable resource to be wasted on something this trivial. There is no other mechanism on a typical mcu that will trigger a reset with simple passage of time, but plenty of peripherals to measure time.
2. WDT in my view is a terrible timing device. it is generally not accurate and its "in-accuracy" varies with temperature / voltage a lot.

So I would suggest that you do NOT use it for timing purposes.

If you do, maybe coding the registers directly is the way to go.
================================
https://dannyelectronics.wordpress.com/
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: [Bitcloud] Using WDT as an interrupt generator
« Reply #5 on: October 28, 2016, 09:06:39 pm »
What is that HAL stuff doing there?
There are literally just 3 bits and a prescaler in a single register.

If you read the manual you'll see that it has many exceptions regarding the use of the WDT.
Your use is not standard. Therefore it will need a non-standard init.
One of them is that you can't clear the WDE when WDRF is true.

If you are in the WDT interrupt, and don't clear the right bits. You chip will reset upon return.
« Last Edit: October 28, 2016, 09:09:04 pm by Jeroen3 »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf