RPM With Timer1


Closed Thread
Results 1 to 15 of 15

Thread: RPM With Timer1

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Posts
    60

    Default RPM With Timer1

    I'm using a 16f687 and trying to get the timer1 working. I'm using a code snipet from mister e. It works great with a 16f688 but can't get it to work with the 16f687.

    @wTimer1 = TMR1L
    wTimer1 var word EXT ' timer1 setup
    Speed:
    wTimer1=0 ' clear Timer1
    T1CON = %00000111 ' start timer1
    pause 1000 ' acquisition time
    T1CON = %00000110 ' stop timer1
    pause 100
    return

    The rest of the code works fine just this part doesn't. Also if I change wtimer1 to 4 it displays the 4 so I know it's getting here??????

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Do you have an external clock input on T1CKI? You have Timer1 configured
    for external clocks.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Jun 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Yes on RA5, sorry forgot to put that.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I can't see anything in the small code fragment you posted that
    would keep Timer1 from counting.

    Assuming you have pulses on RA5 during your pause time - it should
    work the same as on your 16F688. I suspect there's something either
    different in the rest of your code, a bad connection, or a fried pin.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Jun 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    I have pulses on RA5 and here's the code.

    Include "modedefs.bas"

    'DEFINES-----------------------------------------------------------------------
    define OSC 4
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS

    'SETUP REGISTERS---------------------------------------------------------------
    TRISA=%110000 'RA4,RA5 as Input
    ANSEL=%00001000 'AN3 Analog In
    ANSELH=$00 'All pins digital out
    TRISB=$00 'All pins output
    TRISC=$00 'All pins output
    CM1CON0.7=0 'Shut off comparators
    CM2CON0.7=0 'Shut off comparators
    ADCON0.7=1 'Right justify result

    'SETUP VARIBLES----------------------------------------------------------------
    DPIN var PORTC.1 ' Shift data pin
    CPIN var PORTC.2 ' Shift clock pin
    LPIN var PORTB.4 ' Latch pin
    adval var word ' Create adval to store result
    volt var byte ' Battery level
    cvolt var byte ' Charge voltage
    lvolt var byte ' Load voltage
    LBatt var byte ' Low battery alarm
    @wTimer1 = TMR1L
    wTimer1 var word EXT ' timer1 setup
    A595 var byte ' Alarm out byte
    C595 var byte ' Charge out byte
    L595 var byte ' Load out byte

    ; Initialize your Hardware first, set CONFIGs, OSC, Turn off A/D etc
    ;----[ Change these to match your LCD ]---------------------------------------
    LCD_DB4 VAR PORTC.3
    LCD_DB5 VAR PORTC.6
    LCD_DB6 VAR PORTC.7
    LCD_DB7 VAR PORTB.7
    LCD_RS VAR PORTC.5
    LCD_E VAR PORTC.4
    LCD_Lines CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
    LCD_DATAUS CON 50 ' Data delay time in us
    LCD_COMMANDUS CON 2000 ' Command delay time in us

    INCLUDE "LCD_AnyPin.pbp" ; *** Include MUST be AFTER LCD Pin assignments ****
    PAUSE 1000 : LCDOUT $FE,1 : PAUSE 250 ; Initialize LCD (You may not need this,
    ; but some displays are picky)
    ;------------------------------------------------------------------------------

    Voltsetup:
    lvolt=48 ' Set load dump to 14.8 volts
    cvolt=22 ' Set charge to 12.2 volts
    LBatt=16 ' Set low battery alarm to 11.6 volts

    Start:
    lcdout $FE,1,"RMLDESIGN VER1.0"
    lcdout $FE,$C0," WINDCONTROLLER"
    pause 4000
    lcdout $FE,1
    gosub getad
    adval=adval+100
    LCDOUT $FE,$80,"V=",dec (adval/10), ".", dec adval dig 0
    lcdout $FE,$88,"RPM=",dec4 wTimer1*9
    if volt>cvolt then gosub Load 'On Start Up Put On Load If Volts High

    Main:
    gosub Speed
    gosub Getad
    adval=adval+100
    LCDOUT $FE,$80,"V=",dec (adval/10), ".", dec adval dig 0
    lcdout $FE,$88,"RPM=",dec4 wTimer1*9
    if volt<LBatt then Alarm 'Show Low Battery
    if volt>lvolt then Load 'Put charge to load
    If volt<cvolt then Charge 'Charge battery
    goto main

    Speed:
    wTimer1=0 ' clear Timer1
    T1CON = %00000111 ' start timer1
    pause 1000 ' acquisition time
    T1CON = %00000110 ' stop timer1
    pause 100
    return

    Getad:
    adcin 3,adval 'Get A/D value
    if adval> 355 Then adval=355 'Range between 100 & 355 then minus
    if adval< 100 then adval=100 '100 to get 0=10 & 255=35.5
    adval=adval-100
    volt=adval
    return

    Alarm:
    a595=%00001001
    Shiftout DPIN, CPIN, MSBFIRST,[A595] ' send byte to 74hc595
    pulsout lpIN,10
    high portb.6
    lcdout $FE,$C0,"*LOWBATT CHARGE*"
    goto main

    Load:
    l595=%00100100
    Shiftout DPIN, CPIN, MSBFIRST,[L595]
    pulsout lpin,10
    high portb.5
    lcdout $FE,$C0," *ON LOAD* "
    goto main

    Charge:
    c595=%00010010
    Shiftout DPIN, CPIN, MSBFIRST,[C595]
    pulsout lpin,10
    high portb.6
    lcdout $FE,$C0," *CHARGING* "
    goto main

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    It might work once you fix a bunch of errors. Look through your code slowly, line by line.

    if volt>cvolt then gosub Load. This calls Load, but Load doesn't RETURN. It lands on a
    GOTO Main.

    if volt If volt T1CON = %00000111 ' start timer1 ? I'm not sure what this does, but it looks
    pretty odd...;o}

    volt=adval ' volt is a byte. adval is a word?

    Your Main routine has a RETURN instead of a GOTO Main. This, along with the GOSUB Load
    with no RETURN is going to screw up the stack.

    Go through it all slowly. There may be more potential show-stoppers....;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Interrupt RPM and Taylors Elapsed time on 18F4620
    By Tobias in forum mel PIC BASIC Pro
    Replies: 70
    Last Post: - 3rd February 2010, 16:12
  2. Pulsin vs. Interrupt RPM measurement
    By Tobias in forum General
    Replies: 1
    Last Post: - 31st December 2009, 01:29
  3. 16f877A and tmr1 external crystal question
    By comwarrior in forum General
    Replies: 3
    Last Post: - 13th July 2009, 00:40
  4. RPM - DIV32 Problem
    By davewanna in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th April 2008, 04:33
  5. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52

Members who have read this thread : 3

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