Quad Encoder Problem


Results 1 to 37 of 37

Threaded View

  1. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Quad Encoder Problem

    Hi,
    What's weird is the 'MotorRPM' as displayed on the LCD jumps by 3-4 (i.e. current setting is '120' and then one click of the encoder makes it '124').
    Not weird, as I wrote earlier - turning the encoder from one click/detent to the next results in one quadrature cycle which is four "edges", ie four interrupts so, four counts:

    Name:  Quadcycle.JPG
Views: 3371
Size:  14.7 KB

    That's why you can't have any delay in the ISR because turning the encoder one "click" results in four interrupts, if you have a delay (Pause or other) in there it misses one or more of the four edges in the cycle and gets confused.

    You could setup a timer for the EEPROM save, or you could just set a variable to some value in the ISR, the Main routine then decrements this value and when it hits zero you save the value to EEPROM. That will allow the user to turn the knob and the value be saved some time after the change is complete, psuedo code
    Code:
    TimeToSave VAR WORD
    ValueDirty VAR BIT
    
    Main:
       'Code...
       'Code...
    
       If ValueDirty THEN
         TimeToSave = TimeToSave - 1
         If TimeToSave = 0            ' Time to save ?
           Write.....
           ValueDirty = 0               ' Clear the flag
         ENDIF
       ENDIF
    
       'Code
       'Code
    Goto Main
    
    ISR:
      TimeToSave = 5000
      ValueDirty = 1
      'More code....
    @ INT_RETURN
    Here the interrupt routine sets a flag indicating that the value has changed, it also sets a "counter" variable which the main routined counts down. If the Main routine executed 5000 times without the value being changed it saves the value to EEPROM. Obviously this relies on a somewhat constant execution time thru the Main routine but you get the idea.

    /Henrik.

    EDIT: Cross posting.... As for the other "weird" thing. It seems that DT-Ints does NOT handle clearing hte interrupt request flag for the IOC interrupt on these devices so you SHOULD to do that manually before exiting the interrupt (normally NOT needed when the ClearFlag switch is set to Yes). If the interrupt request flag is NOT cleard the interrupt refires over and over and over again which is why the button doesn't seem to work - that code never runs because the CPU spends all the time servicing the interrupt. At least that's what I think is happening, I know it didn't work here if I didn't clear the flags manually.
    Last edited by HenrikOlsson; - 15th March 2013 at 21:56.

Similar Threads

  1. RF600E & RF600D encoder/decoder problem
    By Megahertz in forum Off Topic
    Replies: 0
    Last Post: - 17th April 2012, 17:18
  2. using Quad UART
    By harryweb in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 30th April 2011, 00:13
  3. quad encoders
    By cpayne in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2007, 17:49
  4. Quad encoder problems
    By smitty505000 in forum mel PIC BASIC Pro
    Replies: 51
    Last Post: - 5th October 2006, 22:44
  5. Encoder problem
    By precision in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th September 2006, 22:21

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