PULSEIN Minimum Unit Time


+ Reply to Thread
Results 1 to 8 of 8

Thread: PULSEIN Minimum Unit Time912 days old

  1. #1
    dansagenius
    Guest dansagenius's Avatar

    0 Not allowed!

    Default PULSEIN Minimum Unit Time

    Please could somebody advise.
    I am using the PULSEIN command and see that the detection unit time varies with the clock frequency (4MHz = 10uS, 20MHz = 2uS etc)
    What would be the shorted unit time available for a given clock frequency? If I were to use a 40MHz, would the unit time goto 1uS? and likewise?
    I am measuring an FSK at 56KHz and need the highest resolution to detect the modulation of +/-400Hz.

    Many thanks

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,326
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    802.58 MB

    0 Not allowed!

    Default Re: PULSEIN Minimum Unit Time

    Hi,
    Have you looked at capture, I think with a 40Mhz clock you can get a 100 nanosecond period.
    This is not a PDS command though, you will need to study the datasheet CCP module.

    This is how I set up a CCP to capture ever 4th rising edge.
    Code:
    'Capture settings - used for speed                        
           Symbol CCPR1 = CCPR1L.Word    'Create a 16-bit variable out of CCPRL1
        
           CCP1CON = 000110            'Enable the CCP1 capture, every 4th rising edge    
    '0100 = Capture mode, every falling edge
    '0101 = Capture mode, every rising edge
    '0110 = Capture mode, every 4th rising edge
    '0111 = Capture mode, every 16th rising edge        
        
            Symbol SPEED_CAPTURE = PIR1.2    'CCP1 capture flag
    'Timer 0 settings - used for distance        
            Symbol TIMER0 = TMR0L.Word       'Create a 16-bit variable out of TMR0L
            T0CON = 100001               'TMR0 as counter, low to high, PSA 1:4 
    'Timer 1 settings - used for speed          
            Symbol SPEED_TIMER = TMR1L.Word       'Create a 16-bit variable out of TMR1L
            T1CON = 000001               'TMR1 prescale=1:1, and turn it on (100nS per count)
    'bits 5-4
    '00 = 1:1
    '01 = 1:2 
    '10 = 1:4
    '11 = 1:8
    from memory you just read CCPR1 and multiply it by the time period IE 100nS in this case.

    Regards,
    Bob

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Senior Member Stephen Moss's Avatar
    Join Date
    Jan 2006
    Posts
    505
    Thumbs Up
    Received: 30
    Given: 7
    Total Downloaded
    3.72 GB

    0 Not allowed!

    Default Re: PULSEIN Minimum Unit Time

    The manual instructions indicate it uses a timer but not if that is its own timer or one of the PICs onboard timers, nor does it mention how it uses the timer (Les or a look at the assembler code might indicate that).
    If you have an IOC pin available you could roll you own code using interrupt on change to start & stop one of the PICs timers, read its value and multiple that by the resolution. As you are setting up the timer yourself instead of PDS doing it in the background you will know exactly what your resolution in seconds per bit is.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    dansagenius
    Guest dansagenius's Avatar

    0 Not allowed!

    Default Re: PULSEIN Minimum Unit Time

    many thanks for the responses about using timers.

    With regards the PULSEIN command as shown in the 8bit and 24bit user manual commands list, I believe that there is an error. It seems that a 20MHz clock actually produces a 4uS unit and not the 2us as stated.
    Please could somebody check and confirm. !

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,404
    Thumbs Up
    Received: 290
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: PULSEIN Minimum Unit Time

    The Pulsein does not use any Timer peripherals, and is purely determined by the oscillator used. because it uses a loop and pin comparisons. The simple way to test the values given from a certain pulse length is a small program that displays what it can see with the pulse going to the pin.

    For a frequency of 56KHz, it might not be possible to see such a small frequency difference of 400Hz on a 8-bit device.

    Here's a demo that operates on the fastest 8-bit devices, and operates at 64MHz. It uses the Compare peripheral to capture the pulse width.

    Code:
    '
    ' Pulse width capture using the Compare peripheral
    ' Written by Les Johnson for the Proton BASIC compiler
    '    
        Device = 18F25K20
        Declare Xtal = 64
    
        Declare Hserial_Baud = 9600
        
        Dim wCCPR1_Value As Word
        Dim wPulseWidth As Word
        
        Dim wCCPR1 As  CCPR1L .Word
        Dim wTimer1 As  TMR1L .Word
            
        Input  PORTC .2                           ' The pulse goes on this pin
         T1CON  = 0                               ' \ 
         T1CONbits_TMR1ON  = 1                    ' / Enable Timer1
            
        Do                                      ' Create a loop         
            wTimer1 = 0                         ' Clear Timer1
            
            CCP1CON = $05                       ' Setup for Capture mode on every rising edge
            PIR1bits_CCP1IF = 0                 ' \
            While PIR1bits_CCP1IF = 0 : Wend    ' / Wait for a rising edge
            wCCPR1_Value = wCCPR1               ' Save the value of CCPR1L\H
    
            CCP1CON = $04                       ' Setup for Capture mode on every falling edge      
            PIR1bits_CCP1IF = 0                 ' \
            While PIR1bits_CCP1IF = 0 : Wend    ' / Wait for a falling edge
            wPulseWidth = wCCPR1                ' Save the value of CCPR1L\H
            
            wPulseWidth = wPulseWidth - wCCPR1_Value ' Calculate the pulse length
    
            HRSOutLn Dec wPulseWidth            ' Display the pulse length on the serial terminal
        Loop                                    ' Do it forever
        
    '-------------------------------------------------------------------------------
    ' Set the fuses for 64MHz operation from a 16MHz crystal. i.e. 4xPLL
    '
    Config_Start
        Debug = OFF      ' Background debugger disabled' RB6 and RB7 configured as general purpose I/O pins
        XINST = OFF      ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        STVREN = OFF     ' Reset on stack overflow/underflow disabled
        WDTEN = OFF      ' WDT disabled (control is placed on SWDTEN bit)
        FCMEN = OFF      ' Fail-Safe Clock Monitor disabled
        FOSC = HSPLL     ' HS oscillator, PLL enabled and under software control
        IESO = OFF       ' Two-Speed Start-up disabled
        WDTPS = 128      ' 1:128
        BOREN = OFF      ' Brown-out Reset disabled in hardware and software
        BORV = 18        ' VBOR set to 1.8 V nominal
        MCLRE = On       ' MCLR pin enabled, RE3 input pin disabled
        HFOFST = OFF     ' The system clock is held off until the HF-INTOSC is stable.
        LPT1OSC = OFF    ' T1 operates in standard power mode
        PBADEN = OFF     ' PORTB<4:0> pins are configured as digital I/O on Reset
        CCP2MX = PORTC   ' CCP2 input/output is multiplexed with RC1
        LVP = OFF        ' Single-Supply ICSP disabled
        Cp0 = OFF        ' Block 0 (000800-001FFFh) not code-protected
        CP1 = OFF        ' Block 1 (002000-003FFFh) not code-protected
        CPB = OFF        ' Boot block (000000-0007FFh) not code-protected
        CPD = OFF        ' Data EEPROM not code-protected
        WRT0 = OFF       ' Block 0 (000800-001FFFh) not write-protected
        WRT1 = OFF       ' Block 1 (002000-003FFFh) not write-protected
        WRTB = OFF       ' Boot block (000000-0007FFh) not write-protected
        WRTC = OFF       ' Configuration registers (300000-3000FFh) not write-protected
        WRTD = OFF       ' Data EEPROM not write-protected
        EBTR0 = OFF      ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        EBTR1 = OFF      ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        EBTRB = OFF      ' Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    Maybe more of a frequency counter is required, but this takes a length of time to capture a few cycles, so it might not be any good for modulation detection.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,404
    Thumbs Up
    Received: 290
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Pulse Width Capture on Rising Edges

    Here's the similar code as above, but altered so the subroutine that captures the pulse width is more like a command, and can be altered for every rising edge, every 4th rising edge, or every 16th rising edge:

    Code:
    '
    ' Pulse width capture using the Compare peripheral
    ' Written by Les Johnson for the Proton BASIC compiler
    '    
        Device = 18F25K20
        Declare Xtal = 64
    
        Declare Hserial_Baud = 9600
        
        Dim wCCPR1_Value As Word            ' Holds the value of CCPR1L\H
        Dim wPulseWidth As Word             ' Holds the pulse width
        Dim bEdgeCount As Byte              ' Holds the rising edges to count before capture
    
        Dim wCCPR1 As CCPR1L.Word           ' Create a 16-bit SFR from CCPR1L\H
        Dim wTimer1 As TMR1L.Word           ' Create a 16-bit SFR from TMR1L\H
    
    '--------------------------------------------------------------------------------
        GoTo Main                           ' Jump over the subroutine
    '--------------------------------------------------------------------------------
    ' Capture a pulse width using the compare peripheral
    ' Input     : pEdgeCount holds 1, 4, or 16 for the amount of rising edges to count
    ' Output    : wPulseWidth holds the width of the pulse
    ' Notes     : Must use the CCP1 pin as the input
    '
    $define Pulse_Capture(pEdgeCount, pResult) '
        bEdgeCount = pEdgeCount    '
        GoSub _Pulse_Capture       '
        pResult = wPulseWidth
         
    _Pulse_Capture:       
        Input PORTC.2                           ' The pulse goes on this pin
        T1CON = 0                               ' \ 
        T1CONbits_TMR1ON = 1                    ' / Enable Timer1
                
        If bEdgeCount = 1 Then                  ' Every rising edge?
            CCP1CON = $05                       ' Yes. So setup for Capture mode on every rising edge
        ElseIf bEdgeCount = 4 Then              ' Every 4th rising edge?
            CCP1CON = $06                       ' Yes. So setup for Capture mode on every 4th rising edge
        ElseIf bEdgeCount = 16 Then             ' Every 16th rising edge?
            CCP1CON = $07                       ' Yes. So setup for Capture mode on every 16th rising edge
        Else                                    ' Otherwise...
            CCP1CON = $05                       ' Default for Capture mode on every rising edge
        EndIf
        
        wTimer1 = 0                             ' Clear Timer1
        PIR1bits_CCP1IF = 0                     ' \
        While PIR1bits_CCP1IF = 0 : Wend        ' / Wait for a rising edge
        wCCPR1_Value = wCCPR1                   ' Save the value of CCPR1L\H
    
        PIR1bits_CCP1IF = 0                     ' \
        While PIR1bits_CCP1IF = 0 : Wend        ' / Wait for another edge
        wPulseWidth = wCCPR1                    ' Save the value of CCPR1L\H
            
        wPulseWidth = wPulseWidth - wCCPR1_Value ' Calculate the pulse width
        Return
    
    '-------------------------------------------------------------------------------
    ' The main program loop starts here
    '
    Main:
        Do                                  ' Create a loop         
            Pulse_Capture(4, wPulseWidth)   ' Capture the pulse width on every 4th rising edge    
            HRSOutLn Dec wPulseWidth        ' Display the pulse width on the serial terminal
        Loop                                ' Do it forever
        
    '-------------------------------------------------------------------------------
    ' Set the fuses for 64MHz operation from a 16MHz crystal. i.e. 4xPLL
    '
    Config_Start
        Debug = OFF      ' Background debugger disabled' RB6 and RB7 configured as general purpose I/O pins
        XINST = OFF      ' Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        STVREN = OFF     ' Reset on stack overflow/underflow disabled
        WDTEN = OFF      ' WDT disabled (control is placed on SWDTEN bit)
        FCMEN = OFF      ' Fail-Safe Clock Monitor disabled
        FOSC = HSPLL     ' HS oscillator, PLL enabled and under software control
        IESO = OFF       ' Two-Speed Start-up disabled
        WDTPS = 128      ' 1:128
        BOREN = OFF      ' Brown-out Reset disabled in hardware and software
        BORV = 18        ' VBOR set to 1.8 V nominal
        MCLRE = On       ' MCLR pin enabled, RE3 input pin disabled
        HFOFST = OFF     ' The system clock is held off until the HF-INTOSC is stable.
        LPT1OSC = OFF    ' T1 operates in standard power mode
        PBADEN = OFF     ' PORTB<4:0> pins are configured as digital I/O on Reset
        CCP2MX = PORTC   ' CCP2 input/output is multiplexed with RC1
        LVP = OFF        ' Single-Supply ICSP disabled
        Cp0 = OFF        ' Block 0 (000800-001FFFh) not code-protected
        CP1 = OFF        ' Block 1 (002000-003FFFh) not code-protected
        CPB = OFF        ' Boot block (000000-0007FFh) not code-protected
        CPD = OFF        ' Data EEPROM not code-protected
        WRT0 = OFF       ' Block 0 (000800-001FFFh) not write-protected
        WRT1 = OFF       ' Block 1 (002000-003FFFh) not write-protected
        WRTB = OFF       ' Boot block (000000-0007FFh) not write-protected
        WRTC = OFF       ' Configuration registers (300000-3000FFh) not write-protected
        WRTD = OFF       ' Data EEPROM not write-protected
        EBTR0 = OFF      ' Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
        EBTR1 = OFF      ' Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
        EBTRB = OFF      ' Boot block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    The above "Pulse_Capture" subroutine now uses every rising edge, or every 4th rising edge, or every 16th rising edge before capture begins. This will give a bit more difference in the 400Hz offset. A parameter within the $define alters the CCP1CON SFR accordingly.

    Using every 4th or every 16th rising edge will give measurable and comparable differences in the pulse width value returned for the modulation 400Hz offset. Every rising edge, doesn't give a measurable difference for the 400Hz difference.
    Last edited by top204; 25th May 2017 at 09:16.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    dansagenius
    Guest dansagenius's Avatar

    0 Not allowed!

    Default Re: PULSEIN Minimum Unit Time

    Many thanks for the info and for the sample code. I will carry out some tests.
    With regards my project spec, I realised to my shock that I need to decode the telegram which is sent along an FSK at 56Khz with a +/-200 modulation. This makes it even more tricky to get the timing resolution right!.
    Again, may thanks for the info you folks have provided, but keep them coming!

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,404
    Thumbs Up
    Received: 290
    Given: 141
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: PULSEIN Minimum Unit Time

    In tests, the snippet below detects 200Hz either way of 56KHz, using the above routine:

    Code:
    Main:
        Do                                      ' Create a loop         
            Pulse_Capture(16, wPulseWidth)      ' Capture the pulse width    
            Select wPulseWidth                  ' Compare the value in wPulseWidth
                Case 4550  To 4560              ' Is it between values 4550 and 4560?
                    HRSOutLn "56.2KHz"          ' Yes. So it's 56.2KHz
                Case 4565  To 4575              ' Is it between values 4565 and 4575?
                   HRSOutLn "56.0KHz"           ' Yes. So it's 56.0KHz
                Case 4580  To 4590              ' Is it between values 4580 and 4590?
                    HRSOutLn "55.8KHz"          ' Yes. So it's 55.8KHz
            EndSelect
        Loop                                    ' Do it forever
    So for translation, simply set or clear a bit when the correct frequency appears.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Pulsein minimum value
      By John Drew in forum Proton Plus Compiler v3
      Replies: 29
      Last Post: 27th March 2016, 23:21
    2. [SOLVED !] Question on PULSEIN, internal osc, and PLL
      By spyder0069 in forum Proton Plus Compiler v3
      Replies: 2
      Last Post: 26th March 2015, 20:54
    3. PulseIn
      By teo in forum Proton Plus Compiler v3
      Replies: 6
      Last Post: 25th November 2014, 17:41
    4. [SOLVED !] HRSOut float & PulseIn
      By picprotonguy in forum Proton Plus Compiler v3
      Replies: 14
      Last Post: 28th April 2012, 08:11
    5. DelayUs minimum value?
      By rcurl in forum Proton Plus Compiler v3
      Replies: 3
      Last Post: 31st December 2010, 12:38

    Members who have read this thread since 22nd October 2019, 21:24 : 0

    Actions :  (Set Date)  (Clear Date)

    You do not have permission to view the list of names.

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts