Simulator 2 and WDT interrupts [SOLVED]

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

Guy's

Has anybody 'actually' managed to simulate a wdt interrupt using the simulator?
I mean, actually have code that operates as expected. (An interrupt only, not a reset).
I've been mucking around all day trying to simulate a deep sleep and wdt-int wake up, to no avail. I ended up trimming the code to remove the sleep, just to trace the wdt int event.) I've searched (possibly) a hundred threads, and I've implemented several ideas from them, but still, no interrupt fires.
I'm simulating an ATtiny13 which, according to the doc's has WDT simulation support, but I can't get it to fire. (Studio 4.18sp3)
I can't post code as it's all at work, and I'm at home now.
If anyone has succeeded in simulating this, could you post the code please, so I can try it out?

Thanks.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

Last Edited: Tue. Apr 19, 2011 - 09:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have not tried an interrupt, but it seems the wdt timer is always based on a cpu speed of 1 MHz. So if you've set a speed of 128KHz it would take 8 times longer than you'd expect.

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

I let it run for some considerable number of cycles (many times). I tried various prescaler settings. Sadly, you can't actually see inside the wdt itself, so you have to rely on it's effects, which were, also sadly, nothing!
The simulation was at 1Mhz (9600000/ 8 ) all fuses at default.

In all the threads I've read through, nobody has posted an example that they've claimed that worked, which is what I'm looking for.

I realise that once I've burned the code to a chip, the results will probably stand on their own. But I'm interested in proving the solution in the simulator first.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

The wdt.h file doesn't have code for wdt_ISR, so you have to modify it for that and it then works. In wdt.h you have the tests for defines of mega and a few tiny series MCU then an #else ( where you have to use out instruction only ). In that section put this :

#define wdt_enable_ISR(value)   \
    __asm__ __volatile__ (  \
        "in __tmp_reg__,__SREG__" "\n\t"    \
        "cli" "\n\t"    \
        "wdr" "\n\t"    \
        "out %0, %1" "\n\t"  \
        "out __SREG__,__tmp_reg__" "\n\t"   \
        "out %0, %2" \
        : /* no outputs */  \
        : "I" (_SFR_IO_ADDR(_WD_CONTROL_REG)), \
        "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)),   \
        "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
            _BV(WDTIE) | (value & 0x07)) ) \
        : "r0"  \
    )

This is just the wdt_enable code for this section with WDTIE bit instead of WDE. Of course my code should be in an

#ifdef tiny13

, if needed .

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

Thanks Indy, I've used that define in my main.c
It's an idea I got from one of Cliff's postings about this issue with the wdt.h
It didn't have the desired effect. In fact, the ISR still didn't fire.
Have you tried this to confirm you can get the interrupt to fire in the simulator?

Quote:
I realise that once I've burned the code to a chip, the results will probably stand on their own. But I'm interested in proving the solution in the simulator first.

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Yes in the simulator and simulated accurately ( 30 mS timeout ). Worked every time, perfectly. Show your code implementation, let me check it out. What version of Studio do you have ?

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

Uh... thats in the first post :)

Hang on..

/* Initial Test

	ATtiny13

*/

#define F_CPU	9600000UL / 8


#include 
#include 
#include 
#include 

#define wdt_int_enable(value)   \
__asm__ __volatile__ (  \
    "in __tmp_reg__,__SREG__" "\n\t"    \
    "cli" "\n\t"    \
    "wdr" "\n\t"    \
    "sts #0,#1" "\n\t"  \
    "out __SREG__,__tmp_reg__" "\n\t"   \
    "sts #0,#2" "\n\t" \
    : /* no outputs */  \
    : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
    "r" (_BV(_WD_CHANGE_BIT) | _BV(WDTIE)), \
    "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \
        _BV(WDTIE) | (value & 0x07)) ) \
    : "r0"  \
)


volatile long outer_cnt = 0;
volatile int beep_flag = 0;

void Beep(void)
{
	// beep here
	PORTB |= (1 << 1);		// to see in simulator
	beep_flag = 0;
	
}


// watchdog should just loop
// until we want to do a beep
ISR(WDT_vect)
{
	outer_cnt++;
	if(outer_cnt > 1)
	{
		beep_flag = 1;
		outer_cnt = 0;
	}
	WDTCR |=  (1<<WDTIE);	// set back on
}

void Setup(void)
{
	DDRB = 0x3f;			// all pins output
	wdt_reset();

	//wdt_enable(WDTO_8S);	// maximum 8 seconds

	
	//WDTCR = (1<<WDCE); //  | (1<<WDP2);
	

	//WDTCR =  (1<<WDTIE) | (1<<WDP2);
	//WDTCR &= ~(1<<WDE);	// clear reset

	wdt_int_enable(WDTO_30MS);

	sei();
	Beep();
	
}



int main(void)
{

	Setup();

	while(1)
	{
	/*
		sleep_enable();
        sei();
        sleep_cpu();
        sleep_disable();
		*/

		

		if(beep_flag) Beep();

	}

	return 0;
}

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

1) Use ampersand_poundsign_37_; ( So 5 symbols ttl. If I try to use those here, it just prints percent sign ! ) in place of the % in commented code and it makes the % show in code.

2) Change

"r" (_BV(_WD_CHANGE_BIT) | _BV(WDTIE))

to use WDE instead of WDTIE

3) Must use OUT, not STS in writing to WDTCR for tiny13.

4) I doubt that you need wdt_reset in your function since it resets when calling the enable code.

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

Last Edited: Tue. Apr 19, 2011 - 10:01 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
1) Use % in place of the % in commented code and it makes the % show in code.
What?
1) I used WDTIE rather than WDE as I don't want the reset to occur, just the interrupt.
3) Ok... will do that.
4) Ok... I'll comment it out.

BBL

Thanks

:)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Sorry Greg, I should have wrote in "inline code" not "commented code", and use it where YOU have #'s in the inline code. &_blah_blah that I gave you will then show up as % in inline code.

https://www.avrfreaks.net/index.p...

Scroll down to where Wek replies.

Your #1 in your last reply is wrong, see the datasheet on changing wdt.

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

Indy...

You da man!

Thanks :) :) :)

Now I can get on and build the 'AnnoyaTronWithAttitude' to seriously, and I mean SERIOUSLY annoy that £"!$%^*&^ "£$%£ in the next office that spends ALL DAY WHISTLING!?!?!?!?

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

I'm glad I could help, esp. since it allows you to, LOL,

Quote:
...annoy that £"!$%^*&^ "£$%£ in the next office that spends ALL DAY WHISTLING!?!?!?!?
This is engineering at its FINEST ( doing something for the public good :D ! ) ! I'll bet your co-workers will thank you too ! Just remember to take a video of it in operation and taking down Whistler's Brother so it can be posted on Youtube ! :wink:

Because of what's involved to change WDTCR, your write to it in the ISR won't work AND it's not needed anyway since the bit holds state.

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

Quote:
Because of what's involved to change WDTCR, your write to it in the ISR won't work AND it's not needed anyway since the bit holds state.
Still working on the final solution to my 'problem'.
This 'device' will need to run for MONTHS, hence the commented out code about sleeping!
It will have a nasty little piezo sounder, and be driven by a 3 volt cell. The Beep() function will be called at apparently random intervals, for a duration which will also be random (within predefined limits) and the tone emitted will also vary a little so it's difficult to locate :)

I'm planning to make a load of these and each time the little !@#$#@ finds and destroy's it, I'll just add a new one to his room ;)

He has no idea who he's !@#$ing with :twisted:

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!