Pulse capture on 12F1822


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    41

    Default Pulse capture on 12F1822

    Hello all, I'm having a bit of a problem using the CCP hardware to measure a pulse length on a 12F1822. I know where the program stalls but I can't figure out why. I debugged the program by lighting an LED at the various points. It never moves past the second while/wend loop when the trailing edge of the pulse is supposed to trigger an interrupt. Any ideas on why the interrupt is never happening? Thanks.

    Code:
    #CONFIG
    	__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    	__CONFIG _CONFIG2, _PLLEN_ON
    #ENDCONFIG
    
    OSCCON = %01110000		'8Mhz clock with 4x PLL (32MHz)
    APFCON = %00000001		'CCP1 on RA5 (pin 2) T1G is RA4 (pin 3)
    PORTA = 0				'RA5 all low
    TRISA = %00100000		'RA5 input
    CM1CON0 = 0 			'turn off comparitor 1
    CM1CON1 = 0 			'configuration of comparator 
    MDCON = 0 				'turn off data modulator
    DACCON0 = 0 			'turn off DAC 
    DACCON1 = 0				'turn off DAC
    ANSELA = 0				'All pins digital
    OPTION_REG = %10000000	'Weak pull ups off
    FVRCON = 0				'Bunch of stuff disabled
    CPSCON0 = 0				'Cap touch sensors off
    CCP1AS = 0
    PIE1.2 = 1
    PIE2 = 0
    T1GCON = 0
    
    
    DEFINE OSC 32
    Include "modedefs.bas"
    
    Symbol		Capture = PIR1.2
    T1			VAR word
    PW			VAR word
    
    reload:
    low porta.2
    CCP1CON = %00000101
    
    T1CON = 0
    TMR1H = 0
    TMR1L = 0
    T1CON.0 = 1
    
    Capture = 0
    while !Capture
    wend
    
    T1.HighByte = CCPR1H
    T1.LowByte = CCPR1L
    
    CCP1CON = %00000100
    Capture = 0
    
    
    while !Capture
    wend
    
    
    PW.HighByte = CCPR1H
    PW.LowByte = CCPR1L
    
    PW = PW-T1
    
    serout porta.4,N9600,[#PW,"uS High",13,10]
    goto reload
    
    end

  2. #2
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Pulse capture on 12F1822

    It looks like you're monitoring for a positive going pulse that is caught by the first While/Wend but will stay there because the second While/Wend is waiting for it to go Positive again.

    Change the second one to:
    Code:
    while Capture
    wend
    So now it is waiting for the pulse to go Low.

    Or am I missing something to?... yup, thought the "Capture" was a pin, it's the interrupt. NM
    Last edited by LinkMTech; - 18th May 2015 at 18:16.
    Louie

  3. #3
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Pulse capture on 12F1822

    Okay looked a little closer and "think" you need to enable the interrupts with:
    Code:
    INTCON = %11000000  'Enables global and all active peripheral interrupts
    Louie

  4. #4
    Join Date
    Nov 2008
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Pulse capture on 12F1822

    Louie, thanks for looking it over but I have to admit the mistake of operator error on my part I was using the sync output on the signal generator instead of the real output. Here is the working code.

    Code:
    #CONFIG
    	__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    	__CONFIG _CONFIG2, _PLLEN_ON
    #ENDCONFIG
    
    OSCCON = %01110000		'8Mhz clock with 4x PLL (32MHz)
    APFCON = %00000001		'CCP1 on RA5 (pin 2) T1G is RA4 (pin 3)
    PORTA = 0				'RA5 all low
    TRISA = %00100000		'RA5 input
    CM1CON0 = 0 			'turn off comparitor 1
    CM1CON1 = 0 			'configuration of comparator 
    MDCON = 0 				'turn off data modulator
    DACCON0 = 0 			'turn off DAC 
    DACCON1 = 0				'turn off DAC
    ANSELA = 0				'All pins digital
    OPTION_REG = %10000000	'Weak pull ups off
    FVRCON = 0				'Bunch of stuff disabled
    CPSCON0 = 0				'Cap touch sensors off
    CCP1AS = 0
    PIE2 = 0
    T1GCON = 0
    INTCON = 0
    
    
    DEFINE OSC 32
    Include "modedefs.bas"
    
    Symbol		Capture = PIR1.2
    T1			VAR word
    PW			VAR word
    
    reload:
    CCP1CON = %00000101
    
    T1CON = 0
    TMR1H = 0
    TMR1L = 0
    T1CON.0 = 1
    
    Capture = 0
    
    while !Capture
    wend
    
    T1.HighByte = CCPR1H
    T1.LowByte = CCPR1L
    
    CCP1CON = %00000100
    Capture = 0
    
    
    while !Capture
    wend
    
    
    PW.HighByte = CCPR1H
    PW.LowByte = CCPR1L
    
    PW = PW-T1
    
    serout porta.4,N9600,[#PW,10,13]
    goto reload
    
    end

Similar Threads

  1. 12F1822 troubles
    By Charlie in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th June 2012, 13:53
  2. Use Timer1 Gate to Capture Pulse Widths
    By Bruce in forum Code Examples
    Replies: 1
    Last Post: - 23rd March 2012, 17:21
  3. 12F1822 embedded host?
    By dhouston in forum USB
    Replies: 5
    Last Post: - 18th September 2011, 19:14
  4. MIBAM and 12F1822...
    By alesniak in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 17th September 2011, 07:45
  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