Difference between revisions of "Component: Encoder Rotary (Inputs: General)"
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
| Inputs: General | | Inputs: General | ||
|} | |} | ||
− | |||
Line 18: | Line 17: | ||
Encoder component implements a rotary encoder connected to two pins | Encoder component implements a rotary encoder connected to two pins | ||
+ | ==Detailed description== | ||
+ | |||
+ | Mechanical encoders can be a bit electrically noisy when switching and so to have reliable operation it is recommended to have a simple filter as shown here. | ||
+ | |||
+ | [[Image:EncoderCircuit.jpg]] | ||
==Examples== | ==Examples== | ||
− | |||
===Polling=== | ===Polling=== | ||
Example program showing how to use a quadrature encoder component using a polling method. | Example program showing how to use a quadrature encoder component using a polling method. | ||
− | |||
{{Fcfile|Quad_Encoder_Test.fcfx|Quad_Encoder_Test}} | {{Fcfile|Quad_Encoder_Test.fcfx|Quad_Encoder_Test}} | ||
− | |||
− | |||
===Timer Interrupt Based Polling=== | ===Timer Interrupt Based Polling=== | ||
Example program showing how to use a quadrature encoder component using a polling method via a timer interrupt. | Example program showing how to use a quadrature encoder component using a polling method via a timer interrupt. | ||
− | |||
{{Fcfile|Quad_Encoder_Timer.fcfx|Quad_Encoder_Timer}} | {{Fcfile|Quad_Encoder_Timer.fcfx|Quad_Encoder_Timer}} | ||
− | |||
− | |||
===Interrupt On Change=== | ===Interrupt On Change=== | ||
Example program showing how to use a quadrature encoder component using a interrupt on pin state change interrupt (IOC). | Example program showing how to use a quadrature encoder component using a interrupt on pin state change interrupt (IOC). | ||
− | |||
{{Fcfile|Quad_Encoder_IOC.fcfx|Quad_Encoder_IOC}} | {{Fcfile|Quad_Encoder_IOC.fcfx|Quad_Encoder_IOC}} | ||
− | |||
==Downloadable macro reference== | ==Downloadable macro reference== | ||
Line 140: | Line 135: | ||
==Property reference== | ==Property reference== | ||
+ | <span style="font-weight: normal;"><u>Post Scaler</u></span> | ||
+ | |||
+ | This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''Divider''. | ||
+ | |||
+ | Encoders with a mechanical click will often have 4 transitions per click. | ||
+ | |||
+ | 1:1 would provide the maximum output resolution. | ||
+ | |||
+ | 1:4 would provide the encoder click count. | ||
+ | |||
<span style="font-weight: normal;"><u>A</u></span> | <span style="font-weight: normal;"><u>A</u></span> | ||
Latest revision as of 13:46, 21 November 2022
Author | Matrix TSL |
Version | 1.3 (Release) |
Category | Inputs: General |
Contents
Encoder Rotary component
Encoder component implements a rotary encoder connected to two pins
Detailed description
Mechanical encoders can be a bit electrically noisy when switching and so to have reliable operation it is recommended to have a simple filter as shown here.
Examples
Polling
Example program showing how to use a quadrature encoder component using a polling method. Quad_Encoder_Test
Timer Interrupt Based Polling
Example program showing how to use a quadrature encoder component using a polling method via a timer interrupt. Quad_Encoder_Timer
Interrupt On Change
Example program showing how to use a quadrature encoder component using a interrupt on pin state change interrupt (IOC). Quad_Encoder_IOC
Downloadable macro reference
CheckForChanges
Polling function to check changes
Returns 1 for chaged, 0 for no change, 255 for error
Parameters
- This macro has no parameters
Return value
Disable
Disables the use of the quad encoder
Once this ist called, the read functions will return zeros until the next Enable() call
Parameters
- This macro has no parameters
Return value
- This call does not return a value
Enable
Enables the use of the quad encoder
If this is not called, the read functions will return zeros
Parameters
- This macro has no parameters
Return value
- This call does not return a value
ReadCounter
Reads the current dial counter
This is a counter from -32768 to 32767
Parameters
- This macro has no parameters
Return value
WriteCounter
Sets the value of the internal count variable.
Range: -32768 to 32767
Parameters
- INT Value
- Range: -32768 to 32767
Return value
- This call does not return a value
ResetCounter
Resets the current dial counter to zero
Parameters
- This macro has no parameters
Return value
- This call does not return a value
Simulation macro reference
This component does not contain any simulation macros
Property reference
Post Scaler
This property is of type Fixed list of ints and can be referenced with the variable name Divider.
Encoders with a mechanical click will often have 4 transitions per click.
1:1 would provide the maximum output resolution.
1:4 would provide the encoder click count.
A
This property is of type Single digital pin and can be referenced with the variable name pin_a.
Input pin A
B
This property is of type Single digital pin and can be referenced with the variable name pin_b.
Input Pin B
Repeat Rate
This property is of type Fixed list of ints and can be referenced with the variable name reprate.
Simulated repeat rate when clicking and rotating the encoder