Como mudar os timers

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

Como mudar os timers

Mensagempor Hermann Rocha » 23 Mai 2007 10:24

Ola a todos, Algum tempo atrás fazendo umas pesquisas sobre temporizadores usando o lm555 encontrei esse código p/ PIC, pelo que entendi faz 4 saídas do pic serem temporizadas com tempos diferentes que podem ser modificadas no código. Se alguém mostrar onde modificar agradeço, pois estou algum tempo tentando.

LIST b=16, n=0, t=ON, st=On, c=80
; b - tab spacing
; n - lines per page
; c - column width
; t - truncate lines on, wrap lines off
; st - print symbol table on/off

IFDEF __12F683
#include "p12f683.inc"
#define ADCpresent
ENDIF


IFDEF __12F675
#include "p12f675.inc"
#define ADCpresent
ENDIF

IFDEF __12F629
#include "p12f629.inc"

ENDIF
errorlevel -302 ; suppress banksel warning messages
IFDEF __12F683
__CONFIG _CP_OFF & _WDT_OFF & _BOD_OFF &_PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
ELSE
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
ENDIF




; Set delay times
; -----------------------------------------------------------------------------
; Either multiples of 1mS or 100mS can be set in the main code.
; Each interval can be set independantly to 1mS or 100mS
; Currently main code sets all delays for 1mS intervals
;
; .0 <= Delay <=.255
delay1 equ .5 ; trigger to out1
delay2 equ .5 ; out1 to out2
delay3 equ .5 ; out2 to out3
delay4 equ .25 ; out3 to out4
;
; Delays are software generated and approximate. Accuracy depends a lot on the
; correct calibration value being written to the OSCCAL register.
; You may need to test and fine tune the values to get the actual delays required.


; GPIO port definitions
; -----------------------------------------------------------------------------
; The code will automatiaclly set the TRIS register correctly according to the values here.

reset EQU 5 ;in
out4 EQU 4 ;out
trigger EQU 3 ;in
out3 EQU 2 ;out
out2 EQU 1 ;out
out1 EQU 0 ;out

; Program application variables
; -----------------------------------------------------------------------------
;
cblock 0x20
dtime ; used by delay function
ltime ; used by delay function
endc

; Bank Select pseudo instructions
; -----------------------------------------------------------------------------
;
#define setbank0 bcf STATUS,RP0 ; Sel Bank 0
#define setbank1 bsf STATUS,RP0 ; Sel Bank 1


; ******************************************************************************************************

; Reset Vector
; ------------
org 0x000
_resetVector goto _startup

; ******************************************************************************************************
; Main code block

; This waits for a low-to-high transition before triggering delayed outputs
; This is a software edge trigger - not level triggered
; --------------------------------------------------------------------------
_waitLow btfsc GPIO,trigger ; test trigger input
goto _waitLow ; if input is high wait for it to go low
nop
_waitHigh btfss GPIO,trigger ; test trigger input
goto _waitHigh ; if input low wait for it to go high

; --------------------------------------------------------------------------


; First delay between trigger input going high and output 1 going high
; --------------------------------------------------------------------------
_outDelay1 movlw delay1 ; load W with 5 (0 => W <= 255)
addlw .0 ; add 0 to test for 0
skpz ; Don't call Delay if W=0 (0ms)
call _Delay ; call 1mS delay function
; change _Delay above to _LDelay for delay with 100mS intervals

bsf GPIO,out1 ; set output 1 high
; --------------------------------------------------------------------------

; Second delay between output 1 going high and output 2 going high
; --------------------------------------------------------------------------
_outDelay2 movlw delay2 ; load W with 5 (0 => W <= 255)
addlw .0 ; add 0 to test for 0
skpz ; Don't call Delay if W=0 (0ms)
call _Delay ; call 1mS delay function
; change _Delay above to _LDelay for delay with 100mS intervals

bsf GPIO,out2 ; set output 2 high
; --------------------------------------------------------------------------

