tmr1 on 16f690


Closed Thread
Results 1 to 9 of 9

Thread: tmr1 on 16f690

  1. #1
    dan gill's Avatar
    dan gill Guest

    Unhappy tmr1 on 16f690

    I've just started playing with the tmr1 on the 16F690. I'm using the t1ckin for an async counter to measure rotational shaft speed. What I can't seem to get is how to determine when the timer stops incrementing, ie: when the shaft has stopped rotating or is slowing down. I have tried the count command, but I can't use it due to the long delay necessary for the count. I know I'm going to feel stupid when someone shows me, but I just have a block or something...I'm only using the tmr1L for the timer, since the initial shaft speed doesn't need to register over 60 revs per second.
    I've been reseting the timer once it reaches 60 since I'm only interested when the speed of the shaft is less than 60. Does anyone have any ideas about how to tell when the timer has stopped incrementing???

    Thanks,

    Dan

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Smile Try the search engine first

    Hi Dan,
    Looks like you are a new member, Welcome. As you probably have guessed this has been addressed here before. The forum has a pretty good search engine, on the toolbar at the top. Here is a link to get you started:
    http://www.picbasic.co.uk/forum/show...hlight=encoder
    Do search for timers too.
    Regards
    JS

    IF you need help after reading in these posts, post back and someone else or myself will help you, sayzer just taught me how to set these up last month.
    Last edited by Archangel; - 25th November 2006 at 08:02.

  3. #3
    dan gill's Avatar
    dan gill Guest


    Did you find this post helpful? Yes | No

    Unhappy Still don't get it!

    Thanks Joe for the help, but I'm still not getting it.

    My entire code works perfectly for what I need, except for the timer. I can get it to count fine, but I have no idea when it has quit counting. I'm using a magnetic reed switch and rare earth magnet to drive the t1clkin from high to low and it increments the timer great, but I can't figure out the code to tell the Pic that the shaft is no longer rotating, and that the timer is no longer counting. It has become the bane of my program! Do you have any other ideas??? Thanks...


    Dan

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Post it

    Hi Dan,
    Please post your code so the experts and a few of us novices can see what you are doing. Please tell us what pic you are using too.
    JS

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,531


    Did you find this post helpful? Yes | No

    Default

    Hi Dan,
    One approach could be to read the TMR1L register at certain time intervals and if the value you get is below a certain setpoint you say that the shaft no longer turns.

    Get value from counter...
    Reset counter to 0...
    Compare value to setpoint...
    If lower then shaft is stopped or turning too slow...
    Do other stuff...(this needs to take aprox. the same amount of time each loop.)
    Perhaps pause for a while...
    Do it all over again...

    Or you could set up TMR0 as an interrupt source and get the value of the TMR1 counter in the interrupt service routine.

    /Henrik Olsson.

  6. #6
    dan gill's Avatar
    dan gill Guest


    Did you find this post helpful? Yes | No

    Unhappy tmr1L on 16F690

    Ok guys,

    I've tried the reset deal and the comparison deal. I'm driving an R/C servo, so I can't use any other pause other than the 50Hz update pause. I need the tmr1L to do everything in the background without upsetting the servo refresh rate. I used the COUNT command and it would work the best for what I'm doing if it didn't require such a long pause for the count. I spoke with Charles at MELABS and suggested the tmr1 use. Here's a snippet of the program code. I can't use the tmr0 either. I need the pinout. There is no room to use a larger chip either.

    Chip is a 16F690


    PROGRAMSET:

    SEROUT LCD,R,[I,LINE4]
    SEROUT LCD,R,["PROGRAMSET"]
    A=0
    high LED4 'TURN ON GREEN LED TO SHOW SYSTEM READY
    FOR A= 1 TO 50 '1 SECOND TIME LOOP COUNTER FOR TMR1L
    IF A=50 THEN GROUNDSPEED 'LOOP FOR CHECKING GROUNDSPEED
    IF SW1=1 AND SW2=1 THEN RESET 'push switch 1 first
    HIGH SERVO
    PAUSEUS (1000+S)
    LOW SERVO
    PAUSE 16
    NEXT A
    GOTO PROGRAMSET



    GROUNDSPEED: 'CHECKS GROUNDSPEED EVERY 1 SECOND

    SEROUT LCD,R,[I,1]
    SEROUT LCD,R,[I,LINE1]
    SEROUT LCD,R,["GROUNDSPEED"]
    SEROUT LCD,R,[I,LINE2]
    SEROUT LCD,R,["TMR1L=",#TMR1L]
    IF TMR1L>60 THEN TIMERRESET 'TMR1L RESETS IF SPEED GREATER THAN 60
    HIGH SERVO
    PAUSEUS (1000+S)
    LOW SERVO
    PAUSE 16

    My program works wonderfully if I could just get the last of the code to work.
    Do you guys think I could use a smaller reset and check it like Henrik has suggested. The only problem I can see with the method is what if the program happens to check the timer when it's resetting? That would give a false reading. The absolute bottom line is I must be positive of when the shaft is no longer rotating, or at the very least, moving very slowly. Once the shaft stops moving, I can tell the servo to move, but not before. I really am upset that I have over 3000 words of code and that I can't figure out what is probably only a few words to complete the program.

    I really appreciate all the help. Thanks.

    Dan

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Missing code

    Quote Originally Posted by dan gill
    Ok guys,

    I've tried the reset deal and the comparison deal. I'm driving an R/C servo, so I can't use any other pause other than the 50Hz update pause. I need the tmr1L to do everything in the background without upsetting the servo refresh rate. I used the COUNT command and it would work the best for what I'm doing if it didn't require such a long pause for the count. I spoke with Charles at MELABS and suggested the tmr1 use. Here's a snippet of the program code. I can't use the tmr0 either. I need the pinout. There is no room to use a larger chip either.

    Chip is a 16F690


    PROGRAMSET:

    SEROUT LCD,R,[I,LINE4]
    SEROUT LCD,R,["PROGRAMSET"]
    A=0
    high LED4 'TURN ON GREEN LED TO SHOW SYSTEM READY
    FOR A= 1 TO 50 '1 SECOND TIME LOOP COUNTER FOR TMR1L
    IF A=50 THEN GROUNDSPEED 'LOOP FOR CHECKING GROUNDSPEED
    IF SW1=1 AND SW2=1 THEN RESET 'push switch 1 first
    HIGH SERVO
    PAUSEUS (1000+S)
    LOW SERVO
    PAUSE 16
    NEXT A
    GOTO PROGRAMSET



    GROUNDSPEED: 'CHECKS GROUNDSPEED EVERY 1 SECOND

    SEROUT LCD,R,[I,1]
    SEROUT LCD,R,[I,LINE1]
    SEROUT LCD,R,["GROUNDSPEED"]
    SEROUT LCD,R,[I,LINE2]
    SEROUT LCD,R,["TMR1L=",#TMR1L]
    IF TMR1L>60 THEN TIMERRESET 'TMR1L RESETS IF SPEED GREATER THAN 60
    HIGH SERVO
    PAUSEUS (1000+S)
    LOW SERVO
    PAUSE 16

    My program works wonderfully if I could just get the last of the code to work.
    Do you guys think I could use a smaller reset and check it like Henrik has suggested. The only problem I can see with the method is what if the program happens to check the timer when it's resetting? That would give a false reading. The absolute bottom line is I must be positive of when the shaft is no longer rotating, or at the very least, moving very slowly. Once the shaft stops moving, I can tell the servo to move, but not before. I really am upset that I have over 3000 words of code and that I can't figure out what is probably only a few words to complete the program.

    I really appreciate all the help. Thanks.

    Dan
    Hi Dan,
    isn't there more to this code? Where are your variable declarations? Are there more subroutines? It's just really hard to guess what you have and harder to copy/paste into pbasic compiler so as to work on this for you, if parts are missing.
    JS

  8. #8
    dan gill's Avatar
    dan gill Guest


    Did you find this post helpful? Yes | No

    Smile Yippee. I got it.

    I started messing around with Henrik had said about resetting the timer. I ran the timer thru a one second loop and if the tmr1L>0 then I reset the timer.
    I then ran a counter to count up only when tmr1L was zero. The only way to have it be zero, was for the timer to quit counting. I used a count up to 3 just to be sure it wasn't just counting really slow and it works great. It may not be perfect, but it get the rev/second so close that it really doesn't matter for my application. Thanks guys for all the suggestions. you helped me a lot.

    Dan

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Terrific!

    Hi Dan,
    glad you got it. Check your private mail too!

Similar Threads

  1. Simple TMR1 application example needed
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th February 2010, 09:52
  2. TMR1 external LP xtal setup check
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th October 2009, 18:11
  3. Replies: 2
    Last Post: - 7th October 2009, 00:06
  4. 16f877A and tmr1 external crystal question
    By comwarrior in forum General
    Replies: 3
    Last Post: - 13th July 2009, 00:40
  5. Measuring change of frequency with PIC
    By Aussie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 01:47

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