Better understanding PULSIN


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    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.

  2. #2
    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

  3. #3
    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 " !!!
    *****************************************

  4. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default ... little more help needed

    Hello Alain,

    This is an example of a 13-bit IR pattern I measure on a TSOP4838 receiver module.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2701&stc=1&d=121464754 0">

    At the start, my prog captures the incoming pattern sent continiously until it determines the starting-bit (first one after the pause between two patterns) and the number of bits (Bit-Count) in the pattern.

    I try with this code:
    Code:
    for Ctr_A = 0 to bit_count
       rctime p_in, 0, h_Bit[Ctr_A]
       rctime p_in, 1, l_Bit[Ctr_A]
    next Ctr_A
    
    ' Results are:
    Bit 00  Low  :13795
        00  High :350
    Bit 01  Low  :244
        01  High :1253
    Bit 02  Low  :244
        02  High :349
    Bit 03  Low  :243
        03  High :350
    Bit 04  Low  :244
        04  High :350
    Bit 05  Low  :244
        05  High :349
    Bit 06  Low  :244
        06  High :349
    Bit 07  Low  :243
        07  High :350
    Bit 08  Low  :75
        08  High :1
    Bit 09  Low  :244
        09  High :650
    Bit 10  Low  :243
        10  High :350
    Bit 11  Low  :244
        11  High :350
    Bit 12  Low  :244
        12  High :349
    This is the code (works fine) I use currently use @ 20MHz and the data I get with PULSIN is:
    Code:
    for Ctr_A = 0 to bit_count
       pulsin p_in, 0, L_Bit[Ctr_A]
    next Ctr_A
    for Ctr_A = 0 to bit_count
       pulsin p_in, 1, H_Bit[Ctr_A]
    next Ctr_A
    
    ' Resuts are:
    Bit 00  Low  :1258 'to be multiplied by 2µs (PULSIN res @ 20MHz)
        00  High :247
    Bit 01  Low  :354
        01  High :247
    Bit 02  Low  :354
        02  High :247
    Bit 03  Low  :355
        03  High :247
    Bit 04  Low  :354
        04  High :247
    Bit 05  Low  :354
        05  High :247
    Bit 06  Low  :354
        06  High :247
    Bit 07  Low  :354
        07  High :247
    Bit 08  Low  :655
        08  High :247
    Bit 09  Low  :354
        09  High :247
    Bit 10  Low  :355
        10  High :247
    Bit 11  Low  :355
        11  High :247
    Bit 12  Low  :354
        12  High :13797
    According to your previous message, I might raise the timings accuracy with RCTIME instead of using PULSIN. Unfortunately, I can't get it to work using RCTIME.

    What am I doing wrong, please?
    Attached Images Attached Images  
    Roger

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


    Did you find this post helpful? Yes | No

    Wink ...

    Hi, Roger

    What I see is you should use 1 time Pulsin ( for the leading pulse) and RCTime for all other pulses ...

    AND there's a gentle Mix between H_Bit ( 0 State ) and L_Bit ( 1 state ) ... but may be you did it to match the inverted signal ... ???


    should be :

    Code:
       PULSIN  p_in, 0, l_Bit[0]           ' measure neg leading pulse
       RCTIME p_in, 1, h_Bit[0]          ' measure time staying High
    
    for Ctr_A = 1 to ( bit_count -1 )
    
       rctime p_in, 0, l_Bit[Ctr_A]        ' measure time staying Low
       rctime p_in, 1, h_Bit[Ctr_A]       ' measure time staying High
    
    next Ctr_A
    
       RCTIME p_in, 0, l_bit[bit_count] ' measure time staying Low
    "it's been a hard days night ... And I'm working like a dog ..." as told the Beatles !

    Regards
    Alain
    ************************************************** ***********************
    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 " !!!
    *****************************************

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default

    Thanks Alain,

    I saw the leading PULSIN command in your previous post and tried this already. The result is the same as without PUSLIN but bits are shifted (not important at that time since the bits are sorted lateron).

    But why should the preference go for a PULSIN command first?

    I notice while using RCTIME, the measurements give slightly lower results (i.e. PULSIN = 355, RCTIME = 349) which looks good.

    Any idea why I get a result of 0 or 1 at bit 8 (sometimes bit 7)?

    NB: thank you for noticing the variable mix - I corrected already.
    Roger

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


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    But why should the preference go for a PULSIN command first?
    ... just to be sure to catch the first pulse ... RCTime is somewhat "out of normal use" for the leading pulse ... result is not guaranteed !!!


    Any idea why I get a result of 0 or 1 at bit 8 (sometimes bit 7)?
    your scoping looks strange ... just at bit 8 !!! ... try to raise the TSOP decoupling caps value and to place a ~ 50 - 100 pF as load to the TSOP output - that could catch possible ns glitches ...

    Also take care to have neat 0-5 v levels : the pic Thresold is @ ~1.5 v for TTL inputs ... and Schmitt trigger needs "good" levels ...

    Have a nice evening

    Alain
    Last edited by Acetronics2; - 28th June 2008 at 19:46.
    ************************************************** ***********************
    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 : 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