buserror / simavr

simavr is a lean, mean and hackable AVR simulator for linux & OSX
GNU General Public License v3.0
1.59k stars 369 forks source link

avr_service_interrupts run out of nested stack! in CTC mode #187

Open xenon93 opened 7 years ago

xenon93 commented 7 years ago

I have issue setting the timers in CTC mode for all 8-bit Atmel MCU-s. The response I get from the test is : "avr_service_interrupts run out of nested stack!". Any help would be appreciated. Thank you.

Arcachofo commented 7 years ago

I Have same issue:

Simple 1 Hz blink led Timer0 CTC, working in real atmega 328p. Compiled with avra: avra -W NoRegDef -I /usr/share/avra blink328-t0.asm

;***** ; 1Hz Blink Led with Timer0 interrupt: ; Prescaler 256 => 16uS clock ; OCR0A = 125 => 16x125 = 2000 uS, 2 mS interrupt ; Counter = 250 => 2x250 = 500 mS Toggle Led = 1Hz

.INCLUDE "m328pdef.inc"

.EQU    Counter=256

.ORG    0
    rjmp    START 
.ORG    28
    rjmp    IntTIMER0_COMPA
.ORG    52   
START:
    sbi    DDRB,5                                     ;PORTB,5 as output

    ldi    r21,125                        ;Configure Timer0 for 2 ms CTC
    out    OCR0A,r21                                   ; Top value = 125
    ldi    r21,4
    out    TCCR0B,r21                                   ;Prescaler = 256
    ldi    r21,2
    out    TCCR0A,r21                                          ;CTC Mode
    ldi    r21,2    
    sts    TIMSK0,r21                         ;Enable T0 COMPA Interrupt
    sei                                               ;Enable interrupts
Loop_1:
    rjmp    Loop_1

IntTIMER0_COMPA:                                      ;Interrupt routine
    lds    r21,Counter
    inc    r21
    sts    Counter,r21
    cpi    r21,250
    brlo   END1
    ldi    r21,0
    sts    Counter,r21
    sbi    PINB,5
END1:
    reti

;***** Asm file as .txt: blink328-t0.txt

HEX: :020000020000FC :0200000033C00B :0200380023C0E3 :10006800259A5DE757BD54E055BD52E054BD52E0B6 :1000780050936E007894FFCF5091000153955093A0 :1000880000015A3F20F050E0509300011D9A189546 :00000001FF

Hex file as .txt blink328-t0.hex.txt