PDA

View Full Version : onof timer



andrewwaack
- 4th July 2007, 23:13
can any one help i need to turn on 1 pin of a pic16f84a for 3 min then off for 3 min repeted for 15 mins then off for 45 min here is the code i have tryed
i use microcode studio and pic basic pro

'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 7/2/2007 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
b0 var byte
b1 var byte
b2 var byte
trisb.1 = 0
seqsta:
b0 = 1
b1 = 0
portb.1 = b0
sleep 180
if b2 = 3 then slep
for b2 = 0 to 3
b1 = b0 * 2
b0 = b1
portb.1 = b0
sleep 180
next b2
slep:
sleep 2700
goto seqsta

any help with this would be much apprecated

skimask
- 5th July 2007, 03:28
can any one help i need to turn on 1 pin of a pic16f84a for 3 min then off for 3 min repeted for 15 mins then off for 45 min here is the code i have tryed
i use microcode studio and pic basic pro
Looks to me like you might be over-thinking the problem just a bit...

Assuming portb.0 is the pin you want to turn on and off...

main:
high portb.0
sleep 180 '3 minutes
low portb.0
sleep 180 '6 minutes
high portb.0
sleep 180 '9 minutes
low portb.0
sleep 180 '12 minutes
high portb.1
sleep 180 '15 minutes
low portb.0
sleep 2700 '45 minutes
goto main

or in 'skimask format' :)
x var portb.0 : output x : x = 0
main: x=1:sleep 180:x=0:sleep 180:x=1:sleep 180:x=0:skeep 180:x=1:sleep 180:x=0:sleep 2700:goto main
end

andrewwaack
- 5th July 2007, 05:19
thanks for your rapid responce if you have any more sugestions for this problem it would be great



thanks andrew

andrewwaack
- 5th July 2007, 07:46
is there a way of making this code more accurate


main:
high portb.0
sleep 190 '3 minutes
low portb.0
sleep 190 '6 minutes
high portb.0
sleep 190 '9 minutes
low portb.0
sleep 190 '12 minutes
high portb.0
sleep 190 '15 minutes
low portb.0
sleep 2700 '45 minutes
goto main



thanks andrew

Ioannis
- 5th July 2007, 09:06
Without a timer chip? I guess not. The example by skimask is based on the watchdog of the PIC, which is innacurate by itself very much (look at 5.77 of the manual).

Another option might be the elapsed timer by Darrel Taylors Instant Interrupts. But, maybe too complicated for what you want.

Ioannis

skimask
- 5th July 2007, 15:33
is there a way of making this code more accurate

Learn how to use the TIMER interrupts...
Put the PIC to sleep using the sleep instruction, let the TIMER interrupt wake up the PIC, increment a counter to keep track of elapsed seconds/milliseconds/minutes/hours/whatevever, take whatever action is neccessary based on elasped time, put the PIC back to sleep.

Pic_User
- 5th July 2007, 16:30
is there a way of making this code more accurate thanks andrew
Hi Andrew,

Ski and Ioannis are right. Search the forum.

Take a look at Darrel’s Elapsed Timer Demo
http://www.picbasic.co.uk/forum/showthread.php?t=190
There is a lot of information, but you may be able to use the parts needed for your project.

How accurate does it have to be? Tell us something about the project.
-Adam-