Timing Measurement


Closed Thread
Results 1 to 2 of 2
  1. #1

    Default Timing Measurement

    HI
    I am wanting to measure time between a switch closing and a programmed Pulsewidth. The code executes fine. When I push the button, the display reads out correctly. When I get the output of my pulse generator to the desired stop pulsewidth, an Elapsed time is displayed on the LED.

    The elapsed time sees a bit off, yet I am not sure if its really a measurement problem or my perception. I don't have anyway of measuring it with an instrument at the moment.

    Also is this the best route to take? I am trying to learn about TM0 and TM1 by looking through threads here. So I do have some TM config info in the code from playing around. Any links to TM0 info would be greatly appreciated. Or are there any books available that talk about Timers and CCP's that use PBP? It looks like I could use a CCP to get the pulsewidth too.


    Thanks for the input
    Toby

    Code:
    Include "modedefs.bas"	' Mode definitions for Serout
    DEFINE OSC 20
     
    OPTION_REG.7 = 0 'Pull Ups enabled
    OPTION_REG.6 = 1 'PB0 interrupt on falling edge
    OPTION_REG.5 = 0  'TMR0 Clock source CLK0
    OPTION_REG.4 = 1  'TMR0 high to low
    OPTION_REG.3 = 0  'Prescaler to timer0
    OPTION_REG.2 = 0  'Timer prescaler 1:2
    OPTION_REG.1 = 0
    OPTION_REG.0 = 0
    
    T1CON.5=0   'Prescaler 1:1
    T1CON.4=0
    T1CON.1=0   'Interal clock
    T1CON.0=1   'Enable Timer
    INTCON.4=0
    ADCON1 = 6 'A2D Off
    
    LCD            VAR    PortC.0
    Start          var    PortB.0
    Finish         var    PortB.1
    DSRPM          Var    PortC.3
    LDSRPM         var    word
    HDSRPM         Var    Word
    Time1          var    word
    Time2          VAr    word
    PB             var    PortB.2
    Checker        var    byte
    Seconds        var    byte
    Remainder      var    word
    RPM1000        var    byte
    RPM100         var    byte
    Display1000    var    byte
    Display100     var    byte
    Timer1000      var    byte
    Timer100       var    byte 
    TriggerRPM     var    word
      
    Serout LCD, N9600, [$1b, $30]  
    Serout LCD,N9600,["Ryan Timer",10,13,10,13]  
    
    Pause 1000	' Wait .5 second
    
    Repeat
        'Sets up backlighting
        iF pb = 0 tHEN 
           IF Checker = 0 then
              Serout LCD,N9600,[$1b ,$2a,123 ]
              Checker = Checker + 1
           else
           'pause 200
           if Checker = 1 then 
              Serout LCD,N9600,[$1b ,$2a,225 ]
              Checker = Checker + 1
           else
           'pause 200
           if Checker = 2 then 
              Serout LCD,N9600,[$1b ,$2a,0 ]
              Checker = 0
           endif
           endif
           endif
           pause 200
        endif
           
    Serout LCD, N9600, [$1b, $30]
    Serout LCD,N9600,[" Waiting",10,13]
    TriggerRPM = 528
    Until Start = 0 'B.0 goes low and starts timer
      
    Serout LCD, N9600, [$1b, $30]
    Serout LCD,N9600,[" Timer Activated",10,13]
    
    INTCON.5=1 'Enable Timer0 Interrupt
    
    on Interrupt goto Increment
    
    'Measures RPM
    Repeat
      Pulsin DSRPM, 0, LDSRPM
      PULSIN DSRPM, 1, HDSRPM
      HDSRPM = HDSRPM + LDSRPM
    Until HDSRPM <= TriggerRPM
    
    High Finish 'Turns on light
    
    Serout LCD, N9600, [$1b, $30]
    Serout LCD, N9600, ["E/T ", # Time2,".", # Time1/10,10,13]
    End
    
    disable
    Increment:
    Time1= Time1 +1
      If Time1 = 1000 then
         Time1 = 0
         Time2 = Time2 + 1
      endif
      INTCON.2 = 0
    resume

  2. #2


    Did you find this post helpful? Yes | No

    Default

    OK I got the TMR1 working. Pretty damn simple. It seems to me atleast, the most complicated part about getting any function of a PIC to work is finding the documentation. After that its a piece of cake.

Similar Threads

  1. 12F683 serout timing
    By Hobie Cat in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 21st December 2009, 16:57
  2. Advice on frequency measurement to 30MHz
    By Andy Wood in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th March 2009, 04:23
  3. 18F2550 timing
    By sstt1976 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 22nd August 2008, 00:30
  4. Capacitor Measurement
    By AMay in forum mel PIC BASIC
    Replies: 10
    Last Post: - 21st February 2007, 11:06
  5. HSEROUT buffering and timing - 16F88
    By picster in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 5th March 2006, 17:52

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