This is not so bad ??

Go To Last Post
56 posts / 0 new

Pages

Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I mean the device ATtiny40 ...

When you are newbie you start with this lite wonderful mcu. This device is using the nice TPI protocol for programming. It's a 3 wire system that is great.

The best thing with TPI is.. you can program the target for several times with avrisp mkII and AS6. Then you are comfortable with it it suddenly stops working.
Which is really nice ... then you got the time to read some treads and several pages in the datasheet.
-> https://www.avrfreaks.net/index.p...

Maybe you have been doings some php or other sorts of programing language. You have some knowledge about procedures/functions calls .. but you haven't come across interrupt.
To dealing with this strange stuff you have to set some bits in some strange named register .. TIMKS0, TCCROB etc.

The easiest way is to copy a existing code exampel.

Then it it's very funny to discover after several nights with testing/debugging that your choice of mcu is different from all other example you have come across.

Instead of setting the bit TOIE0 (=1)

TIMSK |= 1<<TOIE0;

you have to clear it (=0)

TIMSK |= ~(1<<TOIE0);

The lesson from this is .. you must read the datasheet !

My project
Some background:

Extend pcb board with toggle option.
The PEEL is replaced with ATTiny40 with wires to TPI programming. The MCU is moved to the bottom of soic24 so channel 1A is lost.

The real highlight is when you have found the code snippet you are looking for (my case debounce) you just can't get it to work.

You try to test it from all direction .. You even verify that it work with your arduino mega board

/*
* Arduino mega 2650
*/


#include 
#include 
#include 
#include 

#ifndef F_CPU
#define F_CPU           1000000                   // processor clock frequency
#endif

#define KEY_PORT        PORTB
#define KEY_PIN         PINB
#define KEY0            7

#define ALL_KEYS        ( 1<<KEY0 )



uint8_t key_state;                                // debounced and inverted key state:
                                                  // bit = 1: key pressed
uint8_t key_press;                                // key press detect



volatile uint8_t tick;

// https://github.com/szczys/Button-Debounce/blob/master/debounce-test.c




void runcheck(void)
{
  static uint8_t ct0, ct1, rpt;
  uint8_t i;

  //TCNT0 = (uint8_t)(int16_t)-(F_CPU / 1024 * 10e-3 + 0.5);  // preload for 10ms


  PORTB ^= 1<<7;


  i = key_state ^ ~KEY_PIN;                       // key changed ?
  ct0 = ~( ct0 & i );                             // reset or count ct0
  ct1 = ct0 ^ (ct1 & i);                          // reset or count ct1
  i &= ct0 & ct1;                                 // count until roll over ?
  key_state ^= i;                                 // then toggle debounced state
  key_press |= key_state & i;                     // 0->1: key press detect

}

//TIMER0_OVF0_vect
//SIG_OUTPUT_COMPARE0A_vect
ISR(SIG_OUTPUT_COMPARE0A)                            // every 10ms
{
    ++tick;
    if (tick>5) {
        runcheck();
        tick = 0;
    }

}

uint8_t get_key_press( uint8_t key_mask )
{
  cli();                                          // read and clear atomic !
  key_mask &= key_press;                          // read key(s)
  key_press ^= key_mask;                          // clear key(s)
  sei();
  return key_mask;
}




void setup()
{
    pinMode(13, OUTPUT);  //7
    pinMode(12, INPUT);   //6
    pinMode(11, OUTPUT);  //5
    digitalWrite(11, LOW);
    PORTB |= 1<<6 ;     // pullup


//    TCCR0B|= (1<<CS02)|(1<<CS00);			// divide by 1024
//    TIMSK0 = 1<<TOIE0;				// enable timer interrupt
   cli();
   TIMSK0 = _BV(OCIE0A);  // Enable Interrupt TimerCounter0 Compare Match A (SIG_OUTPUT_COMPARE0A)
    TCCR0A = _BV(WGM01);  // Mode = CTC
    TCCR0B = _BV(CS02) | _BV(CS00);   // Clock/1024, 0.001024 seconds per tick
    OCR0A = 10;          //  SIG_OUTPUT_COMPARE0A 
   sei();

}

void loop()
{

  if (get_key_press(1<<6)){
    PORTB ^= 1<<5;
  }

}

Okey you didn't manage to get the Counter overflow interrupt working but made workaround with CTC.

But the function is .. when you press the button (and keep it pressed) it just toggle the led on. You release it and press again and it will toggle it off.

But when you go back to your project


/*
* attiny40.c
*/

#define F_CPU 8000000  // default internal clock freq 8 MHz

#include 
#include 
#include 



// Input
#define In_1B PB0
#define In_2A PA7
#define In_2B PA6
#define In_3A PA5
#define In_3B PA4
#define In_NEG PA3
#define In_Unlock PA2
#define In_STAT1 PA1
#define In_STAT2 PA0


// Output
#define Out_1B PB1
#define Out_2A PB2
#define Out_2B PB3
#define Out_3A PC0
#define Out_3B PC1
#define Out_P_enb PC2
#define Out_T_rel PC4
#define Out_Error PC5

// Port mask   7 ... 0
#define PA_Mask 0b00000011 // Port A = input

#define PB_Mask 0b00001110 // Port B = output

#define PC_Mask 0b00111111 // Port C = output


//define pins used by buttons

#define KEY_PIN     ((PINB & 1<<In_1B) | (PINA & 1<<In_2A) | (PINA & 1<<In_3A) | (PINA & 1<<In_3B) | (PINA & 1<<In_Unlock))




//Debounce variables
typedef unsigned char	u8;

volatile uint8_t key_state;				// debounced and inverted key state:
// bit = 1: key pressed
volatile uint8_t key_press;				// key press detect


ISR(TIM0_OVF_vect)
//ISR( TIM0_COMPB_vect ) // Datasheet must be faulty CTC don't work
{
	static unsigned char ct0, ct1;
	unsigned char i;
	
	//TCNT0 is where TIMER0 starts counting. This calculates a value based on
	//the system clock speed that will cause the timer to reach an overflow
	//after exactly 10ms
	//TCNT0 = (unsigned char)(signed short)-(((F_CPU / 1024) * .01) + 0.5);   // preload for 10ms interrupts
	
	PORTC ^= 1<<Out_T_rel;  // visual that interrupt is working

	
	i = key_state ^ ~KEY_PIN;                       // key changed ?
	ct0 = ~( ct0 & i );                             // reset or count ct0
	ct1 = ct0 ^ (ct1 & i);                          // reset or count ct1
	i &= ct0 & ct1;                                 // count until roll over ?
	key_state ^= i;                                 // then toggle debounced state
	key_press |= key_state & i;                     // 0->1: key press detect
}

