2
\$\begingroup\$

I have problems simulating the timer overflow in Atmel Studio 6. The code is for an Attiny10 and looks like below. As far as I know I set all the neccessary bits to enable the counter (which works in simulation) and the interrupt (which doesnt work in simulation).

I guess it's just a stupid mistake and I need a small hint so I would really appreciate if someone could tell me what I'm doing wrong.

;======================
; device attiny10
;======================
;.include tn10def.inc
; _____________
; /1 ° 6|
; O--|PB0 PB3|--O RESET
; | t10 |
; O--|GND VCC|--O
; | |
; O--|PB1 PB2|--O
; |______________|
;======================
; defines
;======================
.def temp = r16
;======================
; reset / int. vecs
;======================
.org 0x0000
 rjmp reset ; Reset Handler
.org 0x0004
 rjmp TIM0_OVF ; Timer0 Overflow Handler
.org 0x000A
;======================
; reset / setup
;======================
reset:
 in temp, TCCR0B ; turn timer on
 ori temp, (1<<CS00)
 out TCCR0B, temp
 in temp, TIMSK0 ; turn overflow interrupt on
 ori temp, (1<<TOIE0)
 out TIMSK0, temp
 ldi 0xff
 out DDRB, temp
 ldi 0x00
 out PORTB, temp
 ldi temp, 0xff
 out TCNT0H, temp
 ldi temp, 250
 out TCNT0L, temp
 ldi temp, 0xff
 sei
;======================
; main loop
;======================
main:
 rjmp main ; while(1);
; overflow interrupt
;====================== 
TIM0_OVF:
 com temp
 out PORTB, temp
 reti

EDIT: Solved: You cant step into/over an ISR. (Thx to Golaž)

asked Apr 20, 2015 at 14:13
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

If you havent got a compiler error when trying to compile the exact code you posted, you have a bigger problem.

Your code is working fine (ignoring the fact you missed out the register names in your 3rd block under reset label). However I would make some changes:

;======================
; device attiny10
;======================
;.include tn10def.inc
; _____________
; /1 ° 6|
; O--|PB0 PB3|--O RESET
; | t10 |
; O--|GND VCC|--O
; | |
; O--|PB1 PB2|--O
; |______________|
;======================
; defines
;======================
.def temp = r16
;======================
; reset / int. vecs
;======================
.org 0x0000
 rjmp reset ; Reset Handler
; Replace : .org 0x0004 with:
.org OVF0addr
 rjmp TIM0_OVF ; Timer0 Overflow Handler
; Replace: .org 0x000A with:
.org INT_VECTORS_SIZE ; End of vector table.
;======================
; reset / setup
;======================
reset:
 ; Initialize stack:
 ldi r16, HIGH(RAMEND)
 out SPH, r16
 ldi r16, LOW(RAMEND)
 out SPL, r16 
 in temp, TCCR0B ; turn timer on
 ori temp, (1<<CS00)
 out TCCR0B, temp
 in temp, TIMSK0 ; turn overflow interrupt on
 ori temp, (1<<TOIE0)
 out TIMSK0, temp
 ; You forgot to specify the regsiter here:
 ldi temp, 0xff
 out DDRB, temp
 ldi temp, 0x00
 out PORTB, temp
 ldi temp, 0xff
 out TCNT0H, temp
 ldi temp, 250
 out TCNT0L, temp
 ldi temp, 0xff
 sei
;======================
; main loop
;======================
main:
 rjmp main ; while(1);
; overflow interrupt
;====================== 
TIM0_OVF:
 com temp
 out PORTB, temp
 reti

You can find the include files for devices and all their specifics (such as OVF0addr, INT_VECTORS_SIZE, RAMEND, ...) in:

C:\Program Files (x86)\Atmel\Atmel Toolchain\AVRAssembler\Native2円.1.1117\avrassembler\include

I am not sure what your exact goal was here, when you've setted TCNT0 registers you've only set its value for one (current) cycle, when the timer would reach its maximum value it will restart from 0.

What was your goal with TIM0_OVF ISR I am not sure.

Stack is needed for the MCU to know which address to return to after the call to subfunction or ISR have been executed.

answered Apr 20, 2015 at 15:39
\$\endgroup\$
7
  • \$\begingroup\$ Well the stack pointer is initialized to RAMEND by default (by the simulator) it doesnt change a thing with or without initializing it manually. I want to have a timebase. Setting TCNT0 to that value make it overflowing in some tickes and i dont have to press F11 ~60000 times to see it overflowing. I knot that the timer overflows from MAX to 0 but when that happens it sould execute the overflow ISR but it doesnt and thats the problem. Eventhough without initialized stackpointer the simulator should at least enter the ISR but it doesnt. \$\endgroup\$ Commented Apr 20, 2015 at 16:13
  • \$\begingroup\$ @user3097432 How did you come to the conclusion, that the ISR doesnt get fired? Did you put a brakepoint in there...? \$\endgroup\$ Commented Apr 20, 2015 at 16:18
  • \$\begingroup\$ @user3097432 You dont have to manually tap F11 60000 times, just put a brakepoint along side one of the instructions inside ISR and click run. Also, if nothing more manually setting stack pointer ensures better portabillity. \$\endgroup\$ Commented Apr 20, 2015 at 16:26
  • \$\begingroup\$ I know I dont have to tab F11 60000 times if I preset the timer register close to the MAX which I did. I can tell its not entering the ISR because I can step into (F11-key) and watch all the registers and the actual program counter position. I dont let the simulation run in free mode I let it run step by step so I let the program run op-code by op-code. And the code in the ISR, which is supposed to invert the value of PORTB, doesnt change PORTB. \$\endgroup\$ Commented Apr 20, 2015 at 16:26
  • \$\begingroup\$ @user3097432 Please do as described above. \$\endgroup\$ Commented Apr 20, 2015 at 16:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.