Capture woes...


Results 1 to 10 of 10

Thread: Capture woes...

Threaded View

  1. #1
    Join Date
    Oct 2004
    Posts
    448

    Default Capture woes...

    I need to measure the RPM of a motor that would range from about 300 to 2000. Based on a thread in which Bruce had given code to measure the pulse width (only the width, not the frequency) of a signal using the capture function, I used the following code, modified for frequency. I used a square wave generator to test out the code, and the numders I get dont match up at all.

    Its a 16F628A running the internal oscillator.

    INTCON = 0 ' Interrupts off


    CCP1CON = %00000101 ' Capture mode, capture on rising edge
    T1CON = 0 ' TMR1 prescale=4, clock=Fosc/4, TMR1=off
    T1CON.4 = 0
    T1CON.5 = 1

    CLEAR

    Reload:
    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

    T1CON.0 = 0 ' Turn TMR1 off here

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

    DEBUG #T1,13,10

    GOTO ReLoad


    I'm also attaching a screen grab of my calculations.

    Any idea where the problem is, guys?

    Thanks,

    Anand
    Attached Images Attached Images  

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