2 interupts - portb.0 rising and falling edges


Closed Thread
Results 1 to 8 of 8
  1. #1
    EDWARD's Avatar
    EDWARD Guest

    Default 2 interupts - portb.0 rising and falling edges

    pic 16f73

    portb.0


    is it possible to switch between rising and falling edges interupt. both within the same loop

    loop:

    if risingedge then mysub

    if falling edge then mysub

    goto loop




    if i try

    OPTION_REG.6 = 1 ' rising edge
    INTCON.4 = 1 'enable int <--not sure if necessry
    INTCON.1 = 0 ' reset the interruptflag

    loop:

    'OPTION_REG.6 = 1 'rising edge
    'INTCON.1 = 0 ' reset the interruptflag

    IF INTCON.1 = 1 THEN
    INTCON.1 = 0 ' reset the interruptflag
    gosub fire
    endif

    'OPTION_REG.6 = 0 ' falling edge
    'INTCON.1 = 0 ' reset the interruptflag

    IF INTCON.1 = 1 THEN
    INTCON.1 = 0 ' reset the interruptflag
    gosub fire
    endif

    goto loop

    it wont work
    Last edited by EDWARD; - 8th July 2005 at 03:17.

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    It would be better to use RB4, 5, 6 or 7, theese pins have the "interrupt on change" feature. That means it will interrupt every time your pin changes state. If you need to know if it were a high-to-low or low-to-high transition, you need to manually check that in your ISR.

  3. #3
    EDWARD's Avatar
    EDWARD Guest


    Did you find this post helpful? Yes | No

    Default thanks

    that is exactly what i need. an " interupt on change" but HAVE to use portb.0. can you think if any other way?

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If you're just going to be sitting in a loop waiting for an interrupt to happen, you might as well poll the state of your input pin. Your code is flawed. I see no ON INTERRUPT statement, no RESUME and no logical path to follow. But if you simply need an answer "Can I change the state of the Interrupt Trigger from High to Low, or Low to High dynamically within my program", then the answer is Yes - absolutely.

    A lot of folks seem to want to use interrupts simply because they "think" that's the way to go or seen other talk about it for a similar application. Not so. If you have a Keyboard Button Push, or even a Trigger on a Paintball or Laser gun, as long as your PIC isn't in SLEEP mode and you can poll the event within say 50mS for a trigger, or 100mS for a Keyboard Button, then nobody is going to be any the wiser. You don't need 1uS reaction time in 99.9% of applications.

  5. #5
    EDWARD's Avatar
    EDWARD Guest


    Did you find this post helpful? Yes | No

    Default thanks for the reply

    sorry that wasnt my whole program, just an idea of how it was stuctured.

    well time is actually very critical as the paintball marker can fire 35+ balls per second. my program is very long ( just under 4k) because i had to create my own lcd subroutines. when i use the on interupt command, my program becomes very large. i try using the enable and disable commands so that only the top 2 subs are enabled and every thing below is is disabled to intertupt.
    i need it to work on edges becuase if i do something like:

    loop:
    if portb.0 = 1 then
    gosub fire
    endif
    goto loop


    the paintball marker will fire in full auto. i could correct this using a variable to hold the state but i was thinking that the interupts would be better.

    i now have 2 loops. with out getting to involved, 1 loop is for rising edges, 1 loop is for falling edges. and when the condiotion is met to switch loops, it change the option_reg.6 from 1 to 0.

    but,for some wierd (but benifitial to me) reason, when i set the option_reg.6 = 0 it will read both rising and falling tansitions, instead of just falling. which is exacly what i needed.

    i need about 1ms reaction time max for my application. my prject is very complex the way it works. my goal is not to make a paintball gun just fire. it is to make it functin a very very specific way. a requirement that is in the tournement handbook.
    Last edited by EDWARD; - 8th July 2005 at 22:55.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    For that purpose, you'll never need interrupt.. i seconf the Melanie's idea of a somple loop. Kinda KISS programming wich is often welcome.

    Quote Originally Posted by EDWARD
    my goal is not to make a paintball gun just fire. it is to make it functin a very very specific way. a requirement that is in the tournement handbook.
    and.. ilegal in many coutry. well in Canada, we can modify our guns BUT we can't use them in real tournament as they don't meet the normal rules. Yeah i play sometime Paintball. I have a DM4, DM5 and since few weeks a DMC.

    But by your question, you can do something like the following pseudo
    Code:
    If Fire=1 then
         Pulsout Solenoid ' rising edge
         While Fire=1
         Wend
         Pulsout Solenoid ' falling edge
         endif
    Be carefulll your loader should have time enough to place those cute ball prior to shoot them. I hope your aware of hat... case else... what a great mess of paint you'll do. And for sure, few minutes/hours of happy cleaning
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    >> 35+ balls per second...

    Now if ever there was a phrase in a thread that could get my attention...

  8. #8
    EDWARD's Avatar
    EDWARD Guest


    Did you find this post helpful? Yes | No

    Default sry to get back so late.

    thank you for the replys.

    just so theres no worries, i am not doing anything illegal guys. the program i am writing is to update the marker to the 2005 rule book or tournemant paintball here in the USA. although the marker can fire as fast as the hopper can feed (35+ BPS), but it is also adjustable to set at 15 Balls Per Second. I just need some help on getting the 15 balls per second mode better.


    i know that there are many ways to do this, which i have done succesfully but my problem is 2 things: consistancy and "real time control".

    ---the consistancy problem is that i need the marker to fire at a very constant rate, even if the input (actual trigger) is not consistant.

    ---the so called "real time control" problem is that i need the marker to stop firing almost instantly as i stop pulling the trigger. 1 to 2 balls fired after i stop pulling the trigger is the MAX.


    although the marker can fire at a very high rate of fire, all i need is it to work at 15 balls per second (BPS). the trigger needs to be pulled at least 3 times a second for the marker to shoot 15 BPS, but needs to stop alsmost instantly. now do you see why this is a little more complex



    At first i just had a 5 shot burst and if the trigger was pulled before all 5 shots were fired, it would ADD to the number of bursts left. this made for a very consistant fire but would shoot 5 balls after i stopped pulling the trigger not good. if i lowered the 5 to a 2 it required pulling the trigger to fast, but only shot 2 balls after releasing.

    so i had to get creative and utilze the release of the trigger. so now it set to 2 shot burst and ADDs 2 shoots everytime the trigger is pulled or released. this makes for for 4 shots a pull but i need 5. (15 BPS)/(3 pulls per sec) = 5 Balls per pull.

    i was am not wondering if i can use a pulse counting interupt. and if the frequency of pulses goes below 3 per sec it will stop firing. could this be done to stop firing the marker instantly? or would it continue to shoot a few more balls?


    oh yeah i forgot to say that i have all the other stuff figred out already, like the timing of the pnumatics required and the optical sesor delay, custom debouncing, and things of that nature. i was at the field a few days ago shooting 26 BPS of the chrono i need new batteries in my halo i think. also i havnt CHOPPED\BUSTED a ball since i got my eye logic down and i shot over 5 cases through it (10,000 paintballs)
    Last edited by EDWARD; - 15th July 2005 at 01:16.

Similar Threads

  1. Interrupt On both (Rising and Falling)
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 12th March 2008, 14:34

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts