Pulse train capture


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795

    Default Pulse train capture

    I am trying to capture in an array the pulse width of a pulse train coming out of an HCS-301 chip.

    The pulses are not always the same in a raw but the width should be fairly consistent as the Logic analyzer confirms, about 800μsec and 400μsec.

    The PIC is the F886 at 8MHz so the resolution of PulsIn is 5μsec. Based on this the attached Excel shows some readings and though some pulses are in the correct range others are even 0 despite the use of PulsIn with a positive pulse trigger.

    Cannot understand why this happens.

    The complete pulse train consist of a guard width of 16ms, then 12 pulses of 50% 400/400μsec, a second guard width of about 4ms and then 66 pulses of 800 or 400μsec.

    the code is this:

    Code:
    #config
    Line1 = _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_ON
    Line2 = _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
        __CONFIG _CONFIG1, Line1 & Line2
        __CONFIG _CONFIG2, _WRT_HALF & _BOR40V
    #endconfig
    
    OSCCON = %01110001 '8MHz Clock
    
    'OSCCON = %01100001  '4MHz Clock
    
    DEFINE OSC 8
    
    ;----- Configuration bits ------------------------------------------------
    
    
    
    PORTA=0:PORTB=4:PORTC=0:PORTE=0
    
    TRISA=%00000000 					'RA0: RED LED
    									'RA1: Relay 1
    									'RA2: Relay 2
                        				'RA3: Relay 3
                        				'RA4: Relay 4
    									'RA5: 
    									'RA6: 
    									'RA7: 
    
    TRISB=%00111111						'RB0: RF in
                                        'RB1: Channel 4 Latch button
                                        'RB2: Channel 3 Latch button
                                        'RB3: Channel 2 Latch button
                        				'RB4: Channel 1 Latch button
                                        'RB5: Autolearn Button
                        				'RB6: NC
                                        'RB7: NC
                        
    TRISC=%00000100						'RC0:
    									'RC1:  
    									'RC2: 
    									'RC3:
    									'RC4:
    									'RC5: 
    									'RC6: TX
    									'RC7: RX
    									
    TRISE=%00000001						'RE0: assigned to /MCLR
    									
    OPTION_REG.0=1						'PSA0 PRESCALER SELECT 1:1 TO 1:256
    OPTION_REG.1=0						'PSA1
    OPTION_REG.2=1						'PSA2
    OPTION_REG.3=0						'PRESCALER TO: 1->WDT, 0->TMR0
    OPTION_REG.4=0						'T0SE SOURCE EDGE 1->H TO L, 0->L TO H
    OPTION_REG.5=0						'T0CS 1->FROM RA4, 0->FROM INT. CLOCK
    OPTION_REG.6=0						'INT EDGE SELECT 0->H TO L, 1->L TO H
    OPTION_REG.7=0						'PULL UP 1->DISABLE, 0->ENABLE
    
    WPUB = %00111111
    
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_SPBRG 12  ' 9600 Baud @ 8MHz, 0,16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    '************************* ADC Setup
    ADCON0 = 0
    ADCON1 = 0	'Set PORTA/E digital
    ANSEL  = 0  'all as digital inputs
    ANSELH = 0  'all as digital inputs
    
    BAUDCTL = %00010000         'Transmit inverted data (No MAX232 needed)
    
    code        VAR byte[9] BANK0   ' Code
    code1       var byte[66]
    temp        var word
    index       var byte
    
    clear
    
    hserout ["Waiting pulse",13,10]
    
    while 1
        pulsin portb.0,0,temp
        if temp>3000 then
            if temp<4000 then     'find lomg header of 16ms
                for index=0 to 10
                    pulsin portb.0,1,temp  'then skip 12 pulses of 50% Duty, 400ìsec
                next index
                for index=0 to 65   'now collect 66 pulses of aroun 800 or 400 ìsec
                    pulsin portb.0,1,temp
                    code[index]=temp
                next index
                for index=0 to 65
                    hserout [#code[index],13,10]  'display pulse train
                next index
                hserout ["End",13,10]
            endif
        endif
    wend
    Ioannis
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by Ioannis; - 25th May 2022 at 23:03.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Pulse train capture

    False alarm... Sorry.

    code[index] should be code1[index] in the for-next loops.

    Ioannis

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    1 out of 1 members found this post helpful. Did you find this post helpful? Yes | No

    Default Re: Pulse train capture

    The HCS301 is a KEELOQ encoder device and what you are possibly asking is for the decoder code.

    Have you seen AN744? It gives a decoder in C. Should not be too far away from implementation in PBP
    https://ww1.microchip.com/downloads/...tes/00744a.pdf

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Pulse train capture

    Thank you Jerson.

    I had this error in the above routine that collects the pulse train from the receiver module.

    Now works remarkably ok. No problem with the decoding. Also works fine.

    Ioannis

    P.S. Yes I do have this AN and others too. Have also the Keeloq Dev.Kit from Microchip but the C routines are not easy for me. Anyway did help a lot.
    Last edited by Ioannis; - 26th May 2022 at 09:59.

Similar Threads

  1. Pulse capture on 12F1822
    By astouffer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th May 2015, 21:25
  2. Help with PWM pulse train
    By abuhafss in forum General
    Replies: 1
    Last Post: - 4th April 2014, 23:19
  3. Use Timer1 Gate to Capture Pulse Widths
    By Bruce in forum Code Examples
    Replies: 1
    Last Post: - 23rd March 2012, 17:21
  4. generate a train of pulses
    By xvladx in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th January 2011, 11:02
  5. Pulse Capture and byte building
    By boroko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st July 2009, 02:59

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