]> hackdaworld.org Git - my-code/atmel.git/commitdiff
more control
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 16 Feb 2011 15:24:54 +0000 (16:24 +0100)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Wed, 16 Feb 2011 15:24:54 +0000 (16:24 +0100)
monolyzer/main.asm
monolyzer/port.asm
monolyzer/timer.asm

index bcc6c1c87b1ced5d2b0adff680ac0d58cbe830fe..e17e9a774854952e6b91c82d7a78dbffd87ff472 100644 (file)
@@ -35,7 +35,7 @@ reti
 reti
 
 ; T1 OVF1
-reti
+rjmp T1_OVF_IR
 
 ; T0 OVF0
 reti
@@ -104,23 +104,18 @@ INIT:
 
        ; more init
        ldi count,0
-       ldi state,1
+       ldi state,0
 
        ; storage pointer
        ldi ZL,low(STORAGE)
        ldi ZH,high(STORAGE)
 
-       ; counter
-       ldi tmp1,0
-       out TCNT1H,tmp1
-       out TCNT1L,tmp1
-
        ; signal ready output
        ldi uart_rxtx,0x72
        rcall UART_TX
 
        ; external interrupt enable
-       rcall INT0_IR_CONF
+       rcall INT0_IR_CONF_INIT
        rcall INT0_IR_ENABLE
 
        ; global interrupt enable
@@ -131,11 +126,12 @@ MAIN:
 SAMPLE:
 
        ; sample as long as there is storage capacity
-       sbrc state,0
+       sbrs state,0
        rjmp SAMPLE
 
-       ; external interrupt enable
+       ; disable interrupts
        rcall INT0_IR_DISABLE
+       rcall TIMER1_INT_DISABLE
 
        ; signal finish
        ldi uart_rxtx,0x66
@@ -159,7 +155,11 @@ TRANSFER:
        ; reset storage pointer
        ldi ZL,low(STORAGE)
        ldi ZH,high(STORAGE)
-       ldi count,0
+       ldi tmp1,0
+
+       ; transmit number of sampled words
+       mov uart_rxtx,count
+       rcall UART_TX
 
 TRANSFER_LOOP:
 
@@ -168,10 +168,10 @@ TRANSFER_LOOP:
        rcall UART_TX
 
        ; count sent data
-       add count,one
+       add tmp1,one
 
        ; check amount of sent data
-       cpi count,110
+       cp tmp1,count
        breq IDLE
 
        rjmp TRANSFER_LOOP
@@ -190,9 +190,29 @@ INT0_IR:
        ; debug output
        ; cbi PORTD,3
 
-       ; write timer value into sram
+       ; get timer value
        in tmp1,TCNT1L
        in tmp2,TCNT1H
+
+       ; check for initial or running state
+       cpi state,0
+       brne INT0_RUN
+
+       ; configure interrupt for running state
+       rcall INT0_IR_CONF_RUN
+       ldi state,1
+
+       ; reset timer and start ovf interrupt
+       ldi tmp1,0
+       out TCNT1H,tmp1
+       out TCNT1L,tmp1
+       rcall TIMER1_INT_ENABLE
+
+       rjmp EXIT_IR
+
+INT0_RUN:
+
+       ; write timer value into sram
        st Z+,tmp2
        st Z+,tmp1
 
@@ -213,6 +233,13 @@ EXIT_IR:
 
        reti
 
+T1_OVF_IR:
+
+       ; exit sampling
+       ldi state,0
+
+       reti
+
 
 ;
 ; sram
index d3ea5244828d24c24969b0bfc22539f4ae3263a7..42c08fa912e3d2c09f6a52259d145465fffd96a0 100644 (file)
@@ -20,7 +20,17 @@ PORT_INIT:
        ret
 
 
-INT0_IR_CONF:
+INT0_IR_CONF_INIT:
+
+       ; trigger interrupt on rising edge
+       in tmp1,MCUCR
+       sbr tmp1,(1<<ISC01)
+       sbr tmp1,(1<<ISC00)
+       out MCUCR,tmp1
+
+       ret
+
+INT0_IR_CONF_RUN:
 
        ; trigger interrupt on falling and rising edge
        in tmp1,MCUCR
index 2f14b6999ed77ccf72d92bf7c943a344acc3ae34..3327547b98574fbeceac73ee6abd16558802553d 100644 (file)
@@ -3,8 +3,29 @@
 TIMER1_INIT:
 
        ; clock select, prescaler 8
-       ldi tmp1,0x02
+       in tmp1,TCCR1B
+       cbr tmp1,(1<<CS12)
+       sbr tmp1,(1<<CS11)
+       cbr tmp1,(1<<CS10)
        out TCCR1B,tmp1
 
        ret
 
+TIMER1_INT_ENABLE:
+
+       ; overflow interrupt enable
+       in tmp1,TIMSK
+       sbr tmp1,(1<<TOIE1)
+       out TIMSK,tmp1
+
+       ret
+
+TIMER1_INT_DISABLE:
+
+       ; overflow interrupt disable
+       in tmp1,TIMSK
+       cbr tmp1,(1<<TOIE1)
+       out TIMSK,tmp1
+
+       ret
+