Forum: Mikrocontroller und Digitale Elektronik Probleme mit Counter


von Marcel Block (Gast)


Lesenswert?

hi,

hier erstmal der quellcode:
1
.include "4433def.inc"
2
3
; ---------------
4
; -- c<onstants --
5
; ---------------
6
.def   temp   = r16
7
.def  counter = r17
8
.def  time   = r18
9
.def  one   = r19
10
.def  zero   = r20
11
12
; ---------------------
13
; -- interrupt-table --
14
; ---------------------
15
.cseg
16
.org  $000
17
  rjmp  reset    ; reset interrupt
18
.cseg
19
.org  OVF0addr      
20
  rjmp  int_timer0   ; timer0 overflow interrupt
21
    
22
reset:  rjmp  init
23
24
; -----------------------
25
; -- interrupt-handler --
26
; -----------------------
27
int_timer0:  
28
  inc  counter
29
  cpse  counter, one
30
  reti        
31
  rjmp  count_0
32
count_0:
33
  ldi  counter, 0
34
  reti
35
36
; --------------------
37
; -- initialization --
38
; --------------------
39
init:
40
  ldi   r16, RAMEND   ; initialize the stack
41
  out   SPL, r16
42
  
43
  sei       ; enable interrupts  
44
  
45
        ldi   r16, 0xFF   ; PortB is output
46
        out   DDRB, r16
47
         
48
        ldi   r16, 0x00   ; PortD is input
49
        out   DDRD, r16
50
51
  ldi   one, 255   ; set some constans
52
  ldi   zero, 0
53
    
54
timer:
55
  ldi   counter, 0
56
57
  ldi  temp,timsk   ; init the register timsk
58
  ori  temp,0b00000010  
59
  out  timsk,temp    
60
61
  ldi  temp,tccr0   ; start Timer0 with
62
  ldi  temp,0b00000011 ; 1/64
63
  out  tccr0,temp    
64
      
65
  rjmp  loop
66
  
67
; ---------------------
68
; -- usefull methods --
69
; ---------------------
70
wait:  ldi  counter, 0
71
  ldi  time, 100
72
  rjmp  count
73
count:  
74
  cpse  counter, time  ; skip if we have 100 timer-overflows
75
  rjmp  count
76
  ret
77
78
; ---------------
79
; -- main-loop --
80
; ---------------
81
loop:    
82
  ldi   temp, 0b00000001
83
  out   PORTB, temp
84
  rcall   wait
85
  
86
  ldi  temp, 0b00000000
87
  out  PORTB, temp  
88
  rcall   wait
89
  
90
  ldi   temp, 0b00000010
91
  out   PORTB, temp
92
  rcall   wait
93
  
94
  ldi  temp, 0b00000000
95
  out  PORTB, temp
96
  rcall   wait
97
  
98
  rjmp   loop
99
  
100
; -----------------
101
; -- other stuff --
102
; -----------------

komischerweiße bleibt das programm beim ersten "rcall wait" einfach 
stehen und macht nix mehr.
ABER jetzt kommt das komische: wenn ich die stromzufuhr ganz kurz 
unterbreche und dann wieder herstelle dann funktioniert die schaltung 
auf einmal

habt ihr ne idee woran das liegen könnte?

MFG Marcel

von Marcel Block (Gast)


Lesenswert?

hat keiner ne idee?

von Uwe (Gast)


Lesenswert?

Hi!
Der Fehler sollte im Timerinit stecken.
Du schreibst:
timer:
  ldi counter, 0

  ldi temp,timsk ; init the register timsk
  ori temp,0b00000010
  out timsk,temp

TIMSK hat $39 + dein ori $2 =$3b
Damit wird TICIE1 + TOIE0 eingeschaltet, aber TICIE1 hat keine
ISR_adresse. Der Programmzeiger springt also irgendwo ins Progr.
Du wolltest vermutlich
in temp,timsk ; init the register timsk
schreiben, das könnte gehen. Aber warum diesen Aufwand?

ldi temp,$2
out timsk,temp

bewirkt das selbe.

ldi temp,tccr0 ; start Timer0 with
und
; -----------------------
; -- interrupt-handler --
; -----------------------

  rjmp count_0
count_0:

Ist auch unsinnig

Gruss Uwe

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.