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:
1.Can capture module of 877 be used for such a job?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
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.);
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.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. Also i could not find a helpful sample or tutorial on that, which explains it simply. i think "capture" is used rarely.
Bookmarks