Using hardware capture


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default Re: Using hardware capture

    Hi Bruce
    i am trying to use your code on 18f452 but it seems to stop at start i must be missing something

    DEFINE LOADER_USED 1 ' uses a bootloader
    Include "Modedefs.Bas"

    Define OSC 20
    clear

    ' Setup Hardware for uart
    DEFINE HSER_BAUD 9600
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_CLROERR 1
    Symbol Capture = PIR1.2 ' CCP1 capture flag
    T1 VAR WORD ' 1st capture value
    PW VAR WORD ' 2nd capture value & ultimately final pulse width
    TRISC.2 = 1 ' CCP1 input pin (Capture input)
    INTCON.7 = 0 ' Interrupts off

    hserout [" Start Measure ",10,13 ]
    ReLoad:
    CCP1CON = 000101 ' Capture mode, capture on rising edge
    T1CON = 0 ' TMR1 prescale=1, clock=Fosc/4, TMR1=off (200nS per count @20MHz)
    TMR1H = 0 ' Clear high byte of TMR1 counter
    TMR1L = 0 ' Clear low byte
    T1CON.0 = 1 ' Turn TMR1 on here
    Capture = 0 ' Clear capture int flag bit
    While !Capture ' Wait here until capture on rising edge
    Wend

    ' Rising edge detected / stuff Timer1 value in T1
    T1.HighByte = CCPR1H
    T1.LowByte = CCPR1L

    CCP1CON.0 = 0 ' Configure capture for falling edge now
    Capture = 0 ' Clear capture interrupt flag bit

    While !Capture ' While here until capture on falling edge
    Wend

    ' Falling edge detected / stuff Timer1 value in PW
    PW.HighByte = CCPR1H
    PW.LowByte = CCPR1L

    PW = PW-T1 ' High pulse width = PW-T1
    ' Convert to uS for 20MHz osc with 200nS Timer1 ticks
    PW = (PW * 2)/10
    hserout ["uS High = ",dec PW,10,13 ]
    'DEBUG dec PW,"uS High",13,10 ' Output to RS232 display
    GOTO ReLoad

    END

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default Re: Using hardware capture

    Not sure what you mean by it seems to stop at start but timer1 is running a lot faster at 20MHz, and you don't mention how far it gets or what it shows as the result, so it's tough to help.

    Have you tried at 4MHz?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    May 2004
    Location
    brighton
    Posts
    149


    Did you find this post helpful? Yes | No

    Default Re: Using hardware capture

    Sorry Bruce
    But got it going now
    i meant it always displayed: start Measure on pc and no measurements but its ok now
    thanks for you support

    Isaac

Similar Threads

  1. mS Timer
    By whmeade10 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th September 2020, 13:12
  2. Using CCP1 and CCP2 to measure instant fuel consumption
    By srspinho in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 20th September 2008, 16:50
  3. Measuring change of frequency with PIC
    By Aussie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 02:47
  4. Hardware capture on 16F876
    By MaxiBoost in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 4th April 2007, 20:19
  5. continious counting process (capture)
    By asynch in forum General
    Replies: 1
    Last Post: - 17th February 2006, 08:42

Members who have read this thread : 0

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