CCP and timers to capture frequency


Results 1 to 4 of 4

Threaded View

  1. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,651


    Did you find this post helpful? Yes | No

    Default Re: CCP and timers to capture frequency

    my old proteus can't sim that chip but a 16f1825 is ok

    done like this the "remainder" is time between pulses in uS provided overflow is < 2







    Code:
    '****************************************************************
    '*  Name    : 324_CCP1_Test.pbp                                 *
    '*  Date    : 09/30/20                                          *  
    '*  Notes   : TEST  using    16F1825                            *
    '****************************************************************
    '*THIS REV:  timing perfect
    #CONFIG
      __config  _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
      __config  _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_19 & _LVP_OFF
    #ENDCONFIG
    
    INCLUDE "DT_INTS-14.bas"  ; 
    INCLUDE "ReEnterPBP.bas"    ; Include for DT_INTS.  ver 3.4
    
    DEFINE OSC 8
    PulseIn     var PORTC.5  ' Monitor ECM tachometer signal 
    PulseFlag   var byte       ' register if CAPTURE Int was entered
    Overflows   VAR word    ' count the times TMR1 overflows
    Remainder   VAR word    ' remaining TMR1 ticks after last overflow
    lastcount   VAR word
    ANSELA = 0                  ' Set all digital 
    ANSELC = 0
    CCP1CON = %00000101     ' On, Capture every + edge
    
    'CCPTMRS = %01010101     ' ALL CCPS using TMR1 (already default)
    'INTCON = %11000001
    
    OSCCON=$70
    
    
    T1CON  = %00010001       ' 1:1 prescale, clock=Fosc/4, TMR1=on 
    T2CON  = %00000100       ' 1:1 PRE and POST, ON 
    '********* USART  ****************************************************
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 51  ' 9600 Baud @ 8MHz, 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    HSEROUT ["324_CCP1_test",10,13]
    pause 2000
    ;----[Interrupts]----------------------------------------
    ASM
    INT_LIST  macro    ; IntSource,   Label,   Type, ResetFlag?
            INT_Handler   CCP1_INT, _Capture,   PBP,  yes        ; WORKS
            INT_Handler   TMR1_INT,  _Timer1,    PBP,  yes
        endm
        INT_CREATE               ; Creates the High Priority interrupt processor
    ENDASM
    @    INT_ENABLE  CCP1_INT    ; enable Capture interrupts
    @    INT_ENABLE  TMR1_INT    ; enable Timer 1 interrupts
    
    
    Main:
      IF PulseFlag = 1 THEN
    '     PULSOUT tachdrv, 50      ' 
         HSEROUT ["OF= ",DEC Overflows,"  ,Ticks= ",DEC Remainder, 13,10]
         PulseFlag = 0
         Overflows = 0
         PIR1.0 = 0               ' clear TMR1IF
      ELSE 
        HSEROUT ["NoFlag", 13,10]  
      ENDIF 
    GOTO Main
    '---[CCP1 - interrupt handler]------------------------------------------
    Capture:  ' Enter here with input Pulse  (CCP1) 
        Remainder= TMR1  - lastcount
        lastcount = TMR1
        PulseFlag = 1           ' set flag to pulse out @ each +capture
    @ INT_RETURN
    ''**** TMR *********
    Timer1:
        Overflows = Overflows + 1
    @ INT_RETURN    
    END
    Last edited by richard; - 1st October 2020 at 11:47.
    Warning I'm not a teacher

Similar Threads

  1. Question regarding CCP
    By spcw1234 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th April 2013, 09:55
  2. Replies: 1
    Last Post: - 9th March 2013, 07:10
  3. Capture without CCP
    By boroko in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th March 2009, 23:09
  4. use of ccp mode
    By boboco in forum General
    Replies: 10
    Last Post: - 6th April 2006, 13:58
  5. CCP question
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th December 2005, 17:08

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