![]() | ![]() | ![]() |
| | |||||||
| Notices |
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink (permalink)) |
| Hi... I build timer circuit (long time delay)... i'm using PIC16F84A...that have 3 outputs represent the range of time delay...(short,med,long).. short 5 minute, med 15 minutes, long 30 minutes...i found 4060 can provided this time delay... the thing is how do i connect this two ic so that my switch, will switch at the right time delay... or there any idea how to make the time delay circuit?.. | |
| | |
| | (permalink (permalink)) | |||
| Quote:
Quote:
Quote:
Code: ; Delay = 300 seconds ; Clock frequency = 4 MHz ; Actual delay = 300 seconds = 300000000 cycles ; Error = 0 % cblock d1 d2 d3 d4 endc ;299999995 cycles movlw 0x54 movwf d1 movlw 0xA1 movwf d2 movlw 0xFD movwf d3 movlw 0x02 movwf d4 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto $+2 decfsz d4, f goto Delay_0 ;5 cycles goto $+1 goto $+1 nop | ||||
| | |
| | (permalink (permalink)) |
| thanks a lot Nigel... ok... for the time delay...can i use RETLW to call my subroutine? which is retlw 5minutes retlw 15minutes retlw 30minutes.... and so on... actually i do develop lookup table which have 64 values (size)i.e. 6 bits inputs... i want my PIC have a time delay for the given inputs (6 bits)... instead of using retlw (if can)...is there any alternative way to put my pic working as using retlw... thank you.. | |
| | |
| | (permalink (permalink)) | ||
| Quote:
call 5minutes call 15 minutes etc. RETLW is used at the end of the subroutine to return from where it came, you can use either RETURN or RETLW (only RETLW on 12 bit cores), RETLW returns a value in the W register. Quote:
For your purpose I would suggest a lookup table, use the returned value in a loop which calls a short delay the required number of times. If you look in my tutorials most of them have a looped delay routine like this, just not using a lookup table. | |||
| | |
| | (permalink (permalink)) | |
| thanks nigel.. ok... looks like i can't use the retlw to call my subroutine.. Quote:
Code: ;***** VARIABLE DEFINITIONS
STATUS EQU 03h ; variable used for context saving
TRISA EQU 85h ; variable used for context saving
PORTA EQU 05H
TRISB EQU 86h
PORTB EQU 06h
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
main bsf STATUS,5 ; bank 0 -----> bank 1
movlw b'00000000' ; set the port a as outputs
movwf TRISA ;
movlw b'00111111' ; set the port b as inputs
movwf TRISB
bcf STATUS,5 ; bank 1 -----> bank 0
read movf PORTB,w ; read input from port B
andlw b'00111111' ; mask of bits
call table ; refer to table, compare with inputs
movwf PORTA ; write to outputs
goto read ; re-read the status of inputs
table addwf PCL,f ; inputs outputs
retlw b'0001' ; 0 off
retlw b'0001' ; 1 off
retlw b'0001' ; 2 off
retlw b'0001' ; 3 off
retlw b'0001' ; 4 off
retlw b'0001' ; 5 off
retlw b'0001' ; 6 off
retlw b'0001' ; 7 off
retlw b'0001' ; 8 off
retlw b'0001' ; 9 off
retlw b'0001' ; 10 off
retlw b'0001' ; 11 off
retlw b'0001' ; 12 off
retlw b'0001' ; 13 off
retlw b'0001' ; 14 off
retlw b'0001' ; 15 off
retlw b'0001' ; 16 off
retlw b'0001' ; 17 off
retlw b'0001' ; 18 off
retlw b'0001' ; 19 off
retlw b'0010' ; 20 low
retlw b'0010' ; 21 low
retlw b'0010' ; 22 low
retlw b'0010' ; 23 low
retlw b'0001' ; 24 off
retlw b'0001' ; 25 off
retlw b'0001' ; 26 off
retlw b'0001' ; 27 off
retlw b'0100' ; 28 med
retlw b'0100' ; 26 med
retlw b'0100' ; 30 med
retlw b'0100' ; 31 med
retlw b'0100' ; 32 med
retlw b'0100' ; 33 med
retlw b'0100' ; 34 med
retlw b'1000' ; 35 high
retlw b'1000' ; 36 high
retlw b'1000' ; 37 high
retlw b'1000' ; 38 high
retlw b'1000' ; 39 high
retlw b'0100' ; 40 med
retlw b'0100' ; 41 med
retlw b'0100' ; 42 med
retlw b'0100' ; 43 med
retlw b'0100' ; 44 med
retlw b'1000' ; 45 high
retlw b'1000' ; 46 high
retlw b'1000' ; 47 high
retlw b'0100' ; 48 med
retlw b'0100' ; 49 med
retlw b'0100' ; 50 med
retlw b'1000' ; 51 high
retlw b'1000' ; 52 high
retlw b'1000' ; 53 high
retlw b'1000' ; 54 high
retlw b'1000' ; 55 high
retlw b'0100' ; 56 med
retlw b'0100' ; 57 med
retlw b'0100' ; 58 med
retlw b'1000' ; 59 high
retlw b'1000' ; 60 high
retlw b'1000' ; 61 high
retlw b'1000' ; 62 high
retlw b'1000' ; 63 high
END ; directive 'end of program' Code: retlw b'0001' ; 0 off Code: goto ShortDel off - short delay low - 5 minutes delay med - 15 minutes delay high - 30 minutes delay if possible, i'll have an array (table) of GOTO intruction as RETLW in my previous code...am i right?.. if not...how do i handle this thing since my PIC have 64 possibilities inputs? to give approriate outputs...(time range delay, 5,15,30 minutes) thanks | ||
| | |
| | (permalink (permalink)) |
| You simply need to call a routine which delays a certain time, multiplied by the value of W. So if the delay time is 1 second, calling it with 1 in W delays 1 second, calling it with 64 would delay 64 seconds. You can modify your routine like this. Code: read movf PORTB,w ; read input from port B
andlw b'00111111' ; mask of bits
call table ; refer to table, compare with inputs
call DelayW ; delay W number of times
movwf PORTA ; write to outputs
goto read ; re-read the status of inputs Code: DelayW movwf count1 d1 movlw 0xC7 ;delay 1mS movwf counta movlw 0x01 movwf countb Delay_0 decfsz counta, f goto $+2 decfsz countb, f goto Delay_0 decfsz count1 ,f goto d1 retlw 0x00 | |
| | |
| | (permalink (permalink)) | ||
| Quote:
if i'm going to put delay 5,15,30 minutes... Code: read movf PORTB,w ; read input from port B
andlw b'00111111' ; mask of bits
call table ; refer to table, compare with inputs
call Delay5 ; 5 minutes delay
movwf PORTA ; write to outputs
goto read ; re-read the status of inputs need more expalination.. Quote:
Code: table addwf PCL,f ; inputs outputs
retlw Delay5
retlw Delay10
retlw Delay5
: :
: :
retlw Delay30
retlw Delay5
retlw Delay5 Code: ; Delay = 300 seconds ; Clock frequency = 4 MHz ; Actual delay = 300 seconds = 300000000 cycles ; Error = 0 % cblock d1 d2 d3 d4 endc ;299999995 cycles movlw 0x54 movwf d1 movlw 0xA1 movwf d2 movlw 0xFD movwf d3 movlw 0x02 movwf d4 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto $+2 decfsz d4, f goto Delay_0 ;5 cycles goto $+1 goto $+1 nop thanks[/quote] | |||
| | |
| | (permalink (permalink)) |
| If all you need is three preset delays you could always use three totally seperate delay routines, or (like I suggested above) a single routine which you call multiple times. Here's a modified version of my DelayW routine from above using your 300 second delay routine: Code: ; Delay = 300 seconds
; Clock frequency = 4 MHz
; Actual delay = 300 seconds = 300000000 cycles
; Error = 0 %
cblock
d1
d2
d3
d4
count1
endc
DelayW movwf count1
Delay5
;299999995 cycles
movlw 0x54
movwf d1
movlw 0xA1
movwf d2
movlw 0xFD
movwf d3
movlw 0x02
movwf d4
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto $+2
decfsz d4, f
goto Delay_0
;5 cycles
goto $+1
goto $+1
nop
decfsz count1 ,f
goto Delay5
retlw 0x00 It's simply a loop encapsulating the delay routine, W is transferred to count1, this is decremented after the 5 minute delay and the delay routine repeated, once it reaches zero the routine returns. Because the delay is 5 minutes, that's your resolution, if you made the delay 1 minute you would have 1 minute resolution, and a maximum delay time of 255 minutes. | |
| | |
| | (permalink (permalink)) | |
| Quote:
about the table...i still do not understand how it will work for this time delay..how do i put value in my table?...how about this.. Code: table addwf PCL,f
retlw 1 ; 5 minutes delay
retlw 2 ; 10 minutes delay
retlw 3 ; 30 minutes delay
: :
: :
retlw 3
retlw 3
retlw 1 if i'm going to have 3 preset delay...which mean i'll have three subroutine for 5, 15, & 30 minutes, how does my table will looks like..? it's possible to do like this?.. Code: table addwf PCL,f
retlw Delay5
retlw Delay10
retlw Delay5
: :
: :
retlw Delay30
retlw Delay5
retlw Delay5 | ||
| | |
| | (permalink (permalink)) |
| thanks a lot Nigel...you help me alot... i do understand to implement 'variable' time delay...by using 1 subroutine i can have up to 255 time delay (for my case), just modify my 'multiply' valeu in my table... let say...for the given input, my pic will ON for 5 minutes, and for another inputs, my pic will OFF for 15 minutes...how do i modified my table...using modified code given?.. maybe i can have 2 preset delay ...1 for on ...1 for off...what do you think?.. thanks | |
| | |
| | (permalink (permalink)) | |
| Quote:
Code: call TurnON movlw 1 ;set 5 minute delay call table call DelayW call TurnOFF movlw 3 ;set 15 minute delay call DelayW goto Main ;loop back to main loop | ||
| | |
| | (permalink (permalink)) |
| My system have 6 inputs and 1 output (on-off) …variable time delays. My pic have the 64 possibilities input value which produce 6 or more type of output that is time delay for ON (5,15,30 minutes) and also time delay for OFF (5,15,30 minutes). For input range (possibilities value) 0-32 …my pic will OFF with certain period (5,15,30 minutes) and 33-63 it will ON (5,15,30 minutes) . My program flow will be like this:-- then for the read routine : Code: read movf PORTB,w ; read input from port B andlw b'00111111' ; mask of bits call table ; refer to table, compare with inputs call DelayW ; delay W number of times Code: table addwf PCL,f
retlw 1 ; 5 minutes delay, off
retlw 2 ; 10 minutes delay, off
retlw 3 ; 15 minutes delay,
: :
: :
retlw 6 ; ON for 30 minutes
retlw 3 ; ON for 15 minutes
retlw 1 ; ON for 5 minutes For the time delay… Code: ; Delay = 300 seconds ; Clock frequency = 4 MHz ; Actual delay = 300 seconds = 300000000 cycles ; Error = 0 % cblock d1 d2 d3 d4 count1 endc DelayW movwf count1 Delay5 ;299999995 cycles movlw 0x54 movwf d1 movlw 0xA1 movwf d2 movlw 0xFD movwf d3 movlw 0x02 movwf d4 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto $+2 decfsz d3, f goto $+2 decfsz d4, f goto Delay_0 ;5 cycles goto $+1 goto $+1 nop decfsz count1 ,f goto Delay5 retlw 0x00 | |
| | |