Hello,
I tried to control a servo with an encoder, and I have some troubles. I cannot find where I made a mistake. I will be thankful if someone checks my project.
Best regards,
Zhmil1789
Encoder troubles
-
Zhmil1789
- Posts: 10
- http://meble-kuchenne.info.pl
- Joined: Sun Mar 01, 2026 6:50 pm
- Has thanked: 9 times
Encoder troubles
- Attachments
-
- encoder.fcfx
- (13.75 KiB) Downloaded 68 times
-
- Screenshot 2026-05-14 072740.png (202.23 KiB) Viewed 277 times
-
BenR
- Matrix Staff
- Posts: 2207
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 605 times
- Been thanked: 803 times
Re: Encoder troubles
Hello,
You need to either poll the encoder at a high rate or you need to enable edge driven interrupts to catch when the encoder moves.
Here's an example of each method, the edge driven approach is much more suitable if you can use that as the interrupt only fires when the encoder moves.
You need to either poll the encoder at a high rate or you need to enable edge driven interrupts to catch when the encoder moves.
Here's an example of each method, the edge driven approach is much more suitable if you can use that as the interrupt only fires when the encoder moves.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: Encoder troubles
Hello Ben,
Thank you for the examples. Unfortunately neither encoder_timer.fcfx nor encoder_edge.fcfx work on my Flowcode 10. The servo still does not move in simulation.
Is there anything different I need to do in Flowcode 10 to make the encoder work with a servo?
Best regards,
Zhmil1789
Thank you for the examples. Unfortunately neither encoder_timer.fcfx nor encoder_edge.fcfx work on my Flowcode 10. The servo still does not move in simulation.
Is there anything different I need to do in Flowcode 10 to make the encoder work with a servo?
Best regards,
Zhmil1789
-
BenR
- Matrix Staff
- Posts: 2207
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 605 times
- Been thanked: 803 times
Re: Encoder troubles
Your maths to do the servo motion from the encoder count looks a little off, what are you trying to acheive there?
Maybe for now just try connecting the servo angle to the encoder count and see how you get on there.
Maybe for now just try connecting the servo angle to the encoder count and see how you get on there.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
medelec35
- Valued Contributor
- Posts: 2288
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 712 times
- Been thanked: 775 times
Re: Encoder troubles
Hello.
Is your issue that you get a compile error as well as simulation issues?
The Servo component is not currently supported on the PICO for any version of Flowcode.
See this topic
It helps to look for issues if as much detail is give as possible.
For example compiler error, or encoder detection issues etc.
"I have some troubles" is very vague and not at all helpful.
We get you have simulation issues, but its always good to compile first, to check if components are compatible.
There are projects posted that can control a servo using timer interrupts ,that could be used as a get around.
I will see if I can find some links.
Is your issue that you get a compile error as well as simulation issues?
The Servo component is not currently supported on the PICO for any version of Flowcode.
See this topic
It helps to look for issues if as much detail is give as possible.
For example compiler error, or encoder detection issues etc.
"I have some troubles" is very vague and not at all helpful.
We get you have simulation issues, but its always good to compile first, to check if components are compatible.
There are projects posted that can control a servo using timer interrupts ,that could be used as a get around.
I will see if I can find some links.
Martin
-
medelec35
- Valued Contributor
- Posts: 2288
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 712 times
- Been thanked: 775 times
Re: Encoder troubles
Attached is controlling a Servo on a PIC using ADC.
It uses the timer interrupt to bit bang a pico pin.
As the interrupt is triggered every 10uS then you should get 151 steps
I have not tested it, but in theory it should work fine.
All you need to do is implement the encoder as per Ben's example.
You won't need to use this method when the servo is fixed.
I don't know if it will be fixed for both V10 & V11 or just V11?
It uses the timer interrupt to bit bang a pico pin.
As the interrupt is triggered every 10uS then you should get 151 steps
I have not tested it, but in theory it should work fine.
All you need to do is implement the encoder as per Ben's example.
You won't need to use this method when the servo is fixed.
I don't know if it will be fixed for both V10 & V11 or just V11?
- Attachments
-
- Servo PICO V1.2.fcfx
- (14.64 KiB) Downloaded 28 times
Martin