| ??? 05/09/07 20:15 Read: times |
#138936 - But you didn't tell him how! Responding to: ???'s previous message |
So now he knows what it should look like, but is none the wiser as to how to achieve it!
The answer, of course, is here: http://www.8052.com/faqs.phtml?FAQ=120199 You also "formatted" the entire post - it's better just to have the code monospaced, and the "prose" in the other font: At first I would like say that I am a beginner on this field. I would like to program a microcontroller of Silabs and i use the C8051FX20-TB. First I would like to program a PWM with output signal 40kHz. That is in fact that, what should function first befor it further goes. Sorry for my bad Englisch. The second part is a programm to be used for the calculation of the phase difference. Somebody already had experiences with that and could help me. Thanks for the efforts For the first part I had considered following:
CPU 8051
INCLUDE stddef51
PWM_OFFVALUE EQU 10
PWM_ONVALUE EQU 11
PWM_COUNT EQU 12
PWM_OUT EQU P3.0
SEGMENT code
ORG 0h
jmp start
; Interruptbehandlungsroutine Timer 0
; Jeder Durchlauf braucht 9 Zyklen
ORG 0Bh
djnz PWM_COUNT, pwm_exit
jb PWM_OUT, pwm_on
pwm_off:
mov PWM_COUNT, PWM_ONVALUE
setb PWM_OUT
reti
pwm_on:
mov PWM_COUNT, PWM_OFFVALUE
clr PWM_OUT
pwm_exit:
reti
; Initialisierung
start:
mov TL0, #235
mov TH0, #235
mov SP, #20h
mov TMOD,#2
mov TCON,#16
mov IE, #130
; Hauptprogramm
main:
; quick 'n dirty Parameter als Test von P1 holen
mov a,P1
subb a,#20
mov PWM_ONVALUE, a
subb a,#255
mov PWM_OFFVALUE, a
jmp main
END
---------------------------------------------------------------
If I enter the code so nothing with my microcontroller passes. Just I initialize still anything? Or is something wrong? Thats the first Question i have!! For the second part I read through the PCA Cookbook and I wanted to attempt following:
; Befehl wo Daten gespeichert werden sollen im RAM
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: ; PCA Timer
initialisieren
MOV CMOD, #00H
MOV CH, #00H
MOV CL, #00H
; in Listing 1. Initialize two PCA modules as follows
;
MOV CCAPM0, #21H
MOV CCAPM1, #21H
;
SETB EC ;Einschalten PCA interrupt
SETB EA
SETB CR ;PCA Timer einschalten ( Zähler Bit)
CLR FLAG ;Reset Test Flag
;***************************************************************
; Hauptprogramm
;***************************************************************
; Im Hauptprogramm werden nur Modul 0 und Modul 1 verwendet.
PCA_INTERRUPT:
JB CCF0, MODULE_0
JB CCF1, MODULE_1
;
MODULE_0:
CLR CCF0
MOV CAPTURE_0, CCAP0L
MOV CAPTURE_0+1, CCAP0H
JB FLAG_1, CALCULATE_PHASE
SETB FLAG_0
RETI
MODUL_1:
CLR CCF_1
MOV CAPTURE_1, CCAP1L
MOV CAPTURE_1+1, CCAP1H
JB FLAG_0, CALCULATE_PHASE
SETB FLAG_1
RETI
;
CALCULATE_PHASE:
PUSH ACC
PUSH PSW
CLR C
;
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 _1+1
SUBB A, CAPTURE_0+1
MOV PHASE+1, A
CLR FLAG_0
JMP EXIT
;
MOD1_LEADING:
MOV A, CAPTURE_0
SUBB A, CAPTURE_1
MOV PHASE, A
MOV A, CAPTURE_0+1
SUBB A, CAPTURE_1+1
MOV PHASE+1, A
CLR FLAG_1
EXIT:
POP PSW
POP ACC
RETI
|
| Topic | Author | Date |
| project | 01/01/70 00:00 | |
| OK, first \'lesson\' | 01/01/70 00:00 | |
| good practice | 01/01/70 00:00 | |
| correct, but let me add | 01/01/70 00:00 | |
| Code formatted | 01/01/70 00:00 | |
| but still not commented | 01/01/70 00:00 | |
| But you didn't tell him how! | 01/01/70 00:00 | |
| Question? | 01/01/70 00:00 | |
| I guess you are using a C8051F020 | 01/01/70 00:00 | |
| Or is it the C8051F120? | 01/01/70 00:00 | |
| link | 01/01/70 00:00 | |
| look here | 01/01/70 00:00 | |
Does not fit | 01/01/70 00:00 |



