Encoder velocity....


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Encoder velocity....

    [QUOTE=HenrikOlsson;126443]Hi,
    For example, TMR1 is a 16 bit wide counter/timer. It's pretty much setup to be a "tick counter" at start up, all you need to do is enable it
    Code:
    T1CON.0 = 1   ' Start TMR1
    From now on TMR1 will tick at Fosc/4 but you can scale that down by using the prescaler.

    OK. So I am starting the clock ticker... How would I pull the current values from it? And then, since I only really need it when the machine is "lost", after my homing process, would it be to my advantage to disable it once finished, or just leave it running?

    And I'm not sure what you mean about getting V without doing a lot of math. The math is simple enough... and I don't see how to find V any easier since V is a calculation of time and distance. I would love an easier way if you can show me. This is what I'm doing now...


    homeElevation:
    serout commout,T4800,"E"
    Eencoder0Pos = 0
    gosub elUP
    pause(250)
    if Eencoder0Pos = 0 then gosub moveerror
    done = 0
    Do
    serin commin,T4800,cereal
    if cereal = "*" then goto abort
    Enewposition = Eencoder0Pos
    newtime = millis()
    if Enewposition > Eoldposition then Enewvel = (Enewposition-Eoldposition) * 1000 /(newtime-oldtime)
    if Eoldposition > Enewposition then Enewvel = (Eoldposition-Enewposition) * 1000 /(newtime-oldtime)
    Eoldposition = Enewposition
    oldtime = newtime

    if Enewvel < .5*Eoldvel then
    gosub allSTOP
    Eencoder0Pos = 3665
    gosub elDN
    do
    serin commin,T4800,cereal
    if cereal = "*" then goto abort
    if Eencoder0Pos =< elHOMEpos then
    gosub allSTOP
    done = 1
    exit
    endif
    pause(250)
    loop
    endif
    if(Enewvel > .5*Eoldvel) then Eoldvel = Enewvel
    if done = 1 then exit
    loop
    return

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Encoder velocity....

    Hi,
    OK. So I am starting the clock ticker... How would I pull the current values from it? And then, since I only really need it when the machine is "lost", after my homing process, would it be to my advantage to disable it once finished, or just leave it running?
    The timer, since it is 16 bits wide, consits of two 8 bit registers, TMR1H and TMR1L (check the datasheet). You read the registers as you read any other register in the PIC, for example TickCount = TMR1H * 256 + TMR1L. Since it's a hardware timer it'll keep running in the background without any impact to the rest of your software - as long as you don't want to use it for something else of course. Just remember that it's "only" 16 bits wide so it'll overflow "frequenctly".

    And I'm not sure what you mean about getting V without doing a lot of math. The math is simple enough...
    Well, yes, the math might not be very complicated from a human perspective but none of the devices you list as possible targets for your code does multiplication OR division (no 10, 12, 16 or 18 series PICs does division) in hardware so even though the actual equation/formula in it self (multiply by a thousand, divide by delta time) isn't "complicated" it's going to take the poor little PIC a lot of instruction cycles to get to a result (which MAY or may not matter). What I'm saying is that if you instead see to it that you get a new position update every x ms then all you need is a subtraction (current position - previous position) to get your velocity (in encoder counts per x ms).

    If it's not possible to get a consistent interval between position updates then you ARE doing the right thing by calculating velocity based on delta time AND distance.

    /Henrik.

Similar Threads

  1. 18F2431 QEI in Velocity mode
    By sean-h in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st February 2011, 17:59
  2. User Position, Velocity & Time II (D1h)
    By dj.lambert in forum GPS
    Replies: 2
    Last Post: - 31st July 2009, 10:21
  3. Encoder problem
    By precision in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th September 2006, 23:21
  4. rf encoder/decoder
    By a_critchlow in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd February 2006, 12:58
  5. Quadrature Encoder
    By Plasmajocky in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th June 2004, 18:35

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