NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Trying to uncomplicate my head, Building an EEPROM, Shift Register, Display Schema
August 18, 2011 by Ralphxyz |
I thought I should ask this in Noter's great I2C EEPROM thread but there should be a lot of general interest programming tips, so I started a new thread. Please contribute I need everybody's ideas as this isn't going to be so simple to do. Specifically this will be for my Water Curtain. I have 4 Shift Registers working thanks to Rick's and Noter's postings now I have to combine the shift registers with the EEPROM pattern storage to get the display session. I am picturing (please jump in here if you have a good idea) storing patterns in external I2C EEPROMs. First thing is what is a pattern? Well a pattern is composed of a series of 32 bit numbers (my water curtain is 32 bits wide). Sorry this will make the thread kinda long but I think I have to illustrate. The letter "A":
and of course the inverse:
There easily will be hundreds of patterns! The A2 pattern above makes a 4kb text file, using Unix (LF) line breaks and Unicode (UTF-8) encoding. Now I am proposing populating the I2C EEPROM from my pc. I have a DevSys USB-I2C board. I'll need to come up with a Python or PEARL script to build the patterns on the pc and then to populate the EEPROM. Anybody want to help? Now how am I going to store these patterns on the EEPROM? Do I store them as 32bit patterns? Or as 8bit components: Sorry but again for illustration:
This also is a 4kb text file! I do not have any timing parameters so that will add another dimension! I am thinking that I will need a lookup table in say the first 10 or 20 kb of the EEPROM. Or what other method might I use? Then what would this "look up" table look like? There has to be a method of condensing the look up code. So if I have the A1 letter at position 100000 - 104000 (assuming 4kb) how would I reference that? It would be nice to use a multidimension array Location[A1][100000][104000] maybe that structure might work, as you can see I really need your help. Then how do I pull a pattern from the EEPROM? Should I use a Dynamic Array? Then how do I display it? Rick had a suggestion to carlhako in my shift register daisy chain thread that I need him to elaborate on or if any one has any other schema I sure would be interested. Again sorry about the length of this post but it is a little slow in the forum so this gives you all something to think about. I'll take any thoughts. So what do you think, it has to be possible but what might be the most efficient method? Or any method for that matter lets get something to work. Keep in mind my "limited" programing abilities, I put things together better than creating from scratch. Ralph |
---|---|
August 18, 2011 by bretm |
You're not going to store text '1' and '0' characters in the EEPROM, you're going to store bits. The 24LC256 EEPROM is 32k x 8 bits, so you're going to be reading and writing bytes. That's 8 bits. So you'll need 4 bytes for each pattern row, plus, let's say one more byte for the row "on" duration. That's 5 bytes per pattern row. A pattern consists of multiple rows, so a pattern could be one byte to indicate the number of rows, then the 5 bytes per row. You'll need two bytes to identify the address of a pattern (since the EEPROM is 32k bytes). So a complete "script" could just be a two-byte count of pattern offsets (number of patterns) followed by two byte pattern address for each pattern than you want to display. I wouldn't mess with complicated C data structures. It's total overkill. I would just do something like this:
|
August 18, 2011 by bretm |
Step 5 should be "Display the pattern row. Pause for the duration." |
August 18, 2011 by bretm |
|
August 18, 2011 by bretm |
Using this scheme, pattern A2 is 60 bytes, plus 2 bytes for each time you use it. |
August 18, 2011 by Ralphxyz |
Thanks bretm, I will be trying your methods. I suppose a lot of this question is outside the realm of microprocessor programming. Maybe I'll break up the question in other threads. Ralph |
August 18, 2011 by BobaMosfet |
Ralph, The simplest way to store this, knowing that it is 48-bytes per character, is as a consecutive string of bytes, and then use simple pointer arithmetic to access the start of each letter in a variable when you need to access it. 26 letters only take a little over 1200 bytes.
Then mask to extract each bit you want and go from there. It can be cleaner/tighter; I wrote it this way for educational purposes. Hope this helps. BM |
August 19, 2011 by Ralphxyz |
Thanks BM, this will work for this font but there will be images also like a diving dolphin or other shapes, I am trying to do some math modeling to see how big a pattern might be. The 32 x 12 A1 and A2 letters were just random selections for illustration. I like your schema, and what bretm has suggested so far, I will try to incorporate it all. This was just my preliminary question I am just starting to think about how I am going to do this so wanted to start to get some feed back. I am probable going to get the pc talking to the EEPROM first before I do much on the mcu/display side. Ralph |
August 19, 2011 by BobaMosfet |
Ralph, Step back, think about your answer, look at what I've provided. This is a learning exercise :P . Can you not see that it would be useful for you to make commonalities between your blocks? letters of a certain dimension, figures of a certain dimension, and so forth, and then just change the values in the algorithm depending on what you're trying to access? Balance man. Balance. Resource .v. Performance- THAT is the name of the game. I've given you a the most important rudiments of an algorithm that uses the least resources while offering significantly high performance. BM |
August 19, 2011 by BobaMosfet |
Did I really say that.... :: hand to forehead :: sheesh BM Ralph, yeah, you're on the right track; just find commonalities; it'll help you write more useful, algorithms. Thank God it's Friday. |
August 20, 2011 by Ralphxyz |
Thanks BM, saying this is a [quote] " learning exercise" [/quote] is a true understatement. I understand your method of modularizing the commonalities. Believe me once I start on this I am gong to need lots of help. I am encouraged as so far I can follow bretm's and your methods. Now to see if I can apply them. I just got my newest solenoid valves and in laying it out it looks like I will have 80 columns eventually. I am working with 32 for now just to see if I can make some recognizable patterns. The same code "should" be able to expand to 80 columns. This is so challenging but a lot of fun. Ralph |
August 21, 2011 by BobaMosfet |
Ralph, I think mostly, you just need a few 'Aha!' moments where things that are murky with how RAM works, how you access it, and what a compiler is actually doing to get you where you want to go, become clear. I think once you start understanding the mechanics of how things work, you'll start realizing just how powerful C is, and why (realistically) it is the most powerful programming language to date. It's the one language that doesn't get in your way, no matter what you're trying to do-- and know almost all of them. For purposes of 'growth', set your column width as a constant (use a define), that way, when you are ready to change it, you can just change a number. BM |
Please log in to post a reply.
Did you know that our customers love us? Learn more...
|