PDA

View Full Version : Ccpr1 Register



battlechess
- 22nd December 2005, 14:07
Hi guys,
I have a problem with following prog to measure a period. I cannot read the real value of CCPR1L and CCPR1H. When I write the eeprom on-chip (16F877A) the value stored is zero.

How can read and store the real value? I'm using the MPLAB SIM to simulate the prog.

Regards

DEFINE LOADER_USED 1 ' Optional, allows use of melabs Loader
define osc 20

capture VAR PIR1.2 ' CCP1 capture flag
overflow VAR PIR1.0 ' Timer1 overflow flag

A VAR WORD ' Word variable that stores the value
I VAR BYTE
period var WORD

T1CON=%00000000 ' Timer1 reset
TMR1L=0 ' Reset Timer
TMR1H=0 ' Remember Timer is OFF

CCP1CON=%00000000
CCPR1L=0
CCPR1H=0

pir1.2=0 ' Reset Capture Flag
pir1.0=0 ' TMR1 register did not overflow

CCP1CON = %00000101 ' Enable the CCP1 capture, RISING edge
PIE1=%00101111 ' Enables:USART-SSP-CCP1-TMR2 to PR2 match -
' TMR1overflow interrupt

'********************* MAIN *************************
loop:
IF (capture = 0) Then loop ' Wait here until captured

T1CON = %00000001 ' TMR1 prescale=1, and turn it on (1uS per count)
CCP1CON = %00000100 ' Enable the CCP1 capture, FALLING edge
pir1.2=0

PERIOD.lowBYTE = CCPR1L ' Store the captured value in
PERIOD.highBYTE = CCPR1H ' period variable

capture = 0 ' Clear the capture flag

write 0,PERIOD.lowbyte

Bruce
- 22nd December 2005, 17:27
If you're testing this with MPLAB then you'll need to setup a pin stimulus to fire the capture event by toggling CCP1 or RC2. It works fine with MPLAB 7.3.

battlechess
- 23rd December 2005, 07:48
If you're testing this with MPLAB then you'll need to setup a pin stimulus to fire the capture event by toggling CCP1 or RC2. It works fine with MPLAB 7.3.

Hi Bruce,
I'm testing the prog on MPLAB 7.21 and I'm using "stimulus control" to apply the pulse on pin but, the result is negative.

Do you think the version of MPLAB might be the cause?

tks

battlechess
- 23rd December 2005, 08:41
Hi Bruce,
I'm testing the prog on MPLAB 7.21 and I'm using "stimulus control" to apply the pulse on pin but, the result is negative.

Do you think the version of MPLAB might be the cause?

tks

I just installed MPLAB ver. 7.3 and I have the same results.

Help me!!!!!

tks

Bruce
- 23rd December 2005, 15:43
Run this in the MPLAB sim. Have the stimulus window open, click animate, and when it stops on "IF (capture = 0) Then loop" ' Wait here until captured click the stimulus "fire button" to toggle RC2.


DEFINE LOADER_USED 1 ' Optional, allows use of melabs Loader
DEFINE osc 20

capture VAR PIR1.2 ' CCP1 capture flag
overflow VAR PIR1.0 ' Timer1 overflow flag

A VAR WORD ' Word variable that stores the value
I VAR BYTE
period var WORD

T1CON=%00000000 ' Timer1 reset
TMR1L=0 ' Reset Timer
TMR1H=0 ' Remember Timer is OFF
TRISC.2 = 1
CCP1CON=%00000000
CCPR1L=0
CCPR1H=0

pir1.2=0 ' Reset Capture Flag
pir1.0=0 ' TMR1 register did not overflow

CCP1CON = %00000101 ' Enable the CCP1 capture, RISING edge
PIE1=%00101111 ' Enables:USART-SSP-CCP1-TMR2 to PR2 match -
' TMR1overflow interrupt

'********************* MAIN *************************
loop:
IF (capture = 0) Then loop ' Wait here until captured

T1CON = %00000001 ' TMR1 prescale=1, and turn it on (1uS per count)
CCP1CON = %00000100 ' Enable the CCP1 capture, FALLING edge
pir1.2=0

PERIOD.lowBYTE = CCPR1L ' Store the captured value in
PERIOD.highBYTE = CCPR1H ' period variable

capture = 0 ' Clear the capture flag

write 0,PERIOD.lowbyte
goto Loop
If you're running this with animate, then go have yourself a cup of coffee because it's going to take a while before the EEPROM write happens.

If you use the run button, then click the stimulus fire button a few times while it's running, then click stop after a few seconds. In the EEPROM window, you'll see location 00 holding the captured value.

battlechess
- 11th January 2006, 15:51
Bruce,
Tks a lot!!!!
It finally working!!!!

tks a lot again