Hi,
Ich hab irgendwie n Problem mit dem CTC Counter. Ich hab n magnetfeldsensor um ne drehzahl zu messen. Nun will ich, dass jede Sekunde die drehzahl aus m register abgefragt und zur geschwindigkeit hochgerechnet wird (geht um mein RC Car) und vorerst testweiße an UART gesendet wird. Problem dabei is, dass ich am Com-port nich jede Sekunde, sondern dauern, fortlaufen was bekomme.. dann natürlich 0, weil der sensor nich so schnell is.. Von der Logik her müsste es aber eigentlich funktionieren.. Ich habs mit 2 verschiedenen Atmega8 probiert,l bei beiden das selbe. Mein Code:
Ich hoffe ihr könnt mir helfen und findet den fehlerCode:.include "m8def.inc" .def temp = r16 .def counts = r17 .def kmh = r18 .def time1 = r21 .def time2 = r22 .equ CLOCK = 16000000 .equ BAUD = 9600 .equ UBRRVAL = CLOCK/(BAUD*16)-1# .org 0x000 rjmp main .org INT0addr rjmp int0_handler .org OC1Aaddr rjmp timer1_compare main: ldi temp, LOW(RAMEND) out SPL, temp ldi temp, HIGH(RAMEND) out SPH, temp ldi temp, LOW(UBRRVAL) out UBRRL, temp ldi temp, HIGH (UBRRVAL) out UBRRH, temp ldi temp, high(40000-1) out OCR1AH, temp ldi temp, low(40000-1) out OCR1AL, temp ldi temp, ( 1 << WGM12 ) | ( 1 << CS00 ) out TCCR1B, temp ldi temp, 1 << OCIE1A ; OCIE1A: Interrupt bei Timer Compare out TIMSK, temp ldi temp, (1<<URSEL)|(3<<UCSZ0) out UCSRC, temp ldi temp, 0x00 out DDRD, temp ;ldi temp, 0xFF ;out PORTD, temp ldi temp, 0b00001010 ; INT0 und INT1 konfigurieren out MCUCR, temp ldi temp, 0b11000000 ; INT0 und INT1 aktivieren out GICR, temp sbi UCSRB,TXEN sei loop: rjmp loop int0_handler: ldi temp, 1 add counts, temp reti timer1_compare: cpi time1, 100 breq time2u brne time1w time2u: cpi time2, 4 breq rechnekmh brne time2w time1w: inc time1 reti time2w: inc time2 reti rechnekmh: clr kmh mov kmh, counts lsl kmh clr counts rjmp uartu uartu: sbis UCSRA, UDRE rjmp uartu out UDR, kmh reti
Edit: der Zähler zählt bis 40000, dann wird in nem register auf 100, in nem weiteren dann auf 4 gezählt. Somit sind das 16000000 Zählschritte, die auch dem 16MHZ Takt entsprechen, also 1 Sekunde
gruß homedom







Zitieren

Lesezeichen