; Third delay between output 2 going high and output 3 going high
; --------------------------------------------------------------------------
_outDelay3 movlw delay3 ; load W with 5 (0 => W <= 255)
addlw .0 ; add 0 to test for 0
skpz ; Don't call Delay if W=0 (0ms)
call _Delay ; call 1mS delay function
; change _Delay above to _LDelay for delay with 100mS intervals

bsf GPIO,out3 ; set output 3 high
; --------------------------------------------------------------------------

; Fourth delay between output 3 going high and output 4 going high
; --------------------------------------------------------------------------
_outDelay4 movlw delay4 ; load W with 5 (0 => W <= 255)
addlw .0 ; add 0 to test for 0
skpz ; Don't call Delay if W=0 (0ms)
call _Delay ; call 1mS delay function
; change _Delay above to _LDelay for delay with 100mS intervals

bsf GPIO,out4 ; set output 4 high
; --------------------------------------------------------------------------

; Level triggered reset.
; if reset input is high, code clears outputs and waits for next trigger input
; --------------------------------------------------------------------------
_reset btfss GPIO,reset ; load W with 255 (0 => W <= 255)
goto _reset
clrf GPIO ; clear all outputs
goto _waitLow ; go back and wait for next lo-to-hi transition
; of input.
; --------------------------------------------------------------------------



; ******************************************************************************************
; Delay Function
; Software delay relies on accuracy of PIC internal RC oscillator
; Based on instruction execution time of 1uS this function will provide
; delays of W x 1mS or W x 100mS

_Delay movwf dtime ; Call for W x 1mS
__Dcall call __1mS
decfsz dtime,F
goto __Dcall
__DlyEnd return
_LDelay movwf ltime ; Call for W x 100mS
__Dlcall movlw d'100'
call _Delay
decfsz ltime,F
goto __Dlcall
return
__1mS movlw 0xC6
_next nop
addlw 0xFF
btfss STATUS,Z
goto _next
nop
nop
nop

return

; ******************************************************************************************************
; Initialisation and startup code block
; ------------------------------------------------------------------------------------------------------

_startup clrf GPIO ; clear GPIO output before setting TRIS register
setbank1 ; switch to register bank 1

IFDEF OSCCAL ; defined only for 12F629 / 675
call 0x3FF ; read factory oscillator calibration value
movwf OSCCAL ; write to OSCCAL register
; If using a 12F629/675 this value must be present
; and correct, or the code will not function properly
; if it functions at all.
ENDIF

IFDEF ADCpresent
clrf ANSEL ; Set ports for digital mode (12F675 / 12F683 only)
ENDIF
movlw ~(1<<out1 | 1<<out2 | 1<<out3 | 1<<out4)
movwf TRISIO ; Sets TRIS register

; Set weak-pull up (enable as required here)
; ---------------------------------------------------------------
bcf OPTION_REG,NOT_GPPU ; enable weak-pull up
bsf WPU,5 ; enable weak-pull-up on GPIO5
;bsf WPU,4 ; enable weak-pull-up on GPIO4
;bsf WPU,2 ; enable weak-pull-up on GPIO2
;bsf WPU,1 ; enable weak-pull-up on GPIO1
;bsf WPU,0 ; enable weak-pull-up on GPIO0
; GPIO3 has no weak-pull-up feature

setbank0
movlw 0x07 ; load W=7
IFDEF __12F683
movwf CMCON0 ; disable Comparator
ELSE
movwf CMCON ; disable Comparator
ENDIF
clrf GPIO ; clear GPIO


; Initialise variables
; ---------------------------------------------------------------
; not using any:-)

goto _waitLow ; device initialised, Start main code.



end
Hermann Rocha
Nibble
 
Mensagens: 59
Registrado em: 09 Fev 2007 20:47

Mensagempor RobL » 23 Mai 2007 11:00

