tiny45 and extint, weird behaviour in simulator

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

I downloaded AS5 and started new Tiny45 project with default settings. Now i have test following example external interrupt service routine code in AS5 simulator.

#include 
#include 

int main(void)
{

DDRB=0x01;  // Port B init INPUTs, except pin0
PORTB=0xfe; // output low, pin0
MCUCR |= (1<<ISC01); //The falling edge of
                     //INT0 generates an interrupt.
GIMSK |= (1<<INT0);  //Ext Int Enabled

sei(); /* enable global interrupts */
	
    while(1)
    {
        //TODO:: Please write your application code 
        asm("nop");
    }
}

ISR( INT0_vect )
{
    PORTB ^= (1<<PB0); //flip output pin0
}

When interrupt is triggered, service routine is executed twice. Interrupt flag in GIFR is not cleared and interrupt starts over again.

Also interrupt is triggered in rising edge???

If I try like this

ISR( INT0_vect )
{
GIFR &= ~(1<<INTF0);// clear bit 6, Ext. Int. Flag
PORTB ^= (1<<PB0); //flip output pin0
}

So what happens? -bit 5, Pin Change interrupt Flag (PCIF) is cleared.

Still, this code seems to work fine in AS4 simulator.

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

I'm not able to reproduce this in AS5.0.1223. Which version of AS5 are you using?
How do you trigger the interrupt? By toggling the interrupt flag in the IO-view?

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

Is this not simply contact bounce?

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

Quote:

Is this not simply contact bounce?

Is the simulator bouncing?!?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Sorry, clearly more caffeine needed here! :oops:

(late flight back from Ireland last night).

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

je_ruud wrote:
I'm not able to reproduce this in AS5.0.1223. Which version of AS5 are you using?
How do you trigger the interrupt? By toggling the interrupt flag in the IO-view?

Version 5.0.1163

I triggering ext. interrupt in I/O-view by clicking PINB.2 (ext.int pin). This works in Studio 4/5.

Maybe I try newest installation some day.

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

I am sorry for the late reply.

I am able to reproduce the behavior you describe, and has filed it as bug 15370. Because of certain circumstances I can't promise you that this will be fixed before Christmas, but I'll try to remember to post here as soon as it is done.

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

The bug is located in the simulator model, meaning it will behave similarly regardless of Studio version.

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

1.

Better late than never. I have to fix that ISR code

ISR( INT0_vect )
{
GIFR &= ~(1<<INTF0);// clear bit 6, Ext. Int. Flag
PORTB ^= (1<<PB0); //flip output pin0
} 

Like that

ISR( INT0_vect )
{
GIFR |= ~(1<<INTF0);// clear/(set) bit 6, Ext. Int. Flag
PORTB ^= (1<<PB0); //flip output pin0
} 

Cause datasheet says: "the flag can be cleared by writing a logical one to it." Oops!

And so, if external interrupt is initialized to falling- or rising edge, ISR is still executed any change on the extpin logical level.

This code still works on AS4 (4.19.638) simulator, but not in AS5 (5.0.1223) simulator. I have used also the same elf-file in both.

2.

In IO-view have a dropdown-list in point of

EXTERNAL_INTERRUPT
-Interrupt sense control(MCUCR)

There is four choices:

1.Low level of INTX 0x00
2.Reserved 0x01
3.Falling edge of INTX 0x02
4.Rising edge of INTX 0x03

Should it be on the line 2. Reserved anymore? because it is nowadays on the datasheet: Any logical change on INTX 0x01.

I dont no what is the meaning of the dropdown list cause it seems not to be any effect to anywhere, and i cant even change it. Its always on Reserved-position.

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

1.

Patze wrote:

GIFR |= ~(1<<INTF0);// clear/(set) bit 6, Ext. Int. Flag


That line writes a 1 to all bits except bit 6. You have to remove the ~. Then the line will clear the interrupt flag.

In case you are not aware of it:
When you write code interrupts flags are write-to-clear, i.e you write a 1 to clear a flag, but you can never set it. But in the IO-view in Studio we have given you full control over the IO-flags. This means that when click on the interrupt flag in the IO-view you are able to set the interrupt, giving you an opportunity to simulate external interrupts.

2.
The "Reserved" on line 2 is another bug, it should of course be "Any logical change on INTX 0x01". I'll report it.
This is only graphical issues and should not affect the behavior of the simulation. But since the simulator model for tiny45 has a bug in the external interrupt the simulation will not be correct until that bug is fixed.

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

One another thing.

Pin Change Enable Mask (PCMSK) initial value is 0x00 in start up (datasheet). But when simulator starts, pin change interrupts mask [5:0] are always enabled.

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

It's amazing how you are able to dig up bugs on this device.

This one was actually a bit strange. It has previously been filed a bug that this device has a initial value of 0x00 in PCMSK while the datasheet says it should be 0x3F. I have verified with the current datasheet and physical devices, and the initial value shall be 0x00. This bug I was actually able to fix imediately.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
GIFR |= ~(1<<INTF0);// clear/(set) bit 6, Ext. Int. Flag 

Quote:
You have to remove the ~. Then the line will clear the interrupt flag.
No, you want:

GIFR = 1<<INTF0;

With the | in there it might also clear the other flags in the register if they were set.

Regards,
Steve A.

The Board helps those that help themselves.

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

Yes, of course. Koshchi is right.

Regarding the strange initializing of PCMSK I have done some digging. It turns out that you can select a tiny15-mode by setting CKSEL-fuses to '0011'. When doing this PCMSK in tiny25 (and ONLY tiny25) is initialized to 0x3f. This was erroneously applied to all three devices, tiny25, tiny45 and tiny85 regardless of CKSEL-settings. This is now fixed and will be applied in the next release.

Thank you for your help :-)