Quote Originally Posted by HenrikOlsson View Post
Hi,

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:

Attachment 6894
I coulda sworn I had it incrementing by 1 in earlier versions (back when I was using HPWM). Nonetheless, I believe I need to detect the 4 edges in order to determine the direction of turn, so maybe I'll add a counter (1-4) in the ISR and only increment MotorRPM when it hits 4 (and then reset).

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
I'll try this out. At first glance, though, the ISR is always setting TimeToSave to 5000 so I think it needs a check like:
Code:
If ValueDirty = 0 Then
  TimeToSave = 5000
EndIf
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.
I'll have to add a comment to my IOC ISR's that I do need to clear the flags.

Thanks again, Henrik!