Deve ser aqui:
; Either multiples of 1mS or 100mS can be set in the main code.
; Each interval can be set independantly to 1mS or 100mS
; Currently main code sets all delays for 1mS intervals
;
; .0 <= Delay <=.255
delay1 equ .5 ; trigger to out1
delay2 equ .5 ; out1 to out2
delay3 equ .5 ; out2 to out3
delay4 equ .25 ; out3 to out4
RobL
Dword
 
Mensagens: 1546
Registrado em: 20 Fev 2007 17:56

Mensagempor Hermann Rocha » 23 Mai 2007 14:08

Ola Robl, já mudei os valores de 5 para 100 por ex. e não mudou nada, não sei se estou fazendo certo, pois já vi em outro timer que o tempo era +ou- assim 1 * .3 * .50 fiz desta forma também mais nada, sei que esta funcionando, pois quando aperto o botão da pra perceber que os leds acendem sucessivamente e ficando todos acesos só que esta muito rápido. obrigado
Hermann Rocha
Nibble
 
Mensagens: 59
Registrado em: 09 Fev 2007 20:47

Mensagempor RobL » 23 Mai 2007 18:54

Se for um 12F629
Experimente tirar essa parte do programa:

IFDEF OSCCAL ; defined only for 12F629 / 675
call 0x3FF ; read factory oscillator calibration value
movwf OSCCAL ; write to OSCCAL register
; If using a 12F629/675 this value must be present
; and correct, or the code will not function properly
; if it functions at all.
ENDIF

coloque ; em tudo.
experiente entrar com valor .255 para todos os timer e veja o resultado.

Se não mudou nada, essa deve ser a razão.
O oscilador interno é de 4Mhz, 1uS por ciclo. Talvez esteja rápido.
Altere as rotinas de tempo, se for o caso.
RobL
Dword
 
Mensagens: 1546
Registrado em: 20 Fev 2007 17:56

Mensagempor RobL » 23 Mai 2007 19:37

Sem dúvida o máximo tempo está em torno de 100ms com 4Mhz de clock.
O problema é esse.
Mude nas rotinas de tempo _Dlay para _LDelay conforme está recomendado abaixo "; change _Delay above to _LDelay for delay with 100mS intervals"

_outDelay1 movlw delay1 ; load W with 5 (0 => W <= 255)
addlw .0 ; add 0 to test for 0
skpz ; Don't call Delay if W=0 (0ms)
call _Delay ; call 1mS delay function
; change _Delay above to _LDelay for delay with 100mS intervals

bsf GPIO,out1 ; set output 1 high

Nota : não é necessário alterar o pgm onde sugerí anteriormente. Mas antes teste sem alterar o valor do OSCCAL.
RobL
Dword
 
Mensagens: 1546
Registrado em: 20 Fev 2007 17:56

Mensagempor Hermann Rocha » 24 Mai 2007 13:00

Ola Robl, vou fazer os testes conforme voce indicou ok, estou usando o 16f629 mesmo, obrigado pela dica
Hermann Rocha
Nibble
 
Mensagens: 59
Registrado em: 09 Fev 2007 20:47

Mensagempor Hermann Rocha » 26 Mai 2007 17:33

Ola Robl, você esta certo,depois que você indicou o lugar achei o texto que indica onde mudar. Agradeço a atenção e ajuda


The four delay periods are set by constants at lines 74-77 of the ASM file.

Each of the four delays can be set to multiples of 1mS or 100mS. To do this you will need to edit the .ASM file at the following lines. You can have a mix of 1ms and 100mS delays depending on your requirement.

Delay1 edit line 137
Delay2 edit line 148
Delay3 edit line 159
Delay4 edit line 170
The download ASM file is set for 1mS delays. To use 100mS delays, edit the call changing _Delay to _LDelay then reassemble the file.

call _Delay ; call 1mS delay function
; change _Delay above to _LDelay for delay with 100mS intervals
Hermann Rocha
Nibble
 
Mensagens: 59
Registrado em: 09 Fev 2007 20:47


Voltar para PIC

Quem está online

Usuários navegando neste fórum: Bing [Bot] e 1 visitante

x