pulsin sample time


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Question pulsin sample time

    Hi guys ,

    Pulsin command returns time measured of the pulse width with the resolution dependent on the real OSC speed ,

    but how long is the sample period before gives a result to variable , and how can that time frame be set within pulsin


    cheers

    Sheldon

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    Hi, Sheldon

    There's no sample period !

    just some µs @the beginning of the command to preset the trigger conditions, and some µs after the end of measure to check end of signal and transfer the result to the variable you've chosen.

    I must suppose your question was ... " which is the minimum period pulsin can measure " or " which is the maximum frequency for pulsin use "

    please try to explain better what you try or intend to do

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

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    just notice it takes a long time to get a sample , doing a pulsin sample serial of 32 bits ,arranging it to make a byte value , write to eprom if the byte data changes only ( 4 bytes) then go do the lot again , i did a debug cycle test , and it takes about 1 sec a loop which seem really long to me doing a sample at 4mhz i am playing with increasing the osc to 8mhz , which should help . but a way to stream line the code would be a better approach , just not sure how to do it

    GetIRcode:

    TRISIO = %00111111 ' setup input=1,output=0 GPIO.0 = 1 to input
    PULSIN GPIO.0,1,Leader ' get leader high pulse time value in on GPIO.0
    IF Leader < 400 tHEN return ' look for 4500us high pulse below 4000us then its 2nd key area pulse or data/ address bits
    IF Leader > 480 tHEN return ' above 4800us then it no sig

    FOR X = 0 TO 31 ' grab 32 incoming pulses
    PULSIN GPIO.0,1,BtnVal(X) ' now measuring high-going pulse widths
    NEXT X

    z = 0 ' Z points to start range of byte
    S = 7 ' S points to end range of byte
    X = 0 ' start X at 0 to line up with BtnVal array
    for Y = 1 to 4 ' Get in Array and decode 4 bytes from 32 bit pulses
    T = 7 ' Set T to 7 so that it puts BtnVal(0) in to D7 location
    FOR X = Z TO S ' sort 8 pulses of byte

    IF BtnVal[X] > 150 THEN ' > 150 x 10uS = > 1.5mS pulse period = 1
    DByteTmp = DByte[Y] ' get into temp var

    DByteTmp.0[T]=1 ' Set value to 0 or 1 , T reverses bit order of BtnVal(x) so byte has correct bin value to write byte
    ELSE
    DByteTmp.0[T]=0
    ENDIF

    DByte[Y] = DByteTmp ' get it back into DByte(y)
    T = T - 1 ' T points to next MSB on loop
    NEXT X

    Z = x ' Z = X (0,8,16,24) points to start of next byte
    S = 7 + X ' S (7,15,23,31) points to End of next DByte BtnVal offset to X
    next Y ' loop for 4 bytes


    ' only save code if it differnat to stored IR code

    for x = 1 to 4
    if DByte[x] <> STDByte[x] then
    wrITE x,DByte[x]
    endif
    next x

    Return

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    this be easier to read


    Code:
     GetIRcode:
         
         TRISIO        = %00111111     ' setup input=1,output=0 GPIO.0 = 1 to input 
         PULSIN GPIO.0,1,Leader        ' get leader high pulse time value in on GPIO.0   
        IF Leader < 400 tHEN return    ' look for 4500us high pulse  below 4000us  then its 2nd key area pulse  or data/ address bits
        IF Leader > 480 tHEN return    ' above 4800us  then it no sig
       
      FOR X = 0 TO 31                  ' grab 32 incoming pulses
          PULSIN GPIO.0,1,BtnVal(X)    ' now measuring high-going pulse widths
      NEXT X
          
          z = 0                            ' Z points to start range of byte 
          S = 7                            ' S points to end range of byte 
          X = 0                            ' start X at 0 to line up with BtnVal array
      for Y = 1 to 4                       ' Get in Array and decode 4 bytes from 32 bit pulses 
            T = 7                          ' Set T to 7 so that it puts BtnVal(0) in to D7 location  
            FOR X = Z TO S                 ' sort 8 pulses of byte
        
              IF BtnVal[X]  > 150 THEN     ' > 150 x 10uS = > 1.5mS pulse period = 1
                 DByteTmp = DByte[Y]       ' get into temp var
           
                  DByteTmp.0[T]=1          ' Set value to 0 or 1 , T reverses bit order of BtnVal(x) so byte has correct bin value to write byte 
                ELSE
                  DByteTmp.0[T]=0
               ENDIF
      
              DByte[Y] = DByteTmp           ' get it back into DByte(y)
              T = T - 1                     ' T points to next MSB on loop
            NEXT X
        
          Z = x                             ' Z = X (0,8,16,24) points to start of next byte
          S = 7 + X                         ' S  (7,15,23,31) points to End of next DByte BtnVal offset to X
      next Y                                ' loop for 4 bytes
     
      
       ' only save code if it differnat to stored IR code 
        
        for x = 1 to 4 
          if  DByte[x] <> STDByte[x] then 
              wrITE x,DByte[x]     
          endif    
        next x  
       
       Return

  5. #5
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    i think the biggest time waist of this sub routine is waiting for a pulsin to see an input transition ,there is no time out on the command.

    As it happens because the input is connected to IR receiver , and some transient spikes do occur it gets to check the pulse and then return from the routine , generally with a sec

    I think ill add a timeout value so that it not waiting for input to occur , see if that improves it

  6. #6
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    is there a way to time out the pulsin command , so in the event i dont get an input , it times out.

    Tried setting timers , but as soon as it hit the pulsin command it sits there untill it gets a pulse and wont read any flags after that till it completes

    any code examples that get around this

  7. #7
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    found this after some searching the help

    DEFINE PULSIN_MAX 1000 'Maximum counts allowed before pulsin times out

    the value of 1000 looks like it clock cycles , but it not stated ?

  8. #8
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    well Pulsin_Max is ok when the pulse is measured , but if it stays at 100% or 0 , then there is no time out ,

    can someone advise some code that can get passed this

  9. #9
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    solved , i think , cheers

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


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    After talking to myself for several hours I realized that no one was listening...

    What was the final solution?
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: pulsin sample time

    lol, it seems that way some times , in some ways you tend to solve problems as you post

    well since this little pic is doing about 4 diff things at about the same time , as it it talking to currently 16 other RF devices , in sync within a started mesh network, its getting harder to get enough time for each process from a 4Mhz clock , so first of all i had to up the speed to 8Mhz , with all the timming changes to specific routines that was based on 4mhz.

    After reading more and doing searches found that pulsin_Max set to the min count time + 5% margin extra of my expected time of the pulsin , allowed it to get to the next command scientifically, when i did not get a valid signal input .

    Now to deal with error rates in TX / RX over RF and try and improve on the current poor performance.

    more fun to come

    Cheers

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