so habe mir mal gedanken gemacht und viel gelesen.folgendes kam dabei
raus.wollte eine Phasenverschiebung zwischen zwei Signalen bestimmen.
mein Code für die Phasenverschiebung zu berechnen:
; RAM locations to store capture values
CAPTURE 0 DATA 30H
CAPTURE 1 DATA 32H
PHASE DATA 34H
FLAG 0 BIT 20H.0
FLAG 1 BIT 20H.1
;
ORG 0000H
JMP PCA INIT
ORG 0033H
JMP PCA INTERRUPT
;
PCA INIT:
; Same initialization for PCA timer, and interrupt as
; in Listing 1. Initialize two PCA modules as follows:
;
MOV CCAPM0, #21H ; Module 0 capture rising edges
MOV CCAPM1, #21H ; Module 1 same
;
;***********************************************************************
***************
; Main program goes here
;***********************************************************************
***************
; This code assumes only Modules 0 and 1 are being used.
PCA INTERRUPT:
JB CCF0, MODULE 0 ; Determine which module's
JB CCF1, MODULE 1 ; event caused the interrupt
;
MODULE 0:
CLR CCF0 ; Clear Module 0's event flag
MOV CAPTURE 0, CCAP0L ; Save 16-bit capture value
MOV CAPTURE 001, CCAP0H
JB FLAG 1, CALCULATE PHASE ; If capture complete on
; Module 1, go to calculation
SETB FLAG 0 ; Signify capture on Module 0
RETI
MODULE 1:
CLR CCF 1 ; Clear Module 1's event flag
MOV CAPTURE 1, CCAP1L
MOV CAPTURE 101, CCAP1H
JB FLAG 0, CALCULATE PHASE ; If capture complete on
; Module 0, go to calculation
SETB FLAG 1 ; Signify capture on Module 1
RETI
;
CALCULATE PHASE:
PUSH ACC ; This calculation does not
PUSH PSW ; have to be completed in the
CLR C ; interrupt service routine
;
JB FLAG 0, MOD0 LEADING
JB FLAG 1, MOD1 LEADING
;
MOD0 LEADING:
MOV A, CAPTURE 1
SUBB A, CAPTURE 0
MOV PHASE, A
MOV A, CAPTURE 101
SUBB A, CAPTURE 001
MOV PHASE01, A
CLR FLAG 0
JMP EXIT
;
MOD1 LEADING:
MOV A, CAPTURE 0
SUBB A, CAPTURE 1
MOV PHASE, A
MOV A, CAPTURE 001
SUBB A, CAPTURE 101
MOV PHASE01, A
CLR FLAG 1
EXIT:
POP PSW
POP ACC
RETI
Bevor ich es einspiele wollte ich mal fragen ob das so funktionieren
könnte.
möchte dann noch einen Timer programmieren mit dem ich ein 40 kHz Signal
erzeugen kann. Da hatte ich mir sowas hier vorgestellt. bin mir aber
nicht ganz sicher:
PWM_OFFTIME EQU 10
PWM_ONTIME EQU 11
PWM_OUT EQU P3.0
SEGMENT code
ORG 0h
jmp start
; Interruptbehandlungsroutine Timer 0
; Jeder Durchlauf braucht 9 Zyklen
ORG 0Bh
cpl PWM_OUT
jb PWM_OUT, pwm_on
pwm_off:
mov TH0, PWM_ONTIME
reti
pwm_on:
mov TH0, PWM_OFFTIME
reti
; Initialisierung
start:
mov TL0, PWM_ONTIME
mov TH0, PWM_OFFTIME
mov SP, #20h
mov TMOD,#2
mov TCON,#16
mov IE, #130
; Hauptprogramm
main:
mov a,P1
subb a,#20
mov PWM_ONTIME, a
subb a,#255
mov PWM_OFFTIME, a
jmp main
END
Ok hoffe das sich jemand dazu äussert. würde mich freuen.
vielen dank im vorraus.
mfg sven
>Bevor ich es einspiele wollte ich mal fragen ob das so funktionieren >könnte. Umgekeht wäre besser! Erst ausprobieren und wennde nicht mehr weiterkommst dann vrägen. Glaubst du ernsthaft, daß sich jemand einen Kopp macht, sich in die Materie einzuarbeiten und dein Proggi im Kopp durchlaufen zu lassen? Probiers aus oder geht da was bei in'n Eimer?
Wie wäre es z.B. mit nem Simulator ? Keil dürfte doch dafür funktioklappnieren , oder ?
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
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.