uint8_t get_key_press( uint8_t key_mask )
{
	cli();                    // read and clear atomic !  .... key_press is denounced and ready by the ISR routine

	key_mask &= key_press;    // read key(s)    .... key_press is denounced and ready by the ISR routine
	key_press ^= key_mask;    // clear key(s)

	sei();                    // enable interrupts
	return key_mask;
}


int main(void)
{
	DDRA = PA_Mask;
	DDRB = PB_Mask;
	DDRC = PC_Mask;



	cli();                        // read and clear atomic !
	//	CCP = 0xFF;    // intiante main clk prescaler
	//	CLKPSR = ~1<<CLKPS3 |  1<<CLKPS2 | ~1<<CLKPS1 | ~1<<CLKPS0;  // set prescaler to 128 .. 8 is deafult
	
	TIMSK |= ~(1<<TOIE0);           //By setting TOIE0=0 enable timer overflow interrupt
	//	TIMSK |= ~(1<<OCIE0B);
	TCCR0B |=  1<<CS02; // | 1<<CS00;   //1024 prescaler. Start the timer
	//	OCR0B = 254;
	sei();                        // enable interrupts
	

	while(1)
	{
		
		if ( get_key_press(1<<In_2A) ){
			PORTB ^= 1<<Out_2A;
			//PORTC ^= 1<<Out_Error;
			PORTC = PORTC ^1<<Out_3A;
		//	key_press ^= key_press;     // reset key_press bit(s)
		}

		if ( get_key_press(1<<In_1B)){
			if ( PINB & 1<<In_1B){
				PORTB |= (1<<Out_2B);
			}
			else
			PORTB &= ~(1<<Out_2B);
		}
	
	}
}

It will unfortunately just keep toggle the led on/off constant when you have the button pressed.It's like get_key_press is catching the state of the key.

You have checked the inputs with your logic analyzer and it looks okey.. but the program don't behave as you expect.

It's so constructive when you put aside all logic and just go for the "fatigue method ". You just try every combination of code/variabel/function/ bit flipping you can come up with for see how it behaves.

Wonderful.....

Attachment(s): 

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

Your code tells me 'if button pressed, toggle outputs' and you tell me this is what it does.

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

Well, the easiest way to deal with debounce is to look at the button every say 50mS. Even 100mS will do. That's long enough for the bounces to settle out, but not so long that the dude pushing the button is going to notice.

Another easy strategy, if you need crisper response, is to watch the button constantly, like with an interrupt or tight loop, and when you see it, do the function, but then don't look at it again for a little while.

You don't notice the light switch in your room bouncing, though it does, because the light bulb and your eyes are pretty slow. Bounces are troublesome because digital systems are so fast. Fast enough to see the switch close - open - close - open - close when we'd think it just closes.

I haven't read your programs.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

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

pernils wrote:
I mean the device ATtiny40 ...

Then it it's very funny to discover after several nights with testing/debugging that your choice of mcu is different from all other example you have come across.

Instead of setting the bit TOIE0 (=1)

TIMSK |= 1<<TOIE0;

you have to clear it (=0)

TIMSK |= ~(1<<TOIE0);

Huh? From the datasheet:
Quote:
• Bit 0 – TOIE0: Timer/Counter0 Overflow Interrupt Enable
When the TOIE0 bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter0 Overflow interrupt is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter0 occurs, i.e., when the TOV0 bit is set in the Timer/Counter Interrupt Flag Register – TIFR.
This is the same behaviour as every other AVR I've ever laid eyes upon.

Perhaps you are confusing interrupt enable bits with interrupt flags:

Quote:
• Bit 0 – TOV0: Timer/Counter0 Overflow Flag
The bit TOV0 is set when an overflow occurs in Timer/Counter0. TOV0 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV0 is cleared by writing a logic one to the flag. When the SREG I-bit, TOIE0 (Timer/Counter0 Overflow Interrupt Enable), and TOV0 are set, the Timer/Counter0 Overflow interrupt is executed.
Has anyone ever seen an AVR that enables an interrupt by clearing the associated mask bit?

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

TOV0 is the interrupt flag. Interrupt flags, generally, are cleared by writing a 1 to that bit, if it is not serviced by an ISR.

There is nothing, there, about the ENABLE bit being set by clearing anything.I just checked and the documentation says:

Quote:
When the TOIE0 bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter0 Overflow inter- rupt is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter0 occurs, i.e., when the TOV0 bit is set in the Timer/Counter Interrupt Flag Register – TIFR.

So, it is false that the interrupt is enabled by clearing any bit.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Just a small detail

    PORTB |= 1<<6 ;     // pullup

This doesn't work on the newer tinys. They have PUEx registers for this.

    PUEB |= 1<<6;

should work.

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

Hmmm, thanks for that detail. I had not noticed PUEx yet.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

So after a few hours of testing and debugging ...

Several nights ago with tired eyes I read from

Quote:

Bit 0 – TOIE0: Timer/Counter0 Overflow Interrupt Enable
When the TOIE0 bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter0 Overflow interrupt
is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter0 occurs, i.e., when the
TOV0 bit is set in the Timer/Counter Interrupt Flag Register – TIFR.

Bit 0 - TOEI0 ...

Yepp I have to clear that bit ...

So with my small testing snippet ...

#include 
#include 

// Output
#define Out_1B PB1
#define Out_2A PB2

ISR(TIM0_OVF_vect)
{
	PORTB ^= 1<<Out_1B;
	PORTB ^= 1<<Out_2A;
}

int main(void)
{
	DDRB |= 1<<Out_1B | 1<<Out_2A;  // Output Mask => 1

	cli();                    // read and clear atomic !
	TIMSK |= ~(1<<TOIE0);     //Start timer 
	TCCR0B |=  1<<CS02;       // | 1<<CS02;   //256 prescaler.
	sei();                    // enable interrupts

	while(1)
	{
	}
}

It started to blink the leds ... It also change freq. when macking around with the prescaler.

But it blinked at little bit to slowly so I think the mcu just keep rebooting..

Anyway I have now done some more testing and something strange thing occur ..

After changing a few lines I didn't get any other result (as usually) so I started to remove code and simplify the task ...

I ended up with something that I was definitely sure should work ..

#define F_CPU 800000  // default internal clock freq 8 MHz
#include 
#include 

// Output
#define Out_1B PB1
#define Out_2A PB2

int main(void)
{
	DDRB |= 1<<Out_1B | 1<<Out_2A;  // Output Mask => 1

	while(1)
	{
            PORTB ^= 1<<Out_1B;
            PORTB ^= 1<<Out_2A;
            _delay_ms(100);
	}
}

It was as usually compiling okay and .. reading the right checksum when programming.

Hmm .. I closed AS6 and restarted and made a new attempt. Now the leds start to blink.

That's a bit progress ... So now I know that my coding could be okay but the mcu will not show that.

When nothing start to work that have been working before you start to get some really paranoid thoughts.. like you can't set the PORT register in interrupt instead you must set a variable and check that in the main loop etc ...

