PBP projects for R/C models


Results 1 to 40 of 772

Threaded View

  1. #3
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Pulse width measurement

    For pulse width measurement, I ran across an interesting page.

    http://www.mcmanis.com/chuck/robotic...e_measure.html

    I borrowed a little bit of the code, and then added it to some DT_Interrupts. I am just measuring a servo pulse width, and sending raw tmr1 result to the serial port here, but you can change it to make it do other things. This was done with a PIC18f2520 in a LAB-X2. But the above gentleman used a PIC16F628, so it should be pretty flexible if you chose the corresponding DT_INTS include file. I would like to see more examples of pulse width measurement as well as pulse generation using interrupts, so if you have some, please share!

    Code:
    DEFINE OSC 20
    DEFINE LOADER_USED 1         
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 42  ' 115200 Baud @ 20MHz, 0.94%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    LED0 VAR portb.0
    LED1 VAR portb.1
    LED2 VAR portb.2
    
    adcon1=15        ;sets all to digital
    TRISA=%00000000                         ' Set PORTA  
    TRISB=%01110000                         ' Set PortB
    TRISC=%10000100                         ' Set PortC bit.2 for input (ccp) and bit.7 for ser input
    
    INCLUDE "DT_INTS-18.bas"  ; Base Interrupt System
    INCLUDE "sub16.inc"       ; subtract 16 bit macro
                       
    LED0=0
    LED2=0
    
    risetime VAR WORD
    falltime VAR WORD
    falltime_l VAR falltime.Byte0
    falltime_h VAR falltime.Byte1
    risetime_l VAR risetime.Byte0
    risetime_h VAR risetime.Byte1
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR0_INT,   ToggleLED0,   ASM,  yes
            INT_Handler    CCP1_INT,   PulseWidth,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T0CON = %10000100
    T1CON = %00000001
    T2CON = %00111101
    CCP1CON = %00000101
    @   INT_ENABLE  TMR0_INT      ; Enable Timer 0 Interrupts 
    @   INT_ENABLE  CCP1_INT      ; Enable Capture Compare for pulse width measurement
    
    Main:
        PAUSE 1000
        HSEROUT [DEC falltime,10]
    GOTO Main
    
    ASM
    ToggleLED0
        btg  _LED0        ;blinky light
        INT_RETURN
    ENDASM
    
    
    ASM
    PulseWidth
        BTFSS   CCP1CON, CCP1M0 ; Check for falling edge watch
        GOTO    FALL_EDGE       ; Go pick up the falling edge
        MOVF    CCPR1L,W        ; else store leading edge value
        MOVWF   _risetime_l         ; into 16 bit word risetime
        MOVF    CCPR1H,W
        MOVWF   _risetime_h
        BCF     CCP1CON, CCP1M0 ; Now capture the trailing edge
        GOTO    ISR_2           ; Exit the interrupt service routine
            
    FALL_EDGE:
        BSF     CCP1CON, CCP1M0 ; Re-set for trailing edge capture
        MOVF    CCPR1L,W        ; Store the captured value into
        MOVWF   _falltime_l         ; falltime_l and ...
        MOVF    CCPR1H,W
        MOVWF   _falltime_h       ;             ... falltime_h
        ;
        ; 16 bit subtract 
        ;     falltime = falltime - risetime
        ;
        SUB16   _falltime, _risetime          ;this subroutine performs 16 bit subtraction
    ISR_2
        INT_RETURN
    ENDASM
    Attached Files Attached Files
    Last edited by ScaleRobotics; - 10th January 2010 at 09:21.

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP Extensions, What are they?
    By PJALM in forum PBP Extensions
    Replies: 9
    Last Post: - 28th September 2021, 11:26
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. Making PBP code more modular
    By forgie in forum General
    Replies: 30
    Last Post: - 25th October 2005, 16:24

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