ok, stopwatch
Postat: 14 januari 2006, 00:09:33
Jag andvänder stop watch. men jag fattar inte hur jag andvänder detta verktyg. Jag sätter en breakpoint i slutet av subrutien init sedan en i början av interrupt subrutien isr_start_hog. Det är mellan dessa två brytpunkter vill jag mäta tiden för programmet att ta sig dit. Med andra ord kollar jag så att när huvudprogrammet börjar att köras dröjer det 50 ms innan subrutien kommer in i bilden. Hur simulerar och mäter jag detta med hjälpa av stop watch, hur gör jag. För om du går in i breakpoints menyn under debugger f12 så sätter den ett frågeteken på breakpoint i subrutinen på någon sludig anledning. Varför är min fråga. Och sedan hur mäter jag denna tid.
här kommer koden
list P=18F452
#include <P18F452.INC>
CONFIG OSC=HS ; Sätt in det som stämmer överens med din miljö !!
; CONFIG isrOSCS=OFF, PWRT=ON, BOR=OFF, WDT=OFF, LVP=OFF, DEBUG=OFF
CONFIG CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF
CONFIG WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTB=OFF, WRTC=OFF, WRTD=OFF
CONFIG EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used.
; More variables may be needed to store other special function registers used
; in the interrupt routines.
;
;UDATA
;
;WREG_TEMP RES 1 ;variable in RAM for context saving
;STATUS_TEMP RES 1 ;variable in RAM for context saving
;BSR_TEMP RES 1 ;variable in RAM for context saving
;
; OVANSTÅENDE BEHÖVS INTE...
; **************Variabler***********************************************
UDATA
Rotation res 1
Input res 1
UDATA_ACS
;**************************Konstanter**************************************
; Definiera upp några konstanter
#define STOPPA_VARDE 1
#define RULLA_ENA_HALLET 2
#define RULLA_ANDRA_HALLET 4
;******************Reset_start*************************************************
;Reset and interrupt vectors
code h'0000'
goto Main
ISR_hog code h'8'
goto isr_start_hog
ISR_log code h'18'
goto isr_start_log
;**************************************************************************
;***************interrupt_låg****************************************************
isr_log_code code
isr_start_log
bcf INTCON3,INT1IF ;Clear INT1 external interrupt flag.
nop
nop
nop
retfie
;**************interrupt_hög**************************************************************
isr_hog_code code
isr_start_hog
nop
nop
nop
nop
nop
movlw h'0B'
movwf TMR0H
movlw h'DC'
movwf TMR0L
bcf INTCON,TMR0IF
retfie
;***************interrupt_konfig***********************************************
;här ställer jag in konfigruerar jag pic:en EX ställer in Out/in defineras och register ställs in.
;init_code code
init
;****************************Konfig portA*********************************************
movlw H'06'
movwf ADCON1
movlw B'11111111'
movwf TRISA ;Sätter PortB till ingångar bit 0-7
;****************************Generella Interrupts inställningar*************
bsf RCON,IPEN ;Enable priority levels on interrupts
bsf INTCON,PEIE ;Enables all unmasked peripheral interrupts
bsf INTCON,GIE ;Enable global interrupts.
;**************************Interrupt overflow*************************
bcf T0CON,T0CS
bcf T0CON,T08BIT
bsf T0CON,TMR0ON
bcf T0CON,PSA
bcf T0CON,T0PS2
bsf T0CON,T0PS1
bsf T0CON,T0PS0
clrf TMR0L
clrf TMR0H
movlw h'0B'
movwf TMR0H
movlw h'DC'
movwf TMR0L
bsf INTCON2,TMR0IP
bsf INTCON,TMR0IE
;********************************************************************
return
;*********************Main********************************************
; Start of main program
Main
call init
movlw STOPPA_VARDE ; Rotation = Stoppa_Värde
movwf Rotation
MAIN_LOOP
clrf PORTA
movf PORTA ; Input = PORTA & 0x03
andlw 0x03
movwf Input
; switch(Input)
CASE_1
btfss Input,0 ; Bit 0 satt?
goto CASE_2 ; Nix, hoppa vidare
movlw RULLA_ENA_HALLET ; Japp! Rotation = Rulla_Ena_Hållet
movwf Rotation
goto MAIN_LOOP ; break;
CASE_2
btfss Input,1 ; Bit 1 satt?
goto CASE_3 ; Nix, hoppa vidare
movlw RULLA_ANDRA_HALLET ; Japp!
movwf Rotation ; Rotation = Rulla_Andra_Hållet
goto MAIN_LOOP ; break;
CASE_3
btfss Input,2 ; Bit 2 & satt?
goto MAIN_LOOP ; Nix, hoppa vidare
movlw STOPPA_VARDE ; Japp! Rotation = Stoppa_Värde
movwf Rotation
goto MAIN_LOOP
;******************************************************************************
;End of program
END
här kommer koden
list P=18F452
#include <P18F452.INC>
CONFIG OSC=HS ; Sätt in det som stämmer överens med din miljö !!
; CONFIG isrOSCS=OFF, PWRT=ON, BOR=OFF, WDT=OFF, LVP=OFF, DEBUG=OFF
CONFIG CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF
CONFIG WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTB=OFF, WRTC=OFF, WRTD=OFF
CONFIG EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used.
; More variables may be needed to store other special function registers used
; in the interrupt routines.
;
;UDATA
;
;WREG_TEMP RES 1 ;variable in RAM for context saving
;STATUS_TEMP RES 1 ;variable in RAM for context saving
;BSR_TEMP RES 1 ;variable in RAM for context saving
;
; OVANSTÅENDE BEHÖVS INTE...
; **************Variabler***********************************************
UDATA
Rotation res 1
Input res 1
UDATA_ACS
;**************************Konstanter**************************************
; Definiera upp några konstanter
#define STOPPA_VARDE 1
#define RULLA_ENA_HALLET 2
#define RULLA_ANDRA_HALLET 4
;******************Reset_start*************************************************
;Reset and interrupt vectors
code h'0000'
goto Main
ISR_hog code h'8'
goto isr_start_hog
ISR_log code h'18'
goto isr_start_log
;**************************************************************************
;***************interrupt_låg****************************************************
isr_log_code code
isr_start_log
bcf INTCON3,INT1IF ;Clear INT1 external interrupt flag.
nop
nop
nop
retfie
;**************interrupt_hög**************************************************************
isr_hog_code code
isr_start_hog
nop
nop
nop
nop
nop
movlw h'0B'
movwf TMR0H
movlw h'DC'
movwf TMR0L
bcf INTCON,TMR0IF
retfie
;***************interrupt_konfig***********************************************
;här ställer jag in konfigruerar jag pic:en EX ställer in Out/in defineras och register ställs in.
;init_code code
init
;****************************Konfig portA*********************************************
movlw H'06'
movwf ADCON1
movlw B'11111111'
movwf TRISA ;Sätter PortB till ingångar bit 0-7
;****************************Generella Interrupts inställningar*************
bsf RCON,IPEN ;Enable priority levels on interrupts
bsf INTCON,PEIE ;Enables all unmasked peripheral interrupts
bsf INTCON,GIE ;Enable global interrupts.
;**************************Interrupt overflow*************************
bcf T0CON,T0CS
bcf T0CON,T08BIT
bsf T0CON,TMR0ON
bcf T0CON,PSA
bcf T0CON,T0PS2
bsf T0CON,T0PS1
bsf T0CON,T0PS0
clrf TMR0L
clrf TMR0H
movlw h'0B'
movwf TMR0H
movlw h'DC'
movwf TMR0L
bsf INTCON2,TMR0IP
bsf INTCON,TMR0IE
;********************************************************************
return
;*********************Main********************************************
; Start of main program
Main
call init
movlw STOPPA_VARDE ; Rotation = Stoppa_Värde
movwf Rotation
MAIN_LOOP
clrf PORTA
movf PORTA ; Input = PORTA & 0x03
andlw 0x03
movwf Input
; switch(Input)
CASE_1
btfss Input,0 ; Bit 0 satt?
goto CASE_2 ; Nix, hoppa vidare
movlw RULLA_ENA_HALLET ; Japp! Rotation = Rulla_Ena_Hållet
movwf Rotation
goto MAIN_LOOP ; break;
CASE_2
btfss Input,1 ; Bit 1 satt?
goto CASE_3 ; Nix, hoppa vidare
movlw RULLA_ANDRA_HALLET ; Japp!
movwf Rotation ; Rotation = Rulla_Andra_Hållet
goto MAIN_LOOP ; break;
CASE_3
btfss Input,2 ; Bit 2 & satt?
goto MAIN_LOOP ; Nix, hoppa vidare
movlw STOPPA_VARDE ; Japp! Rotation = Stoppa_Värde
movwf Rotation
goto MAIN_LOOP
;******************************************************************************
;End of program
END