Menu

No Capturing CCP1 Interrupt

Help
2010-06-21
2013-05-30
  • Reynaldo Díaz

    Reynaldo Díaz - 2010-06-21

    Hi, I'm trying to do a "Pulse Width StopWatch" for a Honda fuel injector to get, doing some math,
    fuel consumtion like litres/km, using PiC 16F777 CCP1 and CCP2 modules.

    The idea is:

    1- Capture a raising edge with CCP1 with CCP1CON = 00000101
    2- When capture, reset timer 1 and start it
    3- Capture a falling edge with CCP2 with CCP2CON = 00000100
    4- Read the value of CCPR2H and CCPR2L with the pulse width time.
    5- Do some math to get litres / km and display the value.

    The problem is I can't get a capture even only with CCP1. I use the example that GCBasic use in "On Interrupt" help, do some modifications to simplify, and when using the same "On Interrupt Timer1Overflow" it works fine, but when I change this for: "On Interrupt CCP1" and press a switch coneccted to RB3(CCP1), nothing happens. I simulate this on Proteus, start debug and the flag for CCP1IF never change to 1 indicating a capture.

    Next the codes, this codes are for 16F628 for simplicity.

    Here is the code for Timer1Overflow Interrupt:

    'This program raise an event whenever timer1 overflows.
    #chip 16F628, 4

    Dir PortB.6 out
    Dir PortB.7 out
    Dir PortB.3 in

    'CCP1CON = b'00000101' 'This is for capturing every raising edge
           'in CCP1 capture mode.

    InitTimer1 Osc, PS1_1/8

    StartTimer 1

    CounterValue = 0

    Wait 100 ms

    On Interrupt Timer1overflow Call IncCounter 'here is the other line
        'I will change for CCP1.

    Do
        Set PortB.6 on 'This is just to see it's working.
        Wait 10 ms
        Set PortB.6 off
        wait 10 ms
    Loop

    Sub IncCounter
    if PortB.7 = on then  'if interrup was capture must toggle.
    PortB.7 = off
    Else
    PortB.7= On
        end if
       
        wait 10 ms
    End Sub

    Here is the code for CCP1 Interrupt:

    'This Program "must" capture an event every time I push a switch on PortB.3 (CCP1)
    #chip 16F628A, 4

    Dir PortB.6 out
    Dir PortB.7 out 'for power a led to see if an interrupt was captured.
    Dir PortB.3 in  'Input for CCP1

    CCP1CON = b'00000101' 'Interrupt every raising edge

    InitTimer1 Osc, PS1_1/8

    StartTimer 1

    CounterValue = 0

    Wait 100 ms

    On Interrupt CCP1 Call IncCounter 'Here is the change of Interrupt.

    Do
        Set PortB.6 on   'This is just to see it's working.
        Wait 10 ms
        Set PortB.6 off
        wait 10 ms
    Loop

    Sub IncCounter
    if PortB.7 = on then   'if interrup was capture must toggle.
    PortB.7 = off
    Else
    PortB.7= On
        end if
       
        wait 10 ms
    End Sub

    ______________________________
    So what is wrong.

    And why I can't compile the asm file on MPASM? there is always errors about symbols and banks.

     
  • Reynaldo Díaz

    Reynaldo Díaz - 2010-06-25

    I read that post but it is too complicated. can you just make the code i wrote works.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.