Quad Encoder!

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

Hi Jorgen,
I believe I know whats going wrong with V5?

The switch component to do with Switch(1) (port A1) could be bugged?
WaitUntilLow or WaitUntilHigh functions don't work
Switch(0) is working as expected
Attached is a is a workaround until issue can be resolved

Can you let me know if it works like V4.5 please.

Martin
Attachments
Bourn5_Modified.fcf
(16.09 KiB) Downloaded 284 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

I had a look at the assembly of a switch routine which is not working and this does not make sense to me:

Code: Select all

label1
BCF STATUS, RP0
DECF FCD_SWITCH_00055_1_switchval, W
BTFSC STATUS,Z
RETURN
MOVLW 0x02
ANDWF gbl_porta, W
MOVWF FCD_SWITCH_00055_1_switchval
GOTO	label1
But nothing to store result in DECF FCD_SWITCH_00055_1_switchval before MOVLW 0x02 ?

the reason switch connected to port A0 works is because if A0 =high so 1 is AND with portA0 then result is 1
the 1 is decremented from DECF FCD_SWITCH_00055_1_switchval, result is placed in W
Since result is not stored in the DECF FCD_SWITCH_00055_1_switchval, this stays at the value of switch.
so in the case of switch connected to A0, 1-1 = 0, so Z=0 and switch is detected as high - all is ok.

However if Switch connected A1 is pressed since FCD_SWITCH_00055_1_switchval = 2, then 2-1 =1. Result is stored in W
so this value will never reach 0 so Z will not be true.

So my conclusion is any bit higher than 0 that has a switch connected to it and using waitUntill component will not work with FC5

Hope I have correctly read the ASM. Im not 100% of being right of course :P
perhaps someone can verify my logic please?

Martin
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Quad Encoder!

Post by Benj »

Hello Martin,

Aha thanks for the bug spot and looking into the assembler.

I have managed to fix the bug now so that the wait until macros now work correctly with the switch and switch bank components.

The switch was being read in and then compared against the polarity mask which could only ever be 0 or 1. I have modified the code now so that the polarity mask should now always match the bit weight of the bit being checked.

To update simply download the files below and drop them into your "Flowcode\v5\Components" directory before running Flowcode.
Attachments
FC5_PIC_SWITCHbank.c
(9.06 KiB) Downloaded 289 times
FC5_PIC_SWITCH.c
(7.29 KiB) Downloaded 282 times

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Quad Encoder!

Post by jgu1 »

Hi Both! :D :D :D

1 - 0 to me, hi, hi.

No I´m really glaad you found something. I am not able to look deepere in FC. I am not wise enough to do this. After work I will test it, and you hear from me.

Once again, thank´s to all. :D :wink: :)

Best regard

Jorgen

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

For the bug, well spotted Jorgen.
I'm just glad we got there in the end. That was good team work by all :)
Thanks for the update Ben.
looks like update has solved the issue. So far so good :) , but not fully tested yet.
Hope update does work for you Jorgen.

If your code works on V4.5, I can't see why it won't work with V5.2 after fix.

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Quad Encoder!

Post by jgu1 »

Hi all!