I'm really lost know .. so I think I need some advice what could be missing.

Taking this step by step

With this

#include 

// Output
#define Out_1B PB1
#define Out_2A PB2

int main(void)
{
	DDRB |= 1<<Out_1B | 1<<Out_2A;  // output
	PORTB |= 1<<Out_1B | 1<<Out_2A; // turn the led off

	while (1) 
	{
	}
}

Will turn the led off (my outputs is reversed see schema in post above)

With this

#define F_CPU 800000  // default internal clock freq 8 MHz
#include 
#include 

// Output
#define Out_1B PB1
#define Out_2A PB2

int main(void)
{
	DDRB |= 1<<Out_1B | 1<<Out_2A;  // Output Mask => 1
	PORTB |= 1<<Out_1B | 1<<Out_2A; // turn the led off
	while(1)
	{
    	    PORTB ^= 1<<Out_1B;
	    PORTB ^= 1<<Out_2A;
	    _delay_ms(100);
	}
}

Will blink the leds.

With this ...

#include 
#include 

// Output
#define Out_1B PB1
#define Out_2A PB2

ISR(TIM0_OVF_vect)
{
  PORTB ^= (1<<Out_1B);
  PORTB ^= (1<<Out_2A);
}

int main(void)
{
	DDRB |= 1<<Out_1B | 1<<Out_2A;  // Output Mask => 1
	PORTB |= 1<<Out_1B | 1<<Out_2A; // turn the led off
	
	TCCR0B = 1<<CS02 | 1<<CS00;    // 1024 prescaler
	
	TIMSK = 1<<TOIE0;     //Start timer 
	sei();
	
	while(1)
	{
	}
}

It will not blink the leds .. not even light the led => the ISR is never running.

With this ...

#include 
#include 

// Output
#define Out_1B PB1
#define Out_2A PB2

ISR(TIM0_COMPA_vect)
{
  PORTB ^= (1<<Out_1B);
  PORTB ^= (1<<Out_2A);
}

int main(void)
{
	DDRB |= 1<<Out_1B | 1<<Out_2A;  // Output Mask => 1
	PORTB |= 1<<Out_1B | 1<<Out_2A; // turn the led off

	TCCR0A = 1<<WGM01;             // CTC	
	TCCR0B = 1<<CS02 | 1<<CS00;    // 1024 prescaler

	OCR0A = 254;	
	
	TIMSK = 1<<OCIE0A;
	sei();
	
	while(1)
	{
	}
}

It will not blink the leds .. not even light the led => the ISR is never running.

With this ...

#define F_CPU 800000  // default internal clock freq 8 MHz
#include 
#include 
#include 

// Output
#define Out_1B PB1
#define Out_2A PB2

ISR(TIM0_COMPA_vect)
{
  PORTB ^= (1<<Out_1B);
  PORTB ^= (1<<Out_2A);
}

int main(void)
{
	DDRB |= 1<<Out_1B | 1<<Out_2A;  // Output Mask => 1
	PORTB |= 1<<Out_1B | 1<<Out_2A; // turn the led off

	TCCR0A = 1<<WGM01;             // CTC	
	TCCR0B = 1<<CS02 | 1<<CS00;    // 1024 prescaler

	OCR0A = 254;	
	
	TIMSK = 1<<OCIE0A;
	sei();
	
	while(1)
	{
           PORTB ^= 1<<Out_1B;
           PORTB ^= 1<<Out_2A;  // see if program is not halted
           _delay_ms(100);
	}
}

It will turn on the leds but not blink them. Strange ...

So I just can't get a grip of this.

ATtiny40 datasheet => http://www.atmel.com/Images/Atme...

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

Quote:

ISR(TIM0_COMPA_vect)

Do you get a warning about mis-spelled vector name(s) when you compile your "don't work" examples?

