2 interupts - portb.0 rising and falling edges


Closed Thread
Results 1 to 8 of 8

Hybrid View

  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.

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 : 0

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