Difference between revisions of "Component: Quadrature Encoder (General Input)"
(Created page with "{| style="width:50%" |- | width="20%" style="color:gray;" | Author | Matrix TSL |- | width="20%" style="color:gray;" | Version | 1.4 |- | width="20%" style="color:gray...") |
|||
(18 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
|- | |- | ||
| width="20%" style="color:gray;" | Version | | width="20%" style="color:gray;" | Version | ||
− | | 1. | + | | 1.5 |
|- | |- | ||
| width="20%" style="color:gray;" | Category | | width="20%" style="color:gray;" | Category | ||
Line 14: | Line 14: | ||
==Quadrature Encoder component== | ==Quadrature Encoder component== | ||
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== | ||
+ | |||
+ | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Encoder_Quadrature.fcfx FC_Comp_Source_Encoder_Quadrature.fcfx] | ||
+ | |||
+ | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Encoder_Quadrature.fcfx FC_Comp_Source_Encoder_Quadrature.fcfx] | ||
==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]] | ||
==Examples== | ==Examples== | ||
− | |||
===Polling=== | ===Polling=== | ||
Line 35: | Line 42: | ||
{{Fcfile|Quad_Encoder_IOC.fcfx|Quad_Encoder_IOC}} | {{Fcfile|Quad_Encoder_IOC.fcfx|Quad_Encoder_IOC}} | ||
− | |||
+ | ==Macro reference== | ||
+ | |||
+ | ===CheckForChanges=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 50: | Line 59: | ||
+ | ===Disable=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 63: | Line 73: | ||
− | + | ===Enable=== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 94: | Line 87: | ||
− | + | ===ReadCounter=== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 120: | Line 96: | ||
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:]] - | + | | 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'' | ||
|} | |} | ||
+ | ===ReadCounter32=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | 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 | ||
|- | |- | ||
− | |||
− | |||
|- | |- | ||
− | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s32-icon.png]] - LONG | |
− | |||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===ResetCounter=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 156: | Line 129: | ||
+ | ===Rotate=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Rotate''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Simulation Rotate function to allow accurate rotation during simulation. Automatically called by any attached coupling or gearbox component. |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center | + | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT |
− | | width="90% | + | | width="90%" | Angle |
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
− | + | | colspan="2" | Amount to rotate the shaft input in degrees | |
− | |||
− | |||
− | | colspan="2" | | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| 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 187: | Line 148: | ||
+ | ===WriteCounter=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteCounter''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Sets the value of the internal count variable. Range: -32768 to 32767 |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s16-icon.png]] - INT |
− | | width="90%" | | + | | width="90%" | Value |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Range: -32768 to 32767 |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| 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 246: | Line 167: | ||
+ | ===WriteCounter32=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WriteCounter32''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Sets the value of the internal count variable. Range: -2147483648 to 2147483647 |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9- | + | | width="10%" align="center" | [[File:Fc9-s32-icon.png]] - LONG |
− | | width="90%" | | + | | width="90%" | Value |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Range: -2147483648 to 2147483647 |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| 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 | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Line 334: | Line 192: | ||
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Count Variable | ||
|- | |- | ||
|- | |- | ||
Line 340: | Line 202: | ||
|- | |- | ||
| 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. | | 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. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Encoder Resolution | ||
+ | |- | ||
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
Line 356: | Line 222: | ||
| colspan="2" | The resolution of the encoder in degrees | | colspan="2" | The resolution of the encoder in degrees | ||
|- | |- | ||
− | | width="10%" align="center" style="background-color:# | + | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] |
− | | width="90%" style="background-color:# | + | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Connections |
|- | |- | ||
|- | |- | ||
Line 370: | Line 236: | ||
| colspan="2" | Input Pin B | | colspan="2" | Input Pin B | ||
|- | |- | ||
− | | width="10%" align="center" style="background-color:# | + | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] |
− | | width="90%" style="background-color:# | + | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation |
|- | |- | ||
|- | |- |
Latest revision as of 15:13, 1 August 2023
Author | Matrix TSL |
Version | 1.5 |
Category | General Input |
Contents
Quadrature Encoder component
Quadrature Encoder component implements a rotary encoder connected to two pins. Quadrature Encoders provides incremental positioning rather than absolute positioning.
Component Source Code
Please click here to download the component source project: FC_Comp_Source_Encoder_Quadrature.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_Encoder_Quadrature.fcfx
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 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
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 |