Ccpr1 Register


Closed Thread
Results 1 to 6 of 6

Thread: Ccpr1 Register

  1. #1
    battlechess's Avatar
    battlechess Guest

    Default Ccpr1 Register

    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

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


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

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

  3. #3
    battlechess's Avatar
    battlechess Guest


    Did you find this post helpful? Yes | No

    Default Ccp1r Register

    Quote Originally Posted by Bruce
    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

  4. #4
    battlechess's Avatar
    battlechess Guest


    Did you find this post helpful? Yes | No

    Default Ccp1r Register

    Quote Originally Posted by battlechess
    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

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


    Did you find this post helpful? Yes | No

    Default

    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.
    Code:
    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.
    Regards,

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

  6. #6
    battlechess's Avatar
    battlechess Guest


    Did you find this post helpful? Yes | No

    Thumbs up Ccpr1 Register

    Bruce,
    Tks a lot!!!!
    It finally working!!!!

    tks a lot again

Similar Threads

  1. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  2. Can anyone help a newcomer?
    By scopit in forum Schematics
    Replies: 18
    Last Post: - 20th October 2009, 09:23
  3. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  4. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07
  5. MX7705 or AD7705 experience
    By FM11 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th January 2006, 21:54

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