Better understanding PULSIN


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Posts
    37

    Default Better understanding PULSIN

    I would better understand how work PULSIN statement.

    I'm using PULSIN of PICBASIC PRO rel 4.47 on a 16F877 at 20 Mhz for decode IR from remote, using Sony format.

    In order to better understand, I would track the timing of PULSIN using one free output pin to view with a scope the beging/end of the PULSIN duration with the following statement:


    for BitCount= 1 to 12
    High SData: pauseus 1: low SData ' Before pulsin, generate a pulse wiewable with an oscilloscope.
    pulsin IR_Sensor,0,IRpuls_len(BitCount)
    High SData: pauseus 1: low SData ' Before pulsin, generate a pulse wiewable with an oscilloscope.

    if IRpuls_len(BitCount) < 580 then
    Packet.0[BitCount-1]=0
    Else
    Packet.0[BitCount-1]=1
    endif
    next BitCount

    In my mind, I immagine that first there are an ON pulse as a witness of the PULSIN begin, then after 2,4 or 1,2 or 0,6 mS I should see the second ON pulse.

    Running it, never I see the ON pulse in continuos phase, with begin/end of PULSIN, but in a random position. Take note that the "IRpuls_len(x)" contain the correct value of the pulse lenght, 2,4 mS, 1,2 mS and 0,6 mS.

    Also working with DEFINE PULSIN_MAX with different value do not help to view the second pulse in timing with the end of PULSIN duration.

    Any comment or consideration is welcome.

    Ciao

    Leo

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The thing that might be giving you unexpected results is you are looking for the low state.
    Code:
    pulsin IR_Sensor,0,IRpuls_len(BitCount)
    Change the "0" to "1" to read the high pulse.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Hi mackrackit,

    the statement is correct, I read the "down" time of the signal, ad the value returned by PULSIN is correct and into the value that I aspect.

    I do not see the pulse in phase with PULSIN generate by this statement

    SData var PORTB.7 ' RB7 output pin for measurement pulse duration
    .....
    High SData: pauseus 1: low SDatapulse
    .....

    SData is aspected lengh one microsecond, and when is show have correct lenght, but non in phase with begin/end of PULSIN.

    Ciao

    Leo

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I am not quite getting it.

    You are talking about another VAR or CON (SDatapulse) that we do not know how it relates to everything else.

    Can you post all of your code?
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    Sorry for delay to upload the code.

    Also I have upload tree screenshot of a digital oscilloscope to better explain what happens.

    Channel B show the incomin IR signal and channel A should show with the pulse of SData/PORTB.1 the begin/end of PULSIN.

    You can see some missing SData/PORTB.1 pulse on the uploaded images, but belive me the IR code is correctly recognized of the incaming IR pulse duration and the array IRpuls_len(x) contain the correct pulse lenght.

    The uploaded program 16F877_IR_pulsin.zip works correctly, but leave me unsatisfied about the use of PULSIN.

    I will expect one pulse of SData/PORTB.1 at the begin of PULSIN and another pulse of SData/PORTB.1 at the end of the PULSIN statement, yust before the execution of the next statement, and no SData/PORTB.1 missing as you can see per attached images.

    Ciao

    Leo
    Attached Files Attached Files

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


    Did you find this post helpful? Yes | No

    Wink A Solution to measure following levels ...

    Hi, Wirecut

    Pulsin is a command that MUST wait for the leading edge ...

    so, if you want to measure, say a PWM signal, you're tempted to Write :

    PULSIN Input, 1, Hilev1
    PULSIN Input, 0, Lolev1
    ...

    ... Am I right ???

    But using Pulsin twice will do the Following :

    READ correctly the High level ...
    RESET it's detection mechanism ( some µs necessary !!! )
    WAIT for an incoming falling edge
    READ the Low level pulse
    RESET it's detection mechanism ( some µs necessary !!! )
    WAIT for an incoming rising edge
    READ the High level pulse


    then it doesn't see the falling edge for the 1st following Low level ( has happend some µs ago !!! )

    THEN it will wait for the NEXT falling edge ... wich is the SECOND low level state ...

    so, let's resume ...

    you read hi state 1, lo state 2, hi state 3, lo state 4

    INSTEAD of : hi state 1 , lo state 1, hi state 2, lo state 2 .... etc, etc

    TURNAROUND ...

    PULSIN Input, 1, Hilev1
    RCTIME Input, 0, Lolev1
    RCTIME Input, 1, Hilev2
    RCTIME Input, 0, Lolev2
    ...

    if using a 4Mhz clock, add 1 unit correction to RCTIME measured values

    if using a 20 Mhz clock, add 4 units to RCTIME Measured values

    And now, you'll get your values right !!! ... or very, very, very, very close, to be honest !!!

    Alain
    Last edited by Acetronics2; - 9th May 2008 at 12:47.
    ************************************************** ***********************
    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. Replies: 17
    Last Post: - 12th April 2014, 02:17
  2. pulsin: how is it used
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th October 2008, 00:11
  3. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08:02
  4. Pulsin 16F819 problem
    By rekcahlaer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th April 2007, 13:52
  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