A stopwatch to improve


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2006
    Location
    Lazio, Italy
    Posts
    41

    Default A stopwatch to improve

    For my stopwatch I need a precision of a hundredth of a second. By using a 18f252 Timer1 driven by a quartz to 32768 hz, I try to get an interrupt every 10 ms that I should increase a variable, but I can not get the right precision although the use of instant interrupt Darrel Taylor. Could someone give me some hints with timer setting? Thanks

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: A stopwatch to improve

    You will need to fine tune the preload value maybe. Do you have an O-scope? How do you know it is not correct? What else does the code do? Did you set your configs correctly? We really will need to know a bit more if we are going to be able to help you. We HAVE NO crystal ball!!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: A stopwatch to improve

    Search engine ................................

    Keyword : " Elapsed timer " .............................

    Result Ok .................................

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jul 2006
    Location
    Lazio, Italy
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: A stopwatch to improve

    Sorry Alain but I use in my stopwatch a ds32khz chip that drives the Timer1, and a crystal of 4 MHz for the 18f252. I believe that the 'elapsed timer using also a crystal of 4 MHz for the pic and 4 mhz/4 (1 Mhz) for Timer1. Am I wrong? Anyway I attach the listing.

    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 26/01/2011 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    @ __CONFIG _CONFIG1H,_OSCS_OFF_1H & _HS_OSC_1H
    @ __CONFIG _CONFIG2L,_BOR_OFF_2L & _PWRT_ON_2L
    @ __CONFIG _CONFIG2H,_WDT_OFF_2H
    @ __CONFIG _CONFIG3H,_CCP2MX_OFF_3H
    @ __CONFIG _CONFIG4L,_STVR_OFF_4L & _LVP_OFF_4L





    '---------------SETTAGGI PORTE ----------------------

    INTCON2.7=0 'ABILITA PORTB PULLUP
    TRISB =%00000111
    PORTB =%00000111
    TRISC =%00000001


    ' --------------SETTAGGI VARI ----------------------------



    DEFINE OSC 4 ' Clock a 4 Mhz

    DEFINE LCD_BITS 4 'NUMERO LINEE DI COMANDO 4 O 8
    DEFINE LCD_DREG PORTB 'PORTA ChE GESTISCE LCD
    DEFINE LCD_DBIT 4 'BIT INIZIALE BUS
    DEFINE LCD_RSREG PORTC 'PORTA CHE GESTISCE RS
    DEFINE LCD_RSBIT 5 'BIT CHE GESTISCE RS
    DEFINE LCD_EREG PORTB 'PORTA CHE GESTISCE E
    DEFINE LCD_EBIT 3 'PIN CHE GESTISCE IL SEGNALE E
    DEFINE LCD_LINES 2 'NUMERO LINEE LCD

    Define LCD_COMMANDUS 2000
    ' Command Delay (uS)
    Define LCD_DATAUS 50 ' Data Delay (uS)


    CENT VAR BYTE
    ORE VAR BYTE
    MINS VAR BYTE
    SEC VAR BYTE


    CENT=0
    ORE=0
    MINS=0
    SEC=0


    TIMERUNO VAR WORD




    INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts



    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    T1CON=%00000111




    START:
    IF PORTB.0=1 THEN START



    timeruno=65214

    TMR1H=TIMERUNO.HIGHBYTE
    TMR1L=TIMERUNO.LOWBYTE

    high porta.5
    pause 10
    low porta.5

    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts


    STO:
    IF CENT=100 THEN
    cent=0
    SEC=SEC+1
    if sec=60 then
    sec=0
    mins=mins+1
    if mins=60 then
    mins=0
    ore=ore+1
    endif
    endif
    LCDOUT $FE,$80,DEC2 ore," ",dec2 mins," ",dec2 sec
    ENDIF

    GOTO STO

    '---[INT - interrupt handler]---------------------------------------------------


    ToggleLED1:

    T1CON.0=0 ' Stop the Clock

    TMR1H=TIMERUNO.HIGHBYTE
    TMR1L=TIMERUNO.LOWBYTE

    T1CON.0=1 ' Restart the Clock
    CENT=CENT+1


    @ INT_RETURN

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default Re: A stopwatch to improve

    Ohhhh

    not difficult to use the Low freq osc with a 32768 Hz Xtal ....instead of the Clock Osc : the mod is really easy.

    I did it for my lawn tractor computer ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 1

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