A quick way...


Closed Thread
Results 1 to 6 of 6

Thread: A quick way...

  1. #1
    Join Date
    Jul 2009
    Posts
    13

    Default A quick way...

    I am using the following code to detect when a pulse arrives at a pin:

    Wt:
    IF fin = 0 then Wt

    It works well, since the pulse is only a couple of micro seconds long and I am running at 4 MHz, but I also need the routine to timeout after about half a second. I tried using PulsIn, but it does not detect the pulse. I though may be using TMR0 and an interrupt coded in assembler could make this loop exit, but my expertise in assembler are very (extremely) limited.
    Do any of you have an idea?

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Tray and see if this works:

    Code:
    Wt:
    W0=0
    While fin = 0
    W0=W0+1
    pause 1
    If W0> 500 then goto TimeOut
    Wend
    Al.
    All progress began with an idea

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


    Did you find this post helpful? Yes | No

    Default

    If it is a very short Pulse (a few uS), you might miss it's arrival during the 1mS Pause statement.

    If you can route your pulse into say RB0, then rather than polling the pin, you can poll the INTF bit (not knowing your PIC I'm using the registers from a 16F628 as an example). This bit will SET and stay SET when your pulse arrives. So if you blink and miss the pulse because you were doing something else, the Flag tells you it's happened.

    Don't worry, the software doesn't actually need to vector to any Interrupt routine, once set up (eg INTEDG=1, INTE=1, GIE=0) you can just poll the INTF flag (rather than the pin) as per Al's example.

    Don't forget, it's your job to reset the INTF flag ready for the next event.

  4. #4
    Join Date
    Jul 2009
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    That sounds perfect, since the pulse could be a short as 2 uS. I am using a PIC12F509 and if you could please give me an example for this one I will really apreciate it...
    By the way, what I need is to toggle pin GPIO.2 from 1 to 0 when this pulse arives in GPIO.1 and this should be as fast as possible, since the actual 1 to 0 edge is used to measure distance.
    Last edited by aherrera; - 27th November 2009 at 23:50.

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


    Did you find this post helpful? Yes | No

    Default

    Then really neither of the above replies are suitable.

    This is because whilst you are away doing something, (for example the PAUSE instruction), you are not looking for the event in order to trigger your Output IMMEDIATELY. Even with my suggested modification, you won't miss the pulse, BUT you'll only do something about it some time later - and that time could be delayed by anything up to 1mS.

    You would need something like Darrel's INSTANT INTERRUPTS - but NOT to Poll the input pin, but to give you your Timeout. If setting your Output pin relative to the Input trigger is so critical, then I would even consider if a PIC is the suitable device - you could do it quicker with discrete logic.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Question

    Hi, Aherra

    Which distance measurement do you want to do ???

    sound in air, in water, light ???

    2µs looks a VERY very very short - or long ( ! ) period for those ...

    Alain

    PS : http://pagesperso-orange.fr/atexa_el...ason/radar.htm
    Last edited by Acetronics2; - 28th November 2009 at 09:58.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Quick n dirty HPWM out of phase
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 17th August 2014, 05:29
  2. Quick DS18B20 question
    By gti_uk in forum General
    Replies: 4
    Last Post: - 21st June 2009, 17:24
  3. Quick USB CRC5 question
    By Michael Wakileh in forum USB
    Replies: 2
    Last Post: - 12th June 2009, 04:23
  4. Two quick (and elementary) questions.
    By scorpion990 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th June 2008, 23:03
  5. Interrupt Quick Question
    By shawn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2005, 05:51

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