Look for value in circular buffer not working

A forums to allow bugs and problems with Flowcode v6 to be reported and resolved.

Moderator: Benj

Zane
Flowcode v5 User
Posts: 195
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 91 times
Been thanked: 75 times
Contact:

Look for value in circular buffer not working

Postby Zane » Tue May 24, 2016 9:36 pm

Hi Ben,

I am having problems with the circular buffers working correctly when looking for a string within buffers. I have two cards, one that is connected to a eb076 touch screen that sends out keystroke commands to a second card that receives those and sends back 2 strings to display messages on the screen. I have found with an earlier program i was working with that was quite small all the "look for value functions" worked fine however with a larger program now i am having problems.
Because information contained is commercially sensitive i have sent a PM to you with the files for the display and controller simulation cards.

Thanks for your help.

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

Re: Look for value in circular buffer not working

Postby Benj » Wed May 25, 2016 9:56 am

Hello Zane,

I wonder if the problem could be the BoostC compiler and the "\xXX" strings.

How about you create a string variable and then assign the hex values your looking for to the variable in a calculation icon like this.

StrVar[0] = 0xB0
StrVar[1] = 0x32
StrVar[2] = 0x97
StrVar[3] = 0xc4
StrVar[4] = 0xb9

Then pass the string to the LookForValue function. The circular buffer component itself is very well tested and I use it all over the place now so I don't think there is a problem here.
These users thanked the author Benj for the post:
Zane (Wed May 25, 2016 10:55 am)
Rating: 5.56%
 

Zane
Flowcode v5 User
Posts: 195
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 91 times
Been thanked: 75 times
Contact:

Re: Look for value in circular buffer not working

Postby Zane » Wed May 25, 2016 10:55 am

Hi Ben,

Thanks for this info and your help, i will give that a try over the next couple of days and will let you know how i get on.

Cheers

Zane

Zane
Flowcode v5 User
Posts: 195
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 91 times
Been thanked: 75 times
Contact:

Re: Look for value in circular buffer not working

Postby Zane » Fri May 27, 2016 7:48 am

Hi Ben,

I have tried enter the data into a string variable and passing this into the "look for value" function. The function where the code checks for manual or auto messages now works however when checking for the messages on line 1 or line 2 it fails every 20 to 50 times it is switched between and manual and auto even though the data in the buffers is correct. I have tried various different methods when using the look for value but still get the same results. I have sent the code to you via a PM with the changes i have made.

I wanted to try this on a 16 bit pic to see if this make any difference but am also having problems where the screen fails to work(separate post).

Any help would be great :D , i have been working on this for the last month but have made no head way.

Thanks

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

Re: Look for value in circular buffer not working

Postby Benj » Thu Jun 16, 2016 11:25 am

Hello Zane,

I have looked at your program but cannot see where you are referring to that has the problem. The program is quite large and so i'm guessing there is a minor bug in the logic somewhere.

Please can you try and create a simple example that shows the problem. As I say I have used the circular buffers extensively and not come across an issue.

Zane
Flowcode v5 User
Posts: 195
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Has thanked: 91 times
Been thanked: 75 times
Contact:

Re: Look for value in circular buffer not working

Postby Zane » Fri Jun 17, 2016 8:40 am

Hi Ben,

Please read the following blurb, it is rather long but explains in detail with what is going on. I have included two programs, one that works correctly for the "look for value" function and one that does not, however the one that does work has other issues of its own that are explained. A third program that i sent you earlier is the one that sends strings to these programs for processing (for test purposes).

OPERATION

The objective of the program is to send keystroke commands from a touch screen keypad and send them out to another PIC for processing before being sent to the machine it is controlling. The card also receives strings of data from the other PIC that it has got from the machine it controls. It is only concerned with two sets of strings that it receives and these are status messages of the machine, one string for the top line and the second for the bottom line. All other strings are ignored.

The operation of the program is straight forward. For the purpose of looking at the issues I am having, only the comms and main macros need to be considered. The comms macro receives incoming strings of data and places each of them into 4 circular buffers. Buffer 1 is for the message on the top line, buffer 2 is for the message on the bottom line and buffers 3 and 4 can be ignored as they are only used for center alignment of the messages on the display. The end of each string always has a 0X97 third byte from the end of the string so after the next two characters are received a variable MessageReceivedOk is set.

In the main macro the program sits there in a loop doing essentially nothing if no keys are pressed, just waiting for incoming messages. Once a complete string is received the data is processed. “Look for value” functions are used to determine if valid data has been received. If valid data has been received for line 1 the data in buffers 1 and 3 are retained and buffers 2 and 4 are cleared. When valid data for line 2 is received the data in buffers 2 and 4 is also retained. After this the contents of all the buffers are read to display the messages on lines 1 and 2 and then they are cleared waiting for the next lot of incoming data.

FAULT

Scroll down in the main macro, there are a couple of large comment boxes highlighting where the issues are located. In the program “Display not working” the trouble that is being experienced is that when the “look for value” function is being used on a circular buffer. The message on line 1 works every time valid data is present however when valid data is present for line 2, every now and then (every 20 to 50 times) the “look for value” for line 2 fails. In the program attached buffer 4 was used instead to display the data that is written to it for each of the messages and displayed on the screen. When the “look for value” fails the data displayed on the screen is correct. This function has been removed but is present in the program posted, “Display working” An output is also placed in the MessageReceivedOk branch to ensure that, that part of the code has been processed too. It is also important to note that when this is simulated in Flowcode it also works every time.
The second program that is attached is a variation on the first “display working”. What has happened when this program is run on the chip things work in reverse?? The second message is displayed first and the first last but in the code it shows that it should do the opposite. (Normally I would export all components if I get odd behavior like this and import them into a new project and things will work normally). However the interesting thing with this program is that both “look for value” functions work fine and I cannot get it to fault.

SUMMARY

I have left the program in its original form and not condensed as I am wondering if there are problems due to the programs size when it is compiled, all the functions are not working as they should. Also I cannot help but wonder why they second program that has parts of it run in reverse once compiled has the “look for value” functions working correctly every time. I have gone over this many times and am fairly sure that I have not made any stupid mistakes?, especially since everything works fine in simulation.

EXPECTATIONS

I am no expert but have my suspicions as to whether the compiler is at fault. I have no expectations for you to fix this unless you see a stupid mistake that is extremely obvious to spot. I wanted to point this issue out to you in an effort to help you build a more robust product if it is not me at fault. I have also had another project where I have had unexplained behavior on an intermittent basis as well, even though everything works fine via simulation. I am hoping with the launch of Flowcode 7 and the use of Microchips compiler sees some improvement.
I am also keen to try running this on a 16bit PIC and see if this manages to cure the problem.
On the other hand all other projects that I have done using Flowcode have been extremely successful and think that it is a wonderful product.

Thanks
Attachments
DisplayWorking.fcfx
(163.52 KiB) Downloaded 118 times
DisplayNotWorking.fcfx
(155.49 KiB) Downloaded 114 times
These users thanked the author Zane for the post:
Benj (Wed Sep 14, 2016 4:26 pm)
Rating: 5.56%