Sorry sorry, it did not solve the problem. Could you please take a look at the files again :( :(

It act the same way..

Ben and Martin, isn´t possible for your expert´s to copy something in the v.4 SWITCH file over to ver 5?

regard

Jorgen.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Jorgen

Ive just re tried your program (bourne5) with the new switch components.
It now works fine with the switches in active high or low. with the old versions it didnt work with active high

The fact I'm using a different encoder is certiainly making some difference to the tests.
Alpha Encoder 2.jpg
Alpha Encoder 2.jpg (75.87 KiB) Viewed 13036 times
Ive used my test pod to take a sample of the waveforms im getting.
I set up up to trigger on rising edge on pin A0 when i started to spin the encoder and turned it a few times while it sampled.
1 in 10 people understand binary, the other one doesn't !

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

I also have tested 4 switch components connected from A0 to A4 on both WaitUntilHigh and WaitUntilLow.
All now works as expected.

Martin

Edit just tested FC4 switch component, and FC5 now behaves in an identical manor to FC4 .
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

I have also tested my bourns encoder with your original flowchart.
I can confirm that with both FC4 and FC5 LCD dispaly was changing up and down in the same way.

My only comment is the routine works but it does get a bit confused some times on both FC4 and FC5 to if it wants to detect up or down when turning the the same direction especially if pausing during turning.

I could look at producing a non interrupt version using port A0 and A1 and see if its any better?
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Quad Encoder!

Post by jgu1 »

Hello friends! :lol: :lol:

After once again having copied (overwrite) the new files, restarted my computer and compiled programmed the pic,

:D Friends it WORKS!! :D

Now I have a bugless FC Ver.5, (I hope) and can continue my project´s.
Again and again, I want really want to thank you all for your interest and help and support. When I once become expert´s like you, I hope that I can help you too.

Thank´s friend´s

Best regard.

Jorgen

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Jorgen

Great to hear you've got it working. Thanks for letting us know.
After once again having copied (overwrite) the new files, restarted my computer and compiled programmed the pic,
I find when I change/update the component files this method works for me

Close flowcode
Make a copy of the file you are going to change (I rename it file-old.c)
Copy the new file to the flowcode folder.
Then start flowcode.
1 in 10 people understand binary, the other one doesn't !

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Quad Encoder!

Post by jgu1 »

Hi John

Yes it is a good idea to do it that way. I will in future follow your advice. :wink:

But a whole different thing. I thought it would be a good idea if every time there came a change or there was discovered a bug like this, MM had to put patches on the front page of this forum. It is not for sure that everyone has followed this thread and seen there is a fix or a similar case. I suggest "Fix ver.5.2".

Well, John, once again thanks and have a nice weekend.

Here i Denmark it´s raining and I have to work the hole weekend I am a Electronic engineering and working the Bridge Storebælt (bridge between fyn and sjælland) and is responsible for all electronic equipment in the pay toll.
but don´t care, only my FC work´s :D

Best Regard.
Jorgen

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Jorgen

A section in the forum for fixs like this might be a good idea, as you say not everyone may be following this thread, especially if they are not interested in encoders, but the switch component can effect most flowcharts.

Suns out here at the moment, but its been very wet recently
1 in 10 people understand binary, the other one doesn't !

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Jorgen

One problem Ive found with the Alpha encoder now I have mounted it on a small PCB and fitted a knob, is if you turn it too quickly i.e. more that 4 rpm it will miss the pulses and does not increment the count.
Testing on a protoboard it was not easy to spin it too quick as it would come off the board.

I think this is down to it being a cheap component.
Be interested to know if you Bournes exhibits similar behaivior.
Alpha Encoder.jpg
Alpha Encoder.jpg (91.66 KiB) Viewed 12997 times
Connections
Top Left = 5V & Ground
Top Right = Encoder A & b
Bottom Left - Push To Make Switch

These little Adafruit boards are brilliant for small projects
The top & bottom 2 rows are connected horizontaly
The other holes are 5 verticaly same as on a protoboard, I just run some thin wire links on the back of the board.
1 in 10 people understand binary, the other one doesn't !

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

Hi John,
Would you mind testing your encoder with this please:
http://www.matrixmultimedia.com/mmforum ... 85&#p35128

I'm not saying it would work better than the flowchart your using (it may even be worse)?

Just wanted to know how good it works with your encoder.

Thank you

Martin
Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Quad Encoder!

Post by jgu1 »

Hi John!

No, John, My count very well up and down now, no speed limit, both in ver 4 and
5 (With my program still not tested the ohter yet)The only thing I've been forced to make in the V.5 is in the properties for "switch" is to put Debounce down to max 1 ms, whereas in ver 4 it doesn´t care if it is 0 or 10ms. I have a suspicion that Debounce settings did not work right in the V4
But I don´t care, now we use ver5 and it seemed to work there. :D

If you are interested, you can give your address and I will send you a Bourns Encoder free for testing.

In my connection for encoder 3 legs I use:

Middle connected to ground, the 2 other pull up resistor 10K and connected to input.

Best regard.

Jorgen.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Martin

Just tried your flowchart with my Alpha encoder, it works well, I can turn the knob a lot quicker )than with Jorgens program), until it loses track of the counts.

