PDA

View Full Version : timer interupt help 16f73



EDWARD
- 28th June 2005, 20:44
i was wondering if anyone out there could help me out with using a timer in my program. are there any resources out there that will give me some basics on timer interupts and how to use them. i cant seem to find any examples in picbasic language on how to define the interupt and more importanty how to utilize it. as of now i have my own nested timer with a 1 ms pause:

X =X +1
pause 1

if X > 1000 then
X = 0
Z = Z + 1
endif

'Z basically holds the numbers of seconds

this works just fine but i would like to eliminate the 1 ms pause. from what i have read so far the tmr interupts allows for a "multi tasking" type abilty. where the counter keeps on counting regaurdless of the programming running. for example the tmr will continue to count even if i am in the middle of a pause 5000 command or similar. am i correct in this thinking?

my goal here is to have an output pin going high to low at a rapid pace, as long as an input pin is countues to go high to low at a much slower rate. the simplest way in my mind for this to happen is to have the program run a chunk of code as long as the intcon.1=1 at least once every second.

suedo:

some event to put z = 1 to start loop

start timer to count to 1 second

while z = 1
if intcon.1 =1 and timer is below 1 second 'intcon.1 is portb.0 rising edge intrpt
let z = 1

do code here

wend

this code is a firing sequence for an electro pnumatic airsoft gun. the idea is this. the gun fires in semi auot mode normally, meaning if i pull and HOLD the trigger only one shot will fire. now heres where things get complex.

there is another firing mode called ramping. and it is not quite semi auto and not quite fully auto. heres how it works. as long as i pull the trigger once every 500ms the gun will shoot at a rate determind in my program. to make the gun shoot all i need to do is this:

simple firing sequnce (semi auto ONLY in this example) just to give an idea.

if intcon.1 =1 then 'if trigger is pulled( portb.0 rising edge)
let intcon.1 = 0 'reset intcon.1
high portb.5 'turn on solenoid
pause FT ' FT is the time the bolt stays foward about 2ms to 20ms
low portb.5 'turn off solenoid
pause BT ' BT is the time the bolt has to stay back for about 30ms to 70ms
endif

so its basicallt fullauto aslong as i update the portb.0 pin once every 500 ms.

the rate of fire is determined my the BT value.

the pauses in the FT and BT causes my custom timer to be thrown off, which i knew wuld happen but only way i can get it to work. yes i read the data sheet :) it tells how to define the timer but not how to use it, as far as i can comprehend.

Dwayne
- 28th June 2005, 20:54
Hello Edward...

I took a quick look, Maybe this could help you:

http://www.picbasic.co.uk/forum/showthread.php?t=790&highlight=Fire

One thing to remember... in PBP, if you are in a PAUSE 5000, and a interupt is triggered... It will NOT be triggered (subroutine called) until the PAUSE 5000 is over with.

If you want "instant" triggering (subroutine called), you have to use a ASM Subroutine.


Dwayne

mister_e
- 28th June 2005, 23:25
Do delay LOOP with PAUSEUS will fix the problem. Let's assume a loop of 5uSec.... not bad. No need to use Assembler interrupt as it's not as this timing critical.

I hope you don't try to modify a DM4, DM5 or DMC if so, stay away from me in future PaintBall battle... ;o]

EDWARD
- 29th June 2005, 06:26
wow mister e u are on the money. i didnt know if people would relate to paintball more over then airsoft, being that airsoft is a little more international. in fact i use a Bob Long intimidator ;) although the dm4, 5 are superior markers. kinda kool that someone in here has heard of paintball and even knows a little somehting about it. well i just got online so i havent tried any of those ideas out yet, but that is a good idea on using the pauseus (pause in micros and not milli) i forgot about that command. ill also check out that link that dwayne was kind enough to add. i dont think that it will be a problem if it occurs during a pause command because 1 or 2 extra shots is acceptable. thanks guys for taking the time to read that long post, i had a lot of trouble try to spit it all out. im gonna try the interpt approch first. ill keep ya updated. thanks

EDWARD
- 3rd July 2005, 07:16
I am still having trouble understanding the timer interupt on the 16f73 and how to use it. whatvariable holds the value for the timer? basically i think all i need is something as simple as this follow psuedo code idea.

while tmr0 is less then 500ms 'tmr0 counts in the background regaurless of pauses.
gosub ramp
if trigger pulled reset tmr0
wend

Melanie
- 3rd July 2005, 08:41
Have a look at this thread... it shows how a PICs timers work and gives an interrupt example... may not be exactly what you need, but it's intended as a starting point for interrupts and timers.

http://www.picbasic.co.uk/forum/showthread.php?t=632