Compare the numbers saved in eeprom of two PIC
Moderator: Benj
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Compare the numbers saved in eeprom of two PIC
Hello everyone,
As I can compare a number that is recorded in a pic (eeprom) with other numbers recorded in a second pic (eeprom) for not repeat? eg. . . .
PIC1 (18F4685) addres0 data 1
addres1 data 5
addres2 data 8
addres3 Data12
Numbers stored in the EEPROM of PIC1: 1,5,8,12
PIC2 (18F4685) addres0 data 3
addres1 data 7
addres2 data 9
addres3 data 1
Numbers stored in the eeprom PIC2: 3,7,9,1
As you can compare the two PIC and know that the number 1 is repeated?
THANKS
ELECTRON67
As I can compare a number that is recorded in a pic (eeprom) with other numbers recorded in a second pic (eeprom) for not repeat? eg. . . .
PIC1 (18F4685) addres0 data 1
addres1 data 5
addres2 data 8
addres3 Data12
Numbers stored in the EEPROM of PIC1: 1,5,8,12
PIC2 (18F4685) addres0 data 3
addres1 data 7
addres2 data 9
addres3 data 1
Numbers stored in the eeprom PIC2: 3,7,9,1
As you can compare the two PIC and know that the number 1 is repeated?
THANKS
ELECTRON67
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Hello everybody,
Anyone know if this can be done?
Thanks
Anyone know if this can be done?
Thanks
- 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: Compare the numbers saved in eeprom of two PIC
Hello,
Sounds like you would need to have a loop which cycled through each location of the EEPROM. For each local location you would then have to scan all locations of the remote device to see if they contained the same value. You could cut down the number of cross chip reads by first reading the entire EEPROM data from device 2 into the RAM of device 1 and then use device 1 to do all the checking.
Sounds like you would need to have a loop which cycled through each location of the EEPROM. For each local location you would then have to scan all locations of the remote device to see if they contained the same value. You could cut down the number of cross chip reads by first reading the entire EEPROM data from device 2 into the RAM of device 1 and then use device 1 to do all the checking.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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: Compare the numbers saved in eeprom of two PIC
Hi electron67
I have put together a flowchart that should do what you asked for in your first post as a starting point.
With 1 in both arrays the following is shown: You will need to add the EEPROM reading function.
If you get stuck I can help you with that.
Can you let me know how you get on.
Martin
I have put together a flowchart that should do what you asked for in your first post as a starting point.
With 1 in both arrays the following is shown: You will need to add the EEPROM reading function.
If you get stuck I can help you with that.
Can you let me know how you get on.
Martin
- Attachments
-
- Repeat Counter.fcf
- (15 KiB) Downloaded 295 times
Martin
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Thanks for the replies Benj and Martin, I can't make a diagram with Flowcode, because I not have idea how to start. I think what you describe Benj is what I need.
The idea is record in a PIC1 eeprom 20 numbers and write to the EEPROM of PIC2 other 20 numbers; then check that the numbers recorded in the eeprom PIC1 with any recurrence of the PIC2; I need not repeat the numbers. I think Benj is as described, it would have to make a loop with the PIC1 and PIC2 to compare the eeprom each PIC that the numbers are not repeated.
this can be done ?
Thanks
The idea is record in a PIC1 eeprom 20 numbers and write to the EEPROM of PIC2 other 20 numbers; then check that the numbers recorded in the eeprom PIC1 with any recurrence of the PIC2; I need not repeat the numbers. I think Benj is as described, it would have to make a loop with the PIC1 and PIC2 to compare the eeprom each PIC that the numbers are not repeated.
this can be done ?
Thanks
- 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: Compare the numbers saved in eeprom of two PIC
Hello,
Yes this can be done,
1) Look at Martins example it shows how to do the comparison from a single chip.
2) You will need a way of transferring data between chips (comms) I suggest using the RS232 component and the hardware UART pins, RX1 to TX2 and TX1 to RX2.
3) You then need a nice way of requesting a value so you essentially need a master slave type operation where device 1 can request a byte from device 2.
4) Device 2 needs to serve out the value when requested.
5) Adopt the program from prog 1 to include the actual values requested from the second device.
Lots of steps so try and break up each step into smaller bite size pieces, this is much easier then trying to work out the entire thing in one go.
Yes this can be done,
1) Look at Martins example it shows how to do the comparison from a single chip.
2) You will need a way of transferring data between chips (comms) I suggest using the RS232 component and the hardware UART pins, RX1 to TX2 and TX1 to RX2.
3) You then need a nice way of requesting a value so you essentially need a master slave type operation where device 1 can request a byte from device 2.
4) Device 2 needs to serve out the value when requested.
5) Adopt the program from prog 1 to include the actual values requested from the second device.
Lots of steps so try and break up each step into smaller bite size pieces, this is much easier then trying to work out the entire thing in one go.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Thanks I will try what example you gave me and explained.
Thanks
Thanks
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
This is the program I'm using the PIC18F4685 (Here only I use one PIC and one EEPROM)
The idea is to record from zero to two hundred ( 0-200 ) , the numbers can be recorded without logic, but not repeated in the EEPROM memory of the PIC ; after the numbers are read in the order they were recorded in the EEPROM memory ; the problem I have is that I get to number 50 and Flowcode ( Flow5 and Flow6 ) no longer compiles ; that I can do to simplify the program and to record the 200 numbers.
The logic is as follows : Press Button 1 to start recording the numbers.
it should make number 2 digits or 3 digits ( 02, 07 , 25, 195, 123 , 15, etc. ) after entering digits press # to record , if not required to record the 200 numbers, press 00 and # is stop recording .
To start calling numbers recorded press BOTON 2 (START) to calling the next number is pressed SIG SEC.
I will appreciate if you can help me to complete this program. I do not understand the language C.
Thanks
The idea is to record from zero to two hundred ( 0-200 ) , the numbers can be recorded without logic, but not repeated in the EEPROM memory of the PIC ; after the numbers are read in the order they were recorded in the EEPROM memory ; the problem I have is that I get to number 50 and Flowcode ( Flow5 and Flow6 ) no longer compiles ; that I can do to simplify the program and to record the 200 numbers.
The logic is as follows : Press Button 1 to start recording the numbers.
it should make number 2 digits or 3 digits ( 02, 07 , 25, 195, 123 , 15, etc. ) after entering digits press # to record , if not required to record the 200 numbers, press 00 and # is stop recording .
To start calling numbers recorded press BOTON 2 (START) to calling the next number is pressed SIG SEC.
I will appreciate if you can help me to complete this program. I do not understand the language C.
Thanks
- Attachments
-
- SELECT4685secV16.8.fcf
- Program
- (1.06 MiB) Downloaded 318 times
-
- 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: Compare the numbers saved in eeprom of two PIC
Hi Enrique,
I have taken a look at your flowchart, and it's far to big and inefficient to be practical.
What Ben said:
Lets take the reading of each EEPROM address.
Don't use a separate macro for each address.
Only use a single macro that will cover all addresses.
The trick is to use an array to store the values.
E.g if reading from address 0 to 20 then have a 20 element array called EEPROM_Data.
An array is created when you add the name of a variable but place square brackets with the array size straight after the name.
Using the array to say store EEPROM data you would use another variable called Address for example see attached flowchart.
Once you have reduced flowchart size and call macros by using arrays instead of single variables, re-post flowchart, and I will take another look.
Martin
I have taken a look at your flowchart, and it's far to big and inefficient to be practical.
What Ben said:
is very good advice.Benj wrote:try and break up each step into smaller bite size pieces, this is much easier then trying to work out the entire thing in one go.
Lets take the reading of each EEPROM address.
Don't use a separate macro for each address.
Only use a single macro that will cover all addresses.
The trick is to use an array to store the values.
E.g if reading from address 0 to 20 then have a 20 element array called EEPROM_Data.
An array is created when you add the name of a variable but place square brackets with the array size straight after the name.
Code: Select all
E.g EEPROM_Data[21]
Once you have reduced flowchart size and call macros by using arrays instead of single variables, re-post flowchart, and I will take another look.
Martin
- Attachments
-
- Read EEPROM with array.fcf
- (10.5 KiB) Downloaded 301 times
Martin
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Hi Martin,
simplify the flow chart, I started with a group of 10 numbers; in the same flowchart are introduced for comparison is not repeated, if a number is repeated the correct number is reintroduced, also verifies that does not exceed the number 200. The comparison number take the simple path for now are 10 issues and no problem; but when arriving at number 200, I think it will complicate.
Thank
simplify the flow chart, I started with a group of 10 numbers; in the same flowchart are introduced for comparison is not repeated, if a number is repeated the correct number is reintroduced, also verifies that does not exceed the number 200. The comparison number take the simple path for now are 10 issues and no problem; but when arriving at number 200, I think it will complicate.
Thank
- Attachments
-
- Read EEPROM with arrayV1.0.fcf
- FLOWCHART
- (110.2 KiB) Downloaded 308 times
-
- 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: Compare the numbers saved in eeprom of two PIC
Hi Enrique,
Have I got this correct:
You press button 1 to start recording.
you enter a number on the keypad.
there is a check to see if the number has already been recorded.
If has not then it will be stored in EEPROM
If it has already been recorded then its rejected and just wait for the next entry on the keypad.
when all numbers have been recoded, a max of 200 sets of numbers or when # is pressed then store all the non rejected numbers retained on EEPROM.
So if numbers recorded are 02,34,34,56
the just 02,34 & 56 are stored within EEPROM?
If the above is not correct, then can you stated in great detail step by step what you want to do.
Martin
Have I got this correct:
You press button 1 to start recording.
you enter a number on the keypad.
there is a check to see if the number has already been recorded.
If has not then it will be stored in EEPROM
If it has already been recorded then its rejected and just wait for the next entry on the keypad.
when all numbers have been recoded, a max of 200 sets of numbers or when # is pressed then store all the non rejected numbers retained on EEPROM.
So if numbers recorded are 02,34,34,56
the just 02,34 & 56 are stored within EEPROM?
If the above is not correct, then can you stated in great detail step by step what you want to do.
Martin
Martin
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Hello Martin
this is correct, the problem I see is when you are comparing numbers 50-200 above, it can be done with the function "IF" used to "OR" to compare each variable with the remaining 199; I think doing it this way is very extensive ?
Enrique
this is correct, the problem I see is when you are comparing numbers 50-200 above, it can be done with the function "IF" used to "OR" to compare each variable with the remaining 199; I think doing it this way is very extensive ?
Enrique
- SteveM
- Posts: 55
- Joined: Tue Mar 25, 2014 2:09 pm
- Has thanked: 28 times
- Been thanked: 65 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Hi Enrique,
This little set of Macro's might help simplify your solution... A quick explanation...
We are testing values between 0 and 200 - i.e. they will fit inside a single byte. We want to store whether or not a given value is used - a 'true/false' value which can be stored in a single bit.
The array 'UsedValues' holds these flags - it only needs 32 array entries, because each array Byte holds the 'true/false' flags for eight different values. Within the macros, we locate the right flag by calculating which Array entry to read, and which bit of that entry to test. These calculations only use bit-shifting and bitwise boolean commands, so they are very fast and economical. This technique can save a lot of valuable program memory compared to using individual variables or a 200 element array - a technique that can be used anywhere that a lot of simple flags need to be stored.
The 'main' macro demonstrates it in use. First call 'ClearValues()' to make sure that all flags are cleared. Then, for each value entered, test its flag using the 'ValueFree()' macro - this returns true if that value is still free (i.e. not used yet). If it is free then you use the 'ClaimValue()' macro to set that value's flag so that you know it has been used.
Best Regards,
Steve.
This little set of Macro's might help simplify your solution... A quick explanation...
We are testing values between 0 and 200 - i.e. they will fit inside a single byte. We want to store whether or not a given value is used - a 'true/false' value which can be stored in a single bit.
The array 'UsedValues' holds these flags - it only needs 32 array entries, because each array Byte holds the 'true/false' flags for eight different values. Within the macros, we locate the right flag by calculating which Array entry to read, and which bit of that entry to test. These calculations only use bit-shifting and bitwise boolean commands, so they are very fast and economical. This technique can save a lot of valuable program memory compared to using individual variables or a 200 element array - a technique that can be used anywhere that a lot of simple flags need to be stored.
The 'main' macro demonstrates it in use. First call 'ClearValues()' to make sure that all flags are cleared. Then, for each value entered, test its flag using the 'ValueFree()' macro - this returns true if that value is still free (i.e. not used yet). If it is free then you use the 'ClaimValue()' macro to set that value's flag so that you know it has been used.
Best Regards,
Steve.
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Thanks Steve,
I appreciate the help, I'll see how to incorporate macro to the flowchart considering the 200 numbers.
Enrique
I appreciate the help, I'll see how to incorporate macro to the flowchart considering the 200 numbers.
Enrique
-
- 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: Compare the numbers saved in eeprom of two PIC
Hi Enrique,
I hopefully have lashed together a Flowchart that does what you want.
I have virally started from scratch.
Its reactively small in size and you can enter a number and only if the number has not been used before it will be saved on EEPROM.
If the number has been repeated, then you will get a warning and number will not be saved: Flowchart is made more efficient because its only using one array of 200 bytes, and it does not read and data from EEPROM.
To start just press switch1
When entering numbers, the display will show: I have not entered 200 numbers, but in theory should work.
When all 200 non repeated numbers or 00 entered then you should see: # = Enter
* = Cancel digit and enter a different one.
Flowchart will still require working on for improved error trapping although I have incorporated some error trapping.
E.g if number entered is>255 then the last digit will be truncated.
Will not allow to enter more than 2 digits if they are zeroes.
If you ant to add call macros that have been removed from the attached flowchart, then just use export macro function form a different flowchart that has the required macro.
Attached flowchart won't be as efficient as Steve's flowchart, as I'm not as clever as he is
Martin
I hopefully have lashed together a Flowchart that does what you want.
I have virally started from scratch.
Its reactively small in size and you can enter a number and only if the number has not been used before it will be saved on EEPROM.
If the number has been repeated, then you will get a warning and number will not be saved: Flowchart is made more efficient because its only using one array of 200 bytes, and it does not read and data from EEPROM.
To start just press switch1
When entering numbers, the display will show: I have not entered 200 numbers, but in theory should work.
When all 200 non repeated numbers or 00 entered then you should see: # = Enter
* = Cancel digit and enter a different one.
Flowchart will still require working on for improved error trapping although I have incorporated some error trapping.
E.g if number entered is>255 then the last digit will be truncated.
Will not allow to enter more than 2 digits if they are zeroes.
If you ant to add call macros that have been removed from the attached flowchart, then just use export macro function form a different flowchart that has the required macro.
Attached flowchart won't be as efficient as Steve's flowchart, as I'm not as clever as he is
Martin
- Attachments
-
- Read EEPROM with arrayV1.1.fcf
- (33.13 KiB) Downloaded 211 times
Martin
- SteveM
- Posts: 55
- Joined: Tue Mar 25, 2014 2:09 pm
- Has thanked: 28 times
- Been thanked: 65 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
He he, thanks - just so long as I ignore the hardware related questions!medelec35 wrote:Attached flowchart won't be as efficient as Steve's flowchart, as I'm not as clever as he is
Weirdly though, I find all this "embedded" stuff strangely nostalgic. It's like going back in time to the mid 1980's '8-bit' era of computing - all the old ZX Spectrum assembly programming techniques I learned in my teens are suddenly useful again! (The real source of Flowcode's power is, of course, the sacrificial offerings of 'blue smoke' from Arduinos we make to the effigy of Clive Sinclair that we keep in the stationery cupboard! )
-
- 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: Compare the numbers saved in eeprom of two PIC
You learn something every daySteveM wrote: (The real source of Flowcode's power is, of course, the sacrificial offerings of 'blue smoke' from Arduinos we make to the effigy of Clive Sinclair that we keep in the stationery cupboard! )
Unfortunately I'm a latecomer into pics.SteveM wrote:t's like going back in time to the mid 1980's '8-bit' era of computing - all the old ZX Spectrum assembly programming techniques I learned in my teens
I did not start to get going until 2009.
Joined forums in 2007, but gave up until 2009.
Martin
Martin
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Honestly I never imagined working with PIC, and if I had not found Flowcode, I would have not advanced in the area of electronics; so far I've done two or three projects that formerly had only in mind and now I can put into practice these projects and largely thanks to the help that is given in forums. . . . . . .
This is really what is needed to simplify the flowchart; honestly lost me a little with the flow chart of Steve , but worth studying . I will at this time implentar flowchart program and test.
Thanks Martin and Steve
This is really what is needed to simplify the flowchart; honestly lost me a little with the flow chart of Steve , but worth studying . I will at this time implentar flowchart program and test.
Thanks Martin and Steve
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Hi Martin
I really appreciate the help;
I now understand in a practical way as you use the functions in the flow chart (not equal the theoretical explanation that practical use)
I understand the function ARRAY [] as used and the logic, I have one doubt, that function has NumberString [5] in the program
Thanks
Enrique
I really appreciate the help;
I now understand in a practical way as you use the functions in the flow chart (not equal the theoretical explanation that practical use)
I understand the function ARRAY [] as used and the logic, I have one doubt, that function has NumberString [5] in the program
Thanks
Enrique
-
- 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: Compare the numbers saved in eeprom of two PIC
Hi Enrique,
If it was not for that the string would not be required.
While typing this I thought of another way without using a string array.
It should take up even less room, See what you think?
The more knowledge gained the easier it gets to create and alter flowcharts so they do exactly what you want them to do.
Is the flowchart posted in the above post working the way you intended?
Martin
The only reason for using string variable is because of this statement:electron67 wrote:I have one doubt, that function has NumberString [5] in the program
using It was one way of displaying 00.electron67 wrote: press 00 and # is stop recording .
If it was not for that the string would not be required.
While typing this I thought of another way without using a string array.
It should take up even less room, See what you think?
That's brilliant.electron67 wrote:I now understand in a practical way as you use the functions in the flow chart
The more knowledge gained the easier it gets to create and alter flowcharts so they do exactly what you want them to do.
Is the flowchart posted in the above post working the way you intended?
Martin
- Attachments
-
- Read EEPROM with arrayV1.2.fcf
- (32.9 KiB) Downloaded 245 times
Martin
-
- Posts: 311
- Joined: Sat Jan 12, 2008 2:08 am
- Has thanked: 104 times
- Been thanked: 47 times
- Contact:
Re: Compare the numbers saved in eeprom of two PIC
Hi Martin,
Now I see more clearly, you still more simplified flowchart; this is what I wanted to do; with one flowchart introduce 200 numbers using the ARRAY function.
I appreciate the help to finish the flowchart and the time to explain how to do it.
THANKS
Enrique
Now I see more clearly, you still more simplified flowchart; this is what I wanted to do; with one flowchart introduce 200 numbers using the ARRAY function.
I appreciate the help to finish the flowchart and the time to explain how to do it.
THANKS
Enrique