Though it only reads in an anticlockwise direction if starting from zero, but will count down clockwise from any other value till it reaches zero then it stops.
(Direction depends on which way round I have wired the encoder A=6 B=7)

Also works the same with the matrix encoder patched A=6 B=7

Im using an 16F877A PIC
1 in 10 people understand binary, the other one doesn't !

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

Hi John,
Thanks for testing my software :) .

Do you mean it looses counts when gets to zero?

I Deliberately configured flowchart so when the level gets to 0 it can't be reduced anymore.
Likewise can only get to a maximum of 255.

So if starting off at zero and encoder is turned in a direction to reduce, then nothing will happen.

It was originally intended for a volume control, as the original flowchart had visual bars for volume level.

Flowchart can easily be alter to remove upper and lower stops.
Martin

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Martin
Yes thats what i was meant. If you are using it as a volume control it it only needs to work like that.
1 in 10 people understand binary, the other one doesn't !

User avatar
fotios
Posts: 458
Joined: Mon Feb 08, 2010 10:17 am
Location: Greece
Has thanked: 109 times
Been thanked: 117 times
Contact:

Re: Quad Encoder!

Post by fotios »

Hi John
Could you try please this volume control fcf? The program code is similar like this i use in my PGA23120 preamplifier project. Encoder used is a Panasonic and pinout is: "C" in the center, "B" in the left and "A" in the right.
Attachments
Panasonic_v5.fcf
(20.51 KiB) Downloaded 219 times
Best Regards FOTIS ANAGNOSTOU

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Quad Encoder!

Post by medelec35 »

This thread is going to be really useful if anyone is wanting to use an encoder :)
With encoders from several diffident people!

Here is another version which does not have any limits set.
It also shows if encoder is moving clockwise or Anticlockwise or stopped.

A is portB6, B is PortB7 & C is 0V.

It also has outputs to port A showing status.

Eg.
Port A0 is high only when encoder is rotating anticlockwise.
Port A1 is high only when encoder has stopped.
Port A2 is high only when encoder is rotating clockwise.
Encoder V3.png
(8.36 KiB) Downloaded 7205 times
Attachments
Rotory Encoder 16f877A V3 .fcf
(23.48 KiB) Downloaded 230 times
Martin

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Martin

Nice one. Works very well
1 in 10 people understand binary, the other one doesn't !

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Quad Encoder!

Post by JohnCrow »

Hi Fotis

Ive tried your flowchart on a 16F877A (dont have a 887) using a 4MHz xtal
This works fine.
Panasonic_v5-4MHZ.fcf
(20.47 KiB) Downloaded 252 times
1 in 10 people understand binary, the other one doesn't !

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Quad Encoder!

Post by jgu1 »

Hi all! :D

The encoder program I had made was for a friend who had built himself a preamplifier and connected D/A converter for Vol ajd. And the D/A conveter, was connected port C on the Pic as driver for this D/A converter.
The program I made would be locked into one of the macros UP/DOWN until there was again turned on the encoder. It does not matter for this purpose since it was only used for this purpose.
I have for fun tried to make the same program but with interrupt and used timer0. Here you have the possibility to add
some program, and can be used for other things.

BOURNS ENCODER.

Best regard

Jorgen
Attachments
Bourn5_Interr..fcf
(14.73 KiB) Downloaded 208 times

Post Reply