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 sheetit tells how to define the timer but not how to use it, as far as i can comprehend.
Bookmarks