Jump to content

Component: Quadrature Encoder 2D (General Input): Difference between revisions

From Flowcode Help
No edit summary
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder""
 
(12 intermediate revisions by 3 users not shown)
Line 15: Line 15:
Quadrature Encoder component implements a rotary encoder connected to two pins. Quadrature Encoders provides incremental positioning rather than absolute positioning.
Quadrature Encoder component implements a rotary encoder connected to two pins. Quadrature Encoders provides incremental positioning rather than absolute positioning.


==Component Source Code==
==Version information==
 
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx]


Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx]
Library Version, Component Version, Date, Author, Info
6, 1.4, 26-11-24, BR, Updated tooltip for CheckForChanges macro


==Detailed description==
==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]]
 
 
 
 
 
 
 
 
''No detailed description exists yet for this component''


==Examples==
==Examples==


===Polling===


Example program showing how to use a quadrature encoder component using a polling method.
{{Fcfile|Quad_Encoder_Test_2d.fcfx|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.
{{Fcfile|Quad_Encoder_Timer_2d.fcfx|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).
{{Fcfile|Quad_Encoder_IOC_2d.fcfx|Quad_Encoder_IOC}}




''<span style="color:red;">No additional examples</span>''




Line 56: Line 51:


===CheckForChanges===
===CheckForChanges===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CheckForChanges'''
| width="90%" class="mtx-class-macrohead" | '''CheckForChanges'''
|-
|-
| colspan="2" | Polling function to check changes Returns 1 for chaged, 0 for no change, 255 for error&nbsp;
| colspan="2" | Polling function to check changes and update internal counter. Returns 1 for chaged, 0 for no change, 255 for error&nbsp;
|-
|-
|-
|-
Line 70: Line 65:


===Disable===
===Disable===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Disable'''
| width="90%" class="mtx-class-macrohead" | '''Disable'''
|-
|-
| colspan="2" | Disables the use of the quad encoder Once this ist called, the read functions will return zeros until the next Enable() call&nbsp;
| colspan="2" | Disables the use of the quad encoder Once this ist called, the read functions will return zeros until the next Enable() call&nbsp;
Line 83: Line 78:




===WriteCounter32===
===Enable===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteCounter32'''
| width="90%" class="mtx-class-macrohead" | '''Enable'''
|-
|-
| colspan="2" | Sets the value of the internal count variable. Range: -2147483648 to 2147483647&nbsp;
| colspan="2" | Enables the use of the quad encoder If this is not called, the read functions will return zeros&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-s32-icon.png]] - LONG
| width="90%" | Value
|-
|-
| colspan="2" | Range: -2147483648 to 2147483647&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 102: Line 92:




===Enable===
===ReadCounter===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Enable'''
| width="90%" class="mtx-class-macrohead" | '''ReadCounter'''
|-
|-
| colspan="2" | Enables the use of the quad encoder If this is not called, the read functions will return zeros&nbsp;
| colspan="2" | Reads the current dial counter This is a counter from -32768 to 32767&nbsp;
|-
|-
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




===Rotate===
===ReadCounter32===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''ReadCounter32'''
|-
| colspan="2" | Reads the current dial counter as a 32-bit value This is a counter from -2147483648 to 2147483647&nbsp;
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Rotate'''
|-
|-
| colspan="2" | Simulation Rotate function to allow accurate rotation during simulation. Automatically called by any attached coupling or gearbox component.&nbsp;
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s32-icon.png]] - LONG
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
===ResetCounter===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''ResetCounter'''
|-
|-
| width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT
| colspan="2" | Resets the current dial counter to zero &nbsp;
| width="90%" | Angle
|-
|-
| colspan="2" | Amount to rotate the shaft input in degrees&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 135: Line 134:




===ReadCounter===
===Rotate===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" class="mtx-class-macrohead" | '''Rotate'''
|-
| colspan="2" | Simulation Rotate function to allow accurate rotation during simulation. Automatically called by any attached coupling or gearbox component.&nbsp;
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadCounter'''
|-
|-
| colspan="2" | Reads the current dial counter This is a counter from -32768 to 32767&nbsp;
| width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT
| width="90%" | Angle
|-
|-
| colspan="2" | Amount to rotate the shaft input in degrees&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}
Line 150: Line 154:


===WriteCounter===
===WriteCounter===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteCounter'''
| width="90%" class="mtx-class-macrohead" | '''WriteCounter'''
|-
|-
| colspan="2" | Sets the value of the internal count variable. Range: -32768 to 32767&nbsp;
| colspan="2" | Sets the value of the internal count variable. Range: -32768 to 32767&nbsp;
Line 168: Line 172:




===ResetCounter===
===WriteCounter32===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ResetCounter'''
| width="90%" class="mtx-class-macrohead" | '''WriteCounter32'''
|-
|-
| colspan="2" | Resets the current dial counter to zero &nbsp;
| colspan="2" | Sets the value of the internal count variable. Range: -2147483648 to 2147483647&nbsp;
|-
|-
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" | [[File:Fc9-s32-icon.png]] - LONG
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" | Value
|}
 
 
===ReadCounter32===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| colspan="2" | Range: -2147483648 to 2147483647&nbsp;
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadCounter32'''
|-
|-
| colspan="2" | Reads the current dial counter as a 32-bit value This is a counter from -2147483648 to 2147483647&nbsp;
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s32-icon.png]] - LONG
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




==Property reference==
==Property reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
| width="90%" class="mtx-class-macrohead" | '''Properties'''  
|-
|-
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Count Variable
| width="90%" class="mtx-class-propfolder" | Count Variable
|-
|-
|-
|-
Line 215: Line 208:
| colspan="2" | Selects the size of the encoder count variable depending on the number of encoder counts required to be stored. The 16 bit variable counter is accessed via the ReadCounter and WriteCounter functions. The 32 bit variable counter is accessed via the ReadCounter32 and WriteCounter32 functions.&nbsp;
| colspan="2" | Selects the size of the encoder count variable depending on the number of encoder counts required to be stored. The 16 bit variable counter is accessed via the ReadCounter and WriteCounter functions. The 32 bit variable counter is accessed via the ReadCounter32 and WriteCounter32 functions.&nbsp;
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Encoder Resolution
| width="90%" | Invert Count
|-
| colspan="2" | &nbsp;
|-
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| width="90%" | Limit Value
|-
| colspan="2" | &nbsp;
|-
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" class="mtx-class-propfolder" | Encoder Resolution
|-
|-
|-
|-
Line 234: Line 237:
| colspan="2" | The resolution of the encoder in degrees&nbsp;
| colspan="2" | The resolution of the encoder in degrees&nbsp;
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Connections
| width="90%" class="mtx-class-propfolder" | Connections
|-
|-
|-
|-
Line 248: Line 251:
| colspan="2" | Input Pin B &nbsp;
| colspan="2" | Input Pin B &nbsp;
|-
|-
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
| width="90%" class="mtx-class-propfolder" | Simulation
|-
|-
|-
|-
Line 257: Line 260:
| colspan="2" | Simulated repeat rate when clicking and rotating the encoder&nbsp;
| colspan="2" | Simulated repeat rate when clicking and rotating the encoder&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" | Scope Traces
| width="90%" | Knob Colour
|-
|-
| colspan="2" | &nbsp;
| colspan="2" | &nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-type-12-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" | Poiner Style
| width="90%" | Pointer Style
|-
|-
| colspan="2" | &nbsp;
| colspan="2" | &nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| width="90%" | Style
| width="90%" | Scope Traces
|-
|-
| colspan="2" | &nbsp;
| colspan="2" | &nbsp;
|}
|}
==Component Source Code==
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx]
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx]

Latest revision as of 14:37, 13 July 2026

Author Matrix TSL
Version 1.4
Category General Input


Quadrature Encoder 2D component

Quadrature Encoder component implements a rotary encoder connected to two pins. Quadrature Encoders provides incremental positioning rather than absolute positioning.

Version information

Library Version, Component Version, Date, Author, Info
6, 1.4, 26-11-24, BR, Updated tooltip for CheckForChanges macro

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




Macro reference

CheckForChanges

CheckForChanges
Polling function to check changes and update internal counter. Returns 1 for chaged, 0 for no change, 255 for error 
- BYTE Return


Disable

Disable
Disables the use of the quad encoder Once this ist called, the read functions will return zeros until the next Enable() call 
- VOID Return


Enable

Enable
Enables the use of the quad encoder If this is not called, the read functions will return zeros 
- VOID Return


ReadCounter

ReadCounter
Reads the current dial counter This is a counter from -32768 to 32767 
- INT Return


ReadCounter32

ReadCounter32
Reads the current dial counter as a 32-bit value This is a counter from -2147483648 to 2147483647 
- LONG Return


ResetCounter

ResetCounter
Resets the current dial counter to zero  
- VOID Return


Rotate

Rotate
Simulation Rotate function to allow accurate rotation during simulation. Automatically called by any attached coupling or gearbox component. 
- FLOAT Angle
Amount to rotate the shaft input in degrees 
- VOID Return


WriteCounter

WriteCounter
Sets the value of the internal count variable. Range: -32768 to 32767 
- INT Value
Range: -32768 to 32767 
- VOID Return


WriteCounter32

WriteCounter32
Sets the value of the internal count variable. Range: -2147483648 to 2147483647 
- LONG Value
Range: -2147483648 to 2147483647 
- VOID Return


Property reference

Properties
Count Variable
Variable Type
Selects the size of the encoder count variable depending on the number of encoder counts required to be stored. The 16 bit variable counter is accessed via the ReadCounter and WriteCounter functions. The 32 bit variable counter is accessed via the ReadCounter32 and WriteCounter32 functions. 
Invert Count
 
Limit Value
 
Encoder Resolution
Post Scaler
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. 
Edges Per Revolution
Number of signal transitions per revolution. E.g. for a 360 degree encoder you would likely get 360 x 4 = 1440 transitions and an accuracy of 0.25 degrees. 
Resolution
The resolution of the encoder in degrees 
Connections
A
Input pin A 
B
Input Pin B  
Simulation
Repeat Rate
Simulated repeat rate when clicking and rotating the encoder 
Knob Colour
 
Pointer Style
 
Scope Traces
 

Component Source Code

Please click here to download the component source project: FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_Encoder_Quadrature_2dgi.fcfx