When you dig down and examine the chip-include file, how are the vector names spelled?
[The online copy at http://www.nongnu.org/avr-libc/u... doesn't seem to have that AVR family in the table.] Your spelling indeed seems to follow the datasheet naming.

What toolchain/version are you using? Until recently, use of brain-dead Tiny models was spotty at best.

As you have reduced things to a small complete test program (Ideal!), perhaps post the generated code.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Quote:

Quote:

ISR(TIM0_COMPA_vect)

Do you get a warning about mis-spelled vector name(s) when you compile your "don't work" examples?

Nope .. when typing in AS6.1 TIM... I get the suggestion :

TIM0_OVF_vect
TIM0_OVF_vect_num

Quote:

What toolchain/version are you using? Until recently, use of brain-dead Tiny models was spotty at best.

What comes with AS6.1 ... hmm ...

Under debug -> Options setting -> Toolchain -> Package Configuration is read Atmel AVR 32-bit ( C language) ..
Changing to -> Atmel AVR 32-bit ( C language)

Before changing I get this message

Quote:

Build succeeded.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

After changing ->

Quote:

Error 1 expected '=', ',', ';', 'asm' or '__attribute__' before 'void' C:\Documents and Settings\pernils\Mina dokument\Atmel Studio\6.1\smp_attiny40\smp_attiny40\smp_attiny40.c 64 1 smp_attiny40

Do I have to start e new project ?

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

Quote:
Atmel AVR 32-bit

Did it become an ARM?

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

No .. But it will become a piece of broken silicon under a 3 kg sled hammer...

The path of the tool chain is C:\Program\Atmel\Atmel Toolchain\AVR32 GCC\Native\3.4.2.365\avr32-gnu-toolchain\bin

Bah .. When you start Atmel AVR Studio (I assumed that is the same firm that is making this silly silicon) you choose your target from their range of mcu in a list.

If I change to codeblocks I have to dig into arvdude for programming ?

What a heck .. I have already wasted 4-5 weeks on nothing ..so one more month will not add so much to the development time ...

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

theusch wrote:
When you dig down and examine the chip-include file, how are the vector names spelled?
[The online copy at http://www.nongnu.org/avr-libc/u... doesn't seem to have that AVR family in the table.] Your spelling indeed seems to follow the datasheet naming.
Checked the latest avr-gcc 4.8.0 based toolchain, and the 3.4.1_798 toolchain and in both cases found iotn40.h contained:
#define TIM0_OVF_vect_num  11
#define TIM0_OVF_vect      _VECTOR(11)  /* Timer/Counter0 Overflow */

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

I'm not a Studio6.1 person right now, but the path you quoted sounds very strange for an AVR8.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Your first example should not work, and is probably resetting as you suspect.

TIMSK |= ~(1<<TOIE0);     //Start timer 

This enables all timer interrupts except TOIE0, and that will cause reset since you don't have handlers for them.

In some other examples you say

#define F_CPU 800000  // default internal clock freq 8 MHz 

Default is 8MHz internal RC divided by 8 for 1MHz clock. But you say 800kHz. Did you disable CKDIV8? (you don't have to, you can change the clock prescaler from software).

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

.. okay .. under the last tab (post above ) you set different toolchains globaly ..

It's under project tab you set your preferred toolchain.

In my case it will include this paths ...

Quote:

C:\Program\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.876\avr8-gnu-toolchain\avr\include
C:\Program\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.876\avr8-gnu-toolchain\lib\gcc\avr\4.7.2\include
C:\Program\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.876\avr8-gnu-toolchain\lib\gcc\avr\4.7.2\include-fixed

Seems right to me 8-bit avr.

Then you have this awfull string of parameter to the avr-gcc

Quote:

-funsigned-char -funsigned-bitfields -DDEBUG -O1 -ffunction-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=attiny40 -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"

The person who remember all that must be the same person who wrote the compiler ..

What have we then .. some Optimization level

Quote:

Optimize (-01)

Aaah then we have the Linker param ...

Quote:

-Wl,-Map="$(OutputFileName).map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=attiny40

The same goes here ...

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

snigelen wrote:
Your first example should not work, and is probably resetting as you suspect.
TIMSK |= ~(1<<TOIE0);     //Start timer 

This enables all timer interrupts except TOIE0, and that will cause reset since you don't have handlers for them.

In some other examples you say

#define F_CPU 800000  // default internal clock freq 8 MHz 

Default is 8MHz internal RC divided by 8 for 1MHz clock. But you say 800kHz. Did you disable CKDIV8? (you don't have to, you can change the clock prescaler from software).

Typo from me .. ( The truth is.. 8 Mhz was the only Hz I found in the datasheet).

F_CPU is only used in _delay_ms() (from what I understand).

The interrupt should work anyway. (Statement from someone who haven't manage to get it working yet).

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

As I mentioned, it might be interesting to see the generated code? [GCC gurus will need to help with giving the magic incantations to see the generated source and listing]

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

You mean the dsassembly file .. ?

Quote:

Disassembly of section .text:

00000000 <__vectors>:
0: 10 c0 rjmp .+32 ; 0x22 <__ctors_end>
2: 17 c0 rjmp .+46 ; 0x32 <__bad_interrupt>
4: 16 c0 rjmp .+44 ; 0x32 <__bad_interrupt>
6: 15 c0 rjmp .+42 ; 0x32 <__bad_interrupt>
8: 14 c0 rjmp .+40 ; 0x32 <__bad_interrupt>
a: 13 c0 rjmp .+38 ; 0x32 <__bad_interrupt>
c: 12 c0 rjmp .+36 ; 0x32 <__bad_interrupt>
e: 11 c0 rjmp .+34 ; 0x32 <__bad_interrupt>
10: 10 c0 rjmp .+32 ; 0x32 <__bad_interrupt>
12: 0f c0 rjmp .+30 ; 0x32 <__bad_interrupt>
14: 0e c0 rjmp .+28 ; 0x32 <__bad_interrupt>
16: 0e c0 rjmp .+28 ; 0x34 <__vector_11>
18: 0c c0 rjmp .+24 ; 0x32 <__bad_interrupt>
1a: 0b c0 rjmp .+22 ; 0x32 <__bad_interrupt>
1c: 0a c0 rjmp .+20 ; 0x32 <__bad_interrupt>
1e: 09 c0 rjmp .+18 ; 0x32 <__bad_interrupt>
20: 08 c0 rjmp .+16 ; 0x32 <__bad_interrupt>

00000022 <__ctors_end>:
22: 11 27 eor r17, r17
24: 1f bf out 0x3f, r17 ; 63
26: cf e3 ldi r28, 0x3F ; 63
28: d1 e0 ldi r29, 0x01 ; 1
2a: de bf out 0x3e, r29 ; 62
2c: cd bf out 0x3d, r28 ; 61
2e: 18 d0 rcall .+48 ; 0x60


30: 24 c0 rjmp .+72 ; 0x7a <_exit>

00000032 <__bad_interrupt>:
32: e6 cf rjmp .-52 ; 0x0 <__vectors>

00000034 <__vector_11>:

//ISR(TIM0_COMPA_vect)
ISR(TIM0_OVF_vect)
{
34: 1f 93 push r17
36: 0f 93 push r16
38: 0f b7 in r16, 0x3f ; 63
3a: 0f 93 push r16
3c: 10 e0 ldi r17, 0x00 ; 0
3e: 4f 93 push r20
40: 5f 93 push r21
PORTB ^= (1<<Out_1B);
42: 56 b1 in r21, 0x06 ; 6
44: 42 e0 ldi r20, 0x02 ; 2
46: 45 27 eor r20, r21
48: 46 b9 out 0x06, r20 ; 6
PORTB ^= (1<<Out_2A);
4a: 56 b1 in r21, 0x06 ; 6
4c: 44 e0 ldi r20, 0x04 ; 4
4e: 45 27 eor r20, r21
50: 46 b9 out 0x06, r20 ; 6
}
52: 5f 91 pop r21
54: 4f 91 pop r20
56: 0f 91 pop r16
58: 0f bf out 0x3f, r16 ; 63
5a: 0f 91 pop r16
5c: 1f 91 pop r17
5e: 18 95 reti

00000060

:
int main(void)
{

DDRB |= 1<<Out_1B | 1<<Out_2A; // output
60: 45 b1 in r20, 0x05 ; 5
62: 46 60 ori r20, 0x06 ; 6
64: 45 b9 out 0x05, r20 ; 5
PORTB |= 1<<Out_1B | 1<<Out_2A; // turn the led off
66: 46 b1 in r20, 0x06 ; 6
68: 46 60 ori r20, 0x06 ; 6
6a: 46 b9 out 0x06, r20 ; 6

cli();
6c: f8 94 cli
// TCCR0A = 1<<WGM01;
// TCCR0A |= 1<<WGM00 | 1<<WGM01;
TCCR0B = 1<<CS02 | 1<<CS00; // 1024 prescaler
6e: 45 e0 ldi r20, 0x05 ; 5
70: 48 bb out 0x18, r20 ; 24

// OCR0A = 244;

TIMSK = 1<<TOIE0; //Start timer and enable overflow intr.
72: 41 e0 ldi r20, 0x01 ; 1
74: 46 bd out 0x26, r20 ; 38
// TIMSK = 1<<OCIE0A;
sei();
76: 78 94 sei
78: ff cf rjmp .-2 ; 0x78

0000007a <_exit>:
7a: f8 94 cli

0000007c <__stop_program>:
7c: ff cf rjmp .-2 ; 0x7c <__stop_program>

Should be erased to save space on the forum.
Hups .. wrong compile ..fixed now

This is the simplest form of interrupt ..timer overflow posted above.

So the best bet is to do this in asm. (... searching for capitulation flag ).

Any rumor
that avr 2313 is double under c?
I could use that device by scraping one of the stat lines.

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

Quote:

(... searching for capitulation flag ).


I suppose it might be "interesting" to load the compiler's generated source into ASM and see what happens.

I don't have any of the little brain-dead beasties. A quick read-through and cross-check with the datasheet and nothing jumps out at me.

Now, they tell me that the simulator in 6.x is pretty good--perhaps run it through there for clues?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Quote:

I suppose it might be "interesting" to load the compiler's generated source into ASM and see what happens.

Have to google that ..

Quote:

I don't have any of the little brain-dead beasties. A quick read-through and cross-check with the datasheet and nothing jumps out at me.

Yepp my brain have slowly been dying while trying to debug this ...

Quote:

Now, they tell me that the simulator in 6.x is pretty good--perhaps run it through there for clues?

It seems to stuck when it comes to the while(1) {}

Time is 23:20 here now so it's time to get some sleep ...

thanks for taking the time on this case ...

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

Quote:

It seems to stuck when it comes to the while(1)

See if the timer is counting up.

(If stepping in the simulator, change to a low prescaler or you will be there for [what seems like] forever. ;) )

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Setting

TCCR0B = 1<<CS00; (none)

or

TCCR0B = 1<<CS02;

Will give the same result ... TCNT0 will not count and the simulator freeze ...

The same stuff even happens if add something in the endless loop ...

while(1)
{
    PORTB ^= 1<<Out_1B;
}

If I have time I will try another IDE tomorrow -> Codeblocks ...

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

Quote:

TCNT0 will not count

Hmmm--I'd think the simulator would handle a basic mode OK...

Does TCCR0B show the prescale bit(s) set?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I disagree about using the ATtiny40 for development work. Especially for people who are new to AVR.

I suggest the Mega328 in PDIP format because it is cheap, versatile, and pin-accessable for DVM and oscilloscope probes. (no DVM and oscilloscope? I think that you are forgetting that this is not a computer that you are programming, it's an IC.)

The ATtiny40 is only available in SOIC format for experimenters, and smaller for commercial applications. Sure you can buy a tiny40 that isn't mounted on anything, but you aren't going to be doing very much with it.

Plus the Tiny40 doesn't have a USART. The tiny1634 has everything that the tiny40 has, along with four times as much memory and two USART ports. For about the same price. It's only available in SOIC format (and smaller sizes that don't count if you are in the development stage. Development stage means that you can burn up or otherwise destroy the IC and then just replace it by popping it out of its socket and putting in a new one. Doesn't work with SOIC and flatpack).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
00000000 <__vectors>:
0: 10 c0 rjmp .+32 ; 0x22 <__ctors_end>
2: 17 c0 rjmp .+46 ; 0x32 <__bad_interrupt>
4: 16 c0 rjmp .+44 ; 0x32 <__bad_interrupt>
6: 15 c0 rjmp .+42 ; 0x32 <__bad_interrupt>
8: 14 c0 rjmp .+40 ; 0x32 <__bad_interrupt>
a: 13 c0 rjmp .+38 ; 0x32 <__bad_interrupt>
c: 12 c0 rjmp .+36 ; 0x32 <__bad_interrupt>
e: 11 c0 rjmp .+34 ; 0x32 <__bad_interrupt>
10: 10 c0 rjmp .+32 ; 0x32 <__bad_interrupt>
12: 0f c0 rjmp .+30 ; 0x32 <__bad_interrupt>
14: 0e c0 rjmp .+28 ; 0x32 <__bad_interrupt>
16: 0e c0 rjmp .+28 ; 0x34 <__vector_11>
18: 0c c0 rjmp .+24 ; 0x32 <__bad_interrupt>
1a: 0b c0 rjmp .+22 ; 0x32 <__bad_interrupt>
1c: 0a c0 rjmp .+20 ; 0x32 <__bad_interrupt>
1e: 09 c0 rjmp .+18 ; 0x32 <__bad_interrupt>
20: 08 c0 rjmp .+16 ; 0x32 <__bad_interrupt>

Are you sure you're compiling for the correct mcu? The ATtiny40 has 18 entries in the interrupt vector table. There are only 17 here (although, the 18th is QTRIP for touch sensing, perhaps there is no support for this in the toolchain?

However, __vector_11 corresponds to TIM0_COMPB_vect, not TIM0_OVF_vect

00000022 <__ctors_end>:
22: 11 27 eor r17, r17
24: 1f bf out 0x3f, r17 ; 63
26: cf e3 ldi r28, 0x3F ; 63
28: d1 e0 ldi r29, 0x01 ; 1
2a: de bf out 0x3e, r29 ; 62
2c: cd bf out 0x3d, r28 ; 61
2e: 18 d0 rcall .+48 ; 0x60 
30: 24 c0 rjmp .+72 ; 0x7a <_exit>

This seems like fairly short init code. Missing are the __do_copy_data and __do_clear_bss bits. Is this normal for AS6.1?

TCCR0B = 1<<CS02 | 1<<CS00; // 1024 prescaler
6e: 45 e0 ldi r20, 0x05 ; 5
70: 48 bb out 0x18, r20 ; 24

TIMSK = 1<<TOIE0; //Start timer and enable overflow intr.
72: 41 e0 ldi r20, 0x01 ; 1
74: 46 bd out 0x26, r20 ; 38

Whatever mcu you are building for, these ports are the same as for the '40, so you are in fact actually enabling TOIE0 as expected. However, with the interrupt vector pointing to __bad_interrupt, you would simply do a soft reset each time. Keep in mind, this is not an actual reset, so I/O register contents will be unaffected.

I compiled:

#include 
#include 

EMPTY_INTERRUPT(TIM0_OVF_vect);

int main(void) {
  while(1);
}

... with:

avr-gcc -g -Os -mmcu=attiny40 foo.c -o foo.c.elf

... and got the same interrupt vector table.

Am I missing something, or is this broken?

Not missing in my test are __do_copy_data and __do_clear_bss. Perhaps they get optimized away by AS6.1 default build options?

EDIT: The disassembled code you posted, main exits to _exit, which disables interrupts with CLI and enters an eternal loop. This will happen before even the first timer interrupt.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Tue. Apr 23, 2013 - 12:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Another look at iotn40.h:

/* Interrupt vectors */
/* Vector 0 is the reset vector */
#define INT0_vect_num  1
#define INT0_vect      _VECTOR(1)  /* External Interrupt Request 0 */
#define PCINT0_vect_num  2
#define PCINT0_vect      _VECTOR(2)  /* Pin Change Interrupt Request 0 */
#define PCINT1_vect_num  3
#define PCINT1_vect      _VECTOR(3)  /* Pin Change Interrupt Request 1 */
#define WDT_vect_num  4
#define WDT_vect      _VECTOR(4)  /* Watchdog Time-out */
#define TIM1_CAPT_vect_num  5
#define TIM1_CAPT_vect      _VECTOR(5)  /* Timer/Counter1 Input Capture */
#define TIM1_COMPA_vect_num  6
#define TIM1_COMPA_vect      _VECTOR(6)  /*  Timer/Counter1 Compare Match A */
#define TIM1_COMPB_vect_num  7
#define TIM1_COMPB_vect      _VECTOR(7)  /*  Timer/Counter1 Compare Match B */
#define TIM1_OVF_vect_num  8
#define TIM1_OVF_vect      _VECTOR(8)  /* Timer/Counter1 Overflow */
#define TIM0_COMPA_vect_num  9
#define TIM0_COMPA_vect      _VECTOR(9)  /* Timer/Counter0 Compare Match A */
#define TIM0_COMPB_vect_num  10
#define TIM0_COMPB_vect      _VECTOR(10)  /* Timer/Counter0 Compare Match B */
#define TIM0_OVF_vect_num  11
#define TIM0_OVF_vect      _VECTOR(11)  /* Timer/Counter0 Overflow */
#define ANA_COMP_vect_num  12
#define ANA_COMP_vect      _VECTOR(12)  /* Analog Comparator */
#define ADC_ADC_vect_num  13
#define ADC_ADC_vect      _VECTOR(13)  /* Conversion Complete */
#define TWI_SLAVE_vect_num  14
#define TWI_SLAVE_vect      _VECTOR(14)  /* Two-Wire Interface */
#define SPI_vect_num  15
#define SPI_vect      _VECTOR(15)  /* Serial Peripheral Interface */
#define QTRIP_vect_num  16
#define QTRIP_vect      _VECTOR(16)  /* Touch Sensing */

#define _VECTOR_SIZE 2 /* Size of individual vector. */
#define _VECTORS_SIZE (17 * _VECTOR_SIZE)

Looks like PCINT2_vect is missing.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Simonetta wrote:
I disagree about using the ATtiny40 for development work. Especially for people who are new to AVR.

I suggest the Mega328 in PDIP format because it is cheap, versatile, and pin-accessable for DVM and oscilloscope probes. (no DVM and oscilloscope? I think that you are forgetting that this is not a computer that you are programming, it's an IC.)

The ATtiny40 is only available in SOIC format for experimenters, and smaller for commercial applications. Sure you can buy a tiny40 that isn't mounted on anything, but you aren't going to be doing very much with it.

Plus the Tiny40 doesn't have a USART. The tiny1634 has everything that the tiny40 has, along with four times as much memory and two USART ports. For about the same price. It's only available in SOIC format (and smaller sizes that don't count if you are in the development stage. Development stage means that you can burn up or otherwise destroy the IC and then just replace it by popping it out of its socket and putting in a new one. Doesn't work with SOIC and flatpack).

I fully agree with your opinions ...

But in my case it was the first device that would be possible to replace the pld on a existing pcb.

My testing is matter fact done on this board at the moment. Was pain in the a.. to solder the tpi 3 wires next to each other with 1.27 pin pitch. Schematics of the board is found in post above.

No USART .. that was a bummer .. had some ideas of serial communications in the future.

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

Quote:
Are you sure you're compiling for the correct mcu? The ATtiny40 has 18 entries in the interrupt vector table. There are only 17 here (although, the 18th is QTRIP for touch sensing, perhaps there is no support for this in the toolchain?

However, __vector_11 corresponds to TIM0_COMPB_vect, not TIM0_OVF_vect

I can't test things at the moment (I'm at work)

But enable TOIE0
and use ISR(TIM0_COMPB_vect) could be a workaround ?

Quote:

EDIT: The disassembled code you posted, main exits to _exit, which disables interrupts with CLI and enters an eternal loop. This will happen before even the first timer interrupt.

I didn't call the cli() (from what I rember)

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

theusch wrote:
Quote:

TCNT0 will not count

Hmmm--I'd think the simulator would handle a basic mode OK...

Does TCCR0B show the prescale bit(s) set?

I say yes at the moment ... but I have to double check it ..

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

The vector's are numbered from reset = 1 in the datashet and from 1 = int0 in avr-libc. But it doesn't look correct (as in the datasheet) in iotn40.h

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

PCINT2_vect is missing in the header file (and in devices/ATtiny40.xml where the information comes from), so everything after that is off by one address.

Does it work if you, for example, enable overflow interrupt on timer0 and use TIM0_COMPB_vect as handler?

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

I have the hardware at home ...

When testing in AS6.1 it freeze anyway (not counting up TCTN0) But I could be working on the "real metal".

When changing to ISR(TIMO_COMPB_vect) i get

  14:	0f c0       	rjmp	.+30     	; 0x34 <__vector_10>
  16:	0d c0       	rjmp	.+26     	; 0x32 <__bad_interrupt>
  18:	0c c0       	rjmp	.+24     	; 0x32 <__bad_interrupt>
  1a:	0b c0       	rjmp	.+22     	; 0x32 <__bad_interrupt>
  1c:	0a c0       	rjmp	.+20     	; 0x32 <__bad_interrupt>
  1e:	09 c0       	rjmp	.+18     	; 0x32 <__bad_interrupt>
  20:	08 c0       	rjmp	.+16     	; 0x32 <__bad_interrupt>

00000022 <__ctors_end>:
  22:	11 27       	eor	r17, r17
  24:	1f bf       	out	0x3f, r17	; 63
  26:	cf e3       	ldi	r28, 0x3F	; 63
  28:	d1 e0       	ldi	r29, 0x01	; 1
  2a:	de bf       	out	0x3e, r29	; 62
  2c:	cd bf       	out	0x3d, r28	; 61
  2e:	18 d0       	rcall	.+48     	; 0x60 
30: 22 c0 rjmp .+68 ; 0x76 <_exit> 00000032 <__bad_interrupt>: 32: e6 cf rjmp .-52 ; 0x0 <__vectors> 00000034 <__vector_10>:

Instead of when ISR(TIM0_OVF_vect)

  16:	0e c0       	rjmp	.+28     	; 0x34 <__vector_11>
  18:	0c c0       	rjmp	.+24     	; 0x32 <__bad_interrupt>
  1a:	0b c0       	rjmp	.+22     	; 0x32 <__bad_interrupt>
  1c:	0a c0       	rjmp	.+20     	; 0x32 <__bad_interrupt>
  1e:	09 c0       	rjmp	.+18     	; 0x32 <__bad_interrupt>
  20:	08 c0       	rjmp	.+16     	; 0x32 <__bad_interrupt>

00000022 <__ctors_end>:
  22:	11 27       	eor	r17, r17
  24:	1f bf       	out	0x3f, r17	; 63
  26:	cf e3       	ldi	r28, 0x3F	; 63
  28:	d1 e0       	ldi	r29, 0x01	; 1
  2a:	de bf       	out	0x3e, r29	; 62
  2c:	cd bf       	out	0x3d, r28	; 61
  2e:	18 d0       	rcall	.+48     	; 0x60 
30: 22 c0 rjmp .+68 ; 0x76 <_exit> 00000032 <__bad_interrupt>: 32: e6 cf rjmp .-52 ; 0x0 <__vectors> 00000034 <__vector_11>:
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I include the PCINT2_vect in iotn40.h and inc the numbers

Quote:

#define PCINT2_vect_num 4
#define PCINT2_vect _VECTOR(4)

I get with ISR(TIM0_OVF_vect)

  16:	0d c0       	rjmp	.+26     	; 0x32 <__bad_interrupt>
  18:	0d c0       	rjmp	.+26     	; 0x34 <__vector_12>
  1a:	0b c0       	rjmp	.+22     	; 0x32 <__bad_interrupt>
...

00000032 <__bad_interrupt>:
  32:	e6 cf       	rjmp	.-52     	; 0x0 <__vectors>

00000034 <__vector_12>:

Should I fiddle with the numbers so I get something

00000034 <__vector_12>:
  32:	e6 cf       	rjmp	.-52     	; 0x0 <__vectors>

* Edit
Why don't they inc the width of the page? It's annoying when the code always is wrapping to the next line ...

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

I got the direction wrong before, it's ANA_COMP_vect that's on TIM0_OVF_vect's place.

N - (Correct) number with avr-libc numbering
WA - Word address
BA - Byte address

 N WA BA Name            Is         Should be
 0 00 00 RESET
 1 01 02 INT0_vect       _VECTOR(1) _VECTOR(1)
 2 02 04 PCINT0_vect     _VECTOR(2) _VECTOR(2)
 3 03 06 PCINT1_vect     _VECTOR(3) _VECTOR(3)
 4 04 08 PCINT2_vect     MISSING!   _VECTOR(4)
 5 05 0a WDT_vect        _VECTOR(4) _VECTOR(5)
 6 06 0c TIM1_CAPT_vect  _VECTOR(5) _VECTOR(6)
 7 07 0e TIM1_COMPA_vect _VECTOR(6) _VECTOR(7)
 8 08 10 TIM1_COMPB_vect _VECTOR(7) _VECTOR(8)
 9 09 12 TIM1_OVF_vect   _VECTOR(8) _VECTOR(9)
10 0a 14 TIM0_COMPA_vect _VECTOR(9) _VECTOR(10)
11 0b 16 TIM0_COMPB_vect _VECTOR(10) _VECTOR(11)
12 0c 18 TIM0_OVF_vect   _VECTOR(11) _VECTOR(12)
13 0d 1a ANA_COMP_vect   _VECTOR(12) _VECTOR(13)
14 0e 1c ADC_ADC_vect    _VECTOR(13) _VECTOR(14)
15 0f 1e TWI_SLAVE_vect  _VECTOR(14) _VECTOR(15)
16 10 20 SPI_vect        _VECTOR(15) _VECTOR(16)
17 11 22 QTRIP_vect      _VECTOR(16) _VECTOR(17)

Quote:
Why don't they inc the width of the page? It's annoying when the code always is wrapping to the next line ...
You can make it a little wider with something like this

==================================================================

But it's annoying if you make it too wide.

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

==================================================================================
The only place from what I can see to edit is

/* Interrupt vectors */
/* Vector 0 is the reset vector */
#define INT0_vect_num  1
#define INT0_vect      _VECTOR(1)  /* External Interrupt Request 0 */
#define PCINT0_vect_num  2
#define PCINT0_vect      _VECTOR(2)  /* Pin Change Interrupt Request 0 */
#define PCINT1_vect_num  3
#define PCINT1_vect      _VECTOR(3)  /* Pin Change Interrupt Request 1 */
#define PCINT2_vect_num  4
#define PCINT2_vect      _VECTOR(4)  /* Pin Change Interrupt Request 2 */
#define WDT_vect_num  5
#define WDT_vect      _VECTOR(5)     /* Watchdog Time-out */
#define TIM1_CAPT_vect_num  6
#define TIM1_CAPT_vect      _VECTOR(6)  /* Timer/Counter1 Input Capture */
#define TIM1_COMPA_vect_num  7
#define TIM1_COMPA_vect      _VECTOR(7)  /*  Timer/Counter1 Compare Match A */
#define TIM1_COMPB_vect_num  8
#define TIM1_COMPB_vect      _VECTOR(8)  // Timer/Counter1 Compare Match B 
#define TIM1_OVF_vect_num  9
#define TIM1_OVF_vect      _VECTOR(9)  /* Timer/Counter1 Overflow */
#define TIM0_COMPA_vect_num  10
#define TIM0_COMPA_vect      _VECTOR(10)  /* Timer/Counter0 Compare Match A */
#define TIM0_COMPB_vect_num  11
#define TIM0_COMPB_vect      _VECTOR(11)  /* Timer/Counter0 Compare Match B */
#define TIM0_OVF_vect_num  12
#define TIM0_OVF_vect      _VECTOR(12)  /* Timer/Counter0 Overflow */
#define ANA_COMP_vect_num  13
#define ANA_COMP_vect      _VECTOR(13)  /* Analog Comparator */
#define ADC_ADC_vect_num  14
#define ADC_ADC_vect      _VECTOR(14)  /* Conversion Complete */
#define TWI_SLAVE_vect_num  15
#define TWI_SLAVE_vect      _VECTOR(15)  /* Two-Wire Interface */
#define SPI_vect_num  16
#define SPI_vect      _VECTOR(16)  /* Serial Peripheral Interface */
#define QTRIP_vect_num  17
#define QTRIP_vect      _VECTOR(17)  /* Touch Sensing */
#define _VECTOR_SIZE 2 /* Size of individual vector. */
#define _VECTORS_SIZE (18 * _VECTOR_SIZE)

Will get

....
  16:	0d c0       	rjmp	.+26     	; 0x32 <__bad_interrupt>
  18:	0d c0       	rjmp	.+26     	; 0x34 <__vector_12>
  1a:	0b c0       	rjmp	.+22     	; 0x32 <__bad_interrupt>
...

00000022 <__ctors_end>:
  22:	11 27       	eor	r17, r17
  24:	1f bf       	out	0x3f, r17	; 63
  26:	cf e3       	ldi	r28, 0x3F	; 63
  28:	d1 e0       	ldi	r29, 0x01	; 1
  2a:	de bf       	out	0x3e, r29	; 62
  2c:	cd bf       	out	0x3d, r28	; 61
  2e:	18 d0       	rcall	.+48     	; 0x60 
30: 22 c0 rjmp .+68 ; 0x76 <_exit> 00000032 <__bad_interrupt>: 32: e6 cf rjmp .-52 ; 0x0 <__vectors> 00000034 <__vector_12>: ISR(TIM0_OVF_vect) //ISR(TIM0_COMPB_vect) { 34: 1f 93 push r17 36: 0f 93 push r16 38: 0f b7 in r16, 0x3f ; 63 3a: 0f 93 push r16 3c: 10 e0 ldi r17, 0x00 ; 0 3e: 4f 93 push r20 40: 5f 93 push r21 PORTB ^= (1<<Out_1B); 42: 56 b1 in r21, 0x06 ; 6 44: 42 e0 ldi r20, 0x02 ; 2 46: 45 27 eor r20, r21 48: 46 b9 out 0x06, r20 ; 6

So it should be read ...

  16:	0d c0       	rjmp	.+26     	; 0x32 <__bad_interrupt>

jump to line 32

00000032 <__bad_interrupt>:
  32:	e6 cf       	rjmp	.-52     	; 0x0 <__vectors>

Jump back from where you came from ...

 18:	0d c0       	rjmp	.+26     	; 0x34 <__vector_12>

Jump to line 34

00000034 <__vector_12>:

ISR(TIM0_OVF_vect)
//ISR(TIM0_COMPB_vect)
{
  34:	1f 93       	push	r17
  36:	0f 93       	push	r16
  38:	0f b7       	in	r16, 0x3f	; 63
.....
  5c:	1f 91       	pop	r17
  5e:	18 95       	reti

He ... run the ISR routine and then jump back from where you came from ... etc ... eventually you are back in the main.

It doesn't work in AS6.1 simulator but what can you expect .. nothing else have seems to work.

But if above is correct it should be a valid program.

* Edit
Removed nonce ...

* Edit
removed even more nonce ....

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

pernils wrote:
I didn't call the cli() (from what I rember)
No, the CLI is part of exit, which gets called if/when main returns. Since you had no eternal loop in main, that's exactly what happens. Mind you, I was only referring to the test code for which you posted the disassembled output.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

joeymorin wrote:
Looks like PCINT2_vect is missing.
Confirmed. Pathch submitted 4 months ago here.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

joeymorin wrote:
Looks like PCINT2_vect is missing.

Oh I didn't see that. It was too early in the morning.
Quote:
Pathch submitted 4 months ago
I guess it's the wrong place. It should be corrected by Atmel in their devices/ATtiny40.xml file since that file is used to generate the header file (I think).

PCINT2_vect is missing in (my copy of) Studio 6.1 beta, both in the header and the xml file.

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

snigelen wrote:
I guess it's the wrong place. It should be corrected by Atmel in their devices/ATtiny40.xml file since that file is used to generate the header file (I think).
Anybody from Atmel following? what's the best way to inform the powers that be?
pernils wrote:
Why don't they inc the width of the page? It's annoying when the code always is wrapping to the next line ...
Do you mean the the appearance of your posts in the forum? There is a 'maximize' link a the top of each page.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

joeymorin wrote:

Do you mean the the appearance of your posts in the forum? There is a 'maximize' link a the top of each page.

JJ

I see it now ...

As stated in posts above I seems to have problem to read .. :D

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

Quote:

Anybody from Atmel following? what's the best way to inform the powers that be?

I'll move this thread to the AS6 forum. Someone ought to raise a Bugzilla entry but I'm sure someone from Atmel will read it in the AS6 forum and do that anyway if no one else has.

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

For what is worth ...

Renumber the vectors in iotn40 did the trick ...

Suddenly it struck me .. the share amount of man hours it takes to develop a application..

I have lost count .. but it must be over 4 weeks of reading and hacking ...
By the way where is my app. now again ?

Aaah here it is ...

#include 

int main(void)
{
  while (1) 
     {
  
     }
}

Tada ...

Yepp, Time to get the glasses on and dig into to the keyboard and compile and debug this beast.

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

pernils wrote:
I have lost count .. but it must be over 4 weeks of reading and hacking ...
By the way where is my app. now again ?
Time well spent. Next time will take only 2 weeks ;)

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

joeymorin wrote:
pernils wrote:
I have lost count .. but it must be over 4 weeks of reading and hacking ...
By the way where is my app. now again ?
Time well spent. Next time will take only 2 weeks ;)

JJ

You have been right in all other things so ..

Have read some sticky treads about "hostile" treatment to young players (it's me) But I must say I haven't seen such behavior.

Like this .. You and other have taking the time to deal with device that you never have seen an pro belly will not .. to easy the living for person you never meet and pro belly won't..

I hope I can give the same treatment (a few 100 years in the future) to other newbies on this forum.

- C Guru .. yepp that's me ...

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

Phew, that was a long read...

Unfortunately, I have no idea of why/how/etc. Let's see if Senthill browses through and has some insight into this, as he has infinetly more knowledge than me on these issues...

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

A neighbor ....

Morn morn ... Eller är det natt? .. bah har tappat fattningen ...

A few post above ... It's written that PCINT2_vect is missing

Just add
#define PCINT2_vect_num 4
#define PCINT2_vect _VECTOR(4)

and inc the vector numbers ...

I would also include that there is some issue with avrisp mkii + AS6.1 + TPI (ATtiny40).

I had to break out my own extern reset button. It was working for approx 1 - 2 weeks.

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

pernils wrote:
You have been right in all other things so ..
HA! I can hear the list laughing already! Have a look at some of my recent posts...
Quote:
Have read some sticky treads about "hostile" treatment to young players (it's me) But I must say I haven't seen such behavior.
It never pays to be rude, snide, impatient, or disrespectful. Always comes back to bite you in the asm.
Quote:
You and other have taking the time to deal with device that you never have seen an pro belly will not .. to easy the living for person you never meet and pro belly won't..
I cannot speak for others, but I contribute where (I believe) I can help to be sure, but it also serves to sharpen my own skills and knowlege. I learn more than I teach. Indeed I just learned something very important about dynamic memory in another thread (to which I have not yet properly responded, as I have been this week posting from a smart phone while at another job), after having initially steered the OP in the wrong direction.
Quote:
I hope I can give the same treatment (a few 100 years in the future) to other newbies on this forum.
It won't take you that long. Read a lot. Solve the problems of others on your own as an exercise. When you grow confident in your answers, share them. And stay humble ;)

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

pernils wrote:
just add
#define PCINT2_vect_num 4
#define PCINT2_vect _VECTOR(4)

and inc the vector numbers.

More accurately, make the correction in the XML file for the device.

JJ

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

Quote:

Morn morn ... Eller är det natt? .. bah har tappat fattningen ...

Hehe, slikt er da ikke så farlig, døgnville er vi alle mann for tiden :P

If you want to be in tracking loop for this, I would suggest that you add a bug on this and I'll notify the internal team about this next time I'm in the office...

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

Nä .. följer så mycke annat ändå.

Var faktiskt i Tronheim för 8 år sedan och drog en hamburgare.

I edit iotn40 so it's okey for now. If it all works I maybe gonna start my own project and implement a pic.

* typo error
on line the line ...
... implement a pic. should be -> implement a avr.
*

Pages