pulsin: how is it used


Results 1 to 15 of 15

Threaded View

  1. #8
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If the pin is already in the the state of the defined "pulse", it starts counting as soon as PULSIN is called and stops counting when the trailing edge is detected.
    Sorry, but I respectfully dissagree with this.

    Try this;
    Code:
        DEFINE OSC 20
        DEFINE LOADER_USED 1
    
        PTIME VAR WORD
        PTIME2 VAR WORD
        
        SYMBOL PIN_PIN = PORTB.0
        TRISB = %11111101 
        
        PTIME = 0
            
    MAIN:
        WHILE PIN_PIN = 0        ' wait for PIN_PIN to go high
        WEND
        
        HIGH 1 ' indicate PULSIN start
        PULSIN PIN_PIN,1,PTIME   ' this reads the pulse after the pin is already high
        LOW 1 ' indicate PULSIN complete
        
        PULSIN PIN_PIN,1,PTIME2  ' this reads it after the rising edge
        HSEROUT ["Pulse 1 width = ",DEC PTIME,13,10]   ' result = 0
        HSEROUT ["Pulse 2 width = ",DEC PTIME2,13,10]  ' result = 25419
        
        GOTO MAIN
    I have a 12F675 programmed to output a train of pulses. 50mS high with a low period of
    250mS between each high pulse.

    See the analyzer capture below. P1A is the pulse train being read with PULSIN. P1B is RB1
    going high just prior to the 1st PULSIN, and low when the 1st PULSIN completes.

    Look at the A & B markers. Now look at the time A-->B: 181.9mS. 50mS of this period is
    the 50mS pulse shown by P1A at the top. P1B is the high period RB1 stays high once the
    1st PULSIN executes. Subtract 50mS. The remainder is the time-out period at 20MHz.

    If PULSIN were not waiting for the leading edge, then it should always return the remainder
    of the high time period in PTIME, but it doesn't. It returns zero.

    Now if you shorten the low period between each high-going pulse to < the PULSIN time-out
    period, it will record the 2nd high-going pulse. Not the first if started when the pin is in
    the state to be measured
    .

    So, what I'm seeing is - PULSIN does need to see the leading edge. It will however appear
    to work, even if started after the leading edge, but will only record the time of the 2nd
    pulse - if it happens prior to the time-out period.

    I have tried several variations, and I just can't get any results if I start PULSIN after
    a leading-edge transition. Except for it locking onto & recording a 2nd pulse that happens
    before the time-out period expires.
    Attached Images Attached Images  
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Better understanding PULSIN
    By Wirecut in forum mel PIC BASIC
    Replies: 12
    Last Post: - 29th June 2008, 10:17
  2. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08:02
  3. Pulsin 16F819 problem
    By rekcahlaer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th April 2007, 13:52
  4. Pulsin to pulsout with up than 4MHZ crystal ?
    By RCtech in forum mel PIC BASIC
    Replies: 5
    Last Post: - 18th May 2006, 19:23
  5. PULSIN and RCTIME
    By Dwayne in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th November 2004, 14:45

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