continious counting process (capture)


Closed Thread
Results 1 to 2 of 2
  1. #1
    asynch's Avatar
    asynch Guest

    Question continious counting process (capture)

    hi,
    i have a differatial steering autonomous robot project. I use 16f877 to count some pulses from pulse generator transducers of each motor. The transducer signals are approx. 1400 rev/s at max. speed. The pulses should be counted continiously, because the robot position has to be logged to avoid it losing its path. My problem is pic must do some other tasks while counting - as it happens in hardware pwm. pic can do other tasks while doing hpwm.
    my counting code is below to give you the idea of how transducer works:
    sample:
    count sensor_data, 1000, speed 'get number of pulses in a second
    LCDOut $fe, 1 ' Clear LCD
    LCDOut $fe, 2 , #speed," pulses/s"
    Serout SO,T2400,[#SPEED," pulses/s",CR]
    goto sample
    1.Can capture module of 877 be used for such a job?
    2.I looked at the datasheet, but i couldn't figure out how to do it. Any assistance would be great!. Microchip's "CCP and ECCP TIPS 'N TRICKS" doc. explains a process as measuring period of a square wave with averaging. And it is;
    TIP #2 Measuring the Period of a Square Wave with Averaging:
    1. Configure control bits CCPxM3:CCPxM0 (CCPxCON<3:0>) to capture every 16th rising edge of the waveform.
    2. Configure the Timer1 prescaler so Timer1 will run 16 TMAX(Note 1) without overflowing.
    3. Enable the CCP interrupt (CCPxIE bit).
    4. When a CCP interrupt occurs:
    a) Subtract saved captured time (t1) from captured time (t2) and store (use Timer1 interrupt flag as overflow indicator).
    b) Save captured time (t2).
    c) Clear Timer1 flag if set.
    d) Shift value obtained in Step 4.a right four times to divide by 16 – this result is the period (T).
    Note 1: TMAX is the maximum pulse period that will occur.

    My coding of this is (its in the doc. squence.);
    include "modedefs.bas"

    TRISC.2=1 ' CCP1 input
    CCP1CON=%00000111 ' enable capture mode for every 16th rising edge
    T1CON = %00000001 ' i dont know how to set it to run 16 TMAX without overflowing.
    PIE1.2=1 ' enable interrupt

    symbol cflag = PIR1.2
    SYMbol SO = PORTB.7 'Serial Out TX
    SYMbol SI = PORTB.6 'Serial in RX

    period var word

    Main:
    if cflag = 1 then 'check the CCP interrupt flag?
    period.lowbyte = CCPR1L ' Store the captured value in
    period.highbyte = CCPR1H ' period variable
    Serout SO,T2400,[#period,CR]
    endif
    Other_processes_here: ' other tasks

    goto main
    there are lots of gaps in the code, i know, but i am a mech. engineering student. and don't know much about these codings. that's what i understand from all that documents. . Also i could not find a helpful sample or tutorial on that, which explains it simply. i think "capture" is used rarely.
    Last edited by asynch; - 10th February 2006 at 02:55.

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default For Continuos Counting it is better to use an interrupt

    Hi,

    Whenever you trigger a capture input pin it loads the value of Timer1 to the capture registers. So for your application you need to track Timer1 get difference values and do the calculation there after. Why not use an interrupt to increment a counter. Use an asm interrupt or if you are not so conversant with asm hunt for Darrel Taylor's instant interrupt thread. It lets processing the interrupts in basic with a little bit more code overhead. As for the distance measurement you can have some additional circuitry to get the direction of the rotation and use another pin to increment the counter. Albeit this can be done in software itself but may be complex with lots of noise on the encoder signals.

    Regards

    Sougata

Similar Threads

  1. mS Timer
    By whmeade10 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th September 2020, 13:12
  2. Using hardware capture
    By Bruce in forum Code Examples
    Replies: 14
    Last Post: - 25th March 2012, 06:52
  3. Interrupt RPM and Taylors Elapsed time on 18F4620
    By Tobias in forum mel PIC BASIC Pro
    Replies: 70
    Last Post: - 3rd February 2010, 17:12
  4. 16F684 - Capture - Timing - Counting
    By chips123 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th September 2009, 12:14
  5. Measuring change of frequency with PIC
    By Aussie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 02:47

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