Pages

Tampilkan postingan dengan label eureka. Tampilkan semua postingan
Tampilkan postingan dengan label eureka. Tampilkan semua postingan

Jumat, 20 Mei 2016

Energia Using The EEPROM on TI Stellaris and Tiva C Launchpads

[Tonights post is by Ed Smith, participant in the Humboldt Microcontrollers Group]

Im writing this blog post largely because it took me quite a while to figure out how to use the Tiva-Cs EEPROM in an effective way. My hope is that this page will make life easier for future people who use the Tiva-C.

First up, these are the Microcontroller boards were going to be talking about today.




















The Stellaris LM4F120 / Tiva-C TM4C123 Launchpad and the very snazzy TM4C129 Connected IoT Launchpad.

There are plenty of other Launchpads worth talking about, but all of them fall into one or more of two categories: Launchpads I do not have, and: Launchpads containing no EEPROM.
Not having EEPROM makes this article about using the built in EEPROM a bit irrelevant, and if I havent used it I dont like writing about it.

Many programs and projects dont need to use EEPROM. All the variables are either burnt into the flash and never change, or are kept in RAM and updated as needed for that boot. When power is cycled the program starts fresh and off it goes. You dont need your calculator to remember what you did last week for instance.
There are other times when having some storage is extremely useful, calibrating sensors is a wonderful example. The Humboldt Laser Harp for instance uses EEPROM to store the calibration data for the laser sensors, as well as to store the MIDI "Velocity" of the notes. Without EEPROM you would have to either redo the mechanical/physical calibration every time you turned the harp on in slightly different circumstances (which takes 10-15 minutes), or recompile and reupload the firmware every time.
Almost any sort of sensor that requires calibration once in a while is a good use for EEPROM. Things like odometers or hour meters as well.
That brings us to the question of how.

How do I get access to the EEPROM of my microcontroller?
Im glad you asked!
If youre using an Arduino, or a TI Launchpad and the Energia IDE, the process is very simple.
First you include the EEPROM library (At the top of your program, add "#include <EEPROM.h>" without the quotes), then in your program you call EEPROM.read(address) and EEPROM.write(address, value) to read and store values respectively. For example:

This would read the value at address 10 into the someVariable variable, update it, and then stuff it back into EEPROM address 10.
The process is very simple, if your value fits into a single byte. That is to say, 0-255. If your value is 256 it will be stored as 0. If its 260 it will be stored as 4, and so on.
You have to do some bitshifting to split larger variables up into bytes and store the bytes individually, then bitshift it back together when you want to use it. Its very doable, but something of a pain.
There are add-on Arduino libraries that can be used to automate the bitshifting, though I have not used them.
What I have used is a slightly lower level method of EEPROM access on the TI Stellaris and Tiva-C chips.
This method and example still uses the Energia IDE, though I believe the code is more or less the same for TivaWare and the TI Code Composer Studio.

Instead of EEPROM.whatever, you use "ROM_EEPROMRead(variable, start address, length)" and "ROM_EEPROMProgram(variable, start address, length)".

The trick is, the variables you use are long integers (32 bits, 4 bytes) in an array, rather than single bytes.
The same operation as above, but with the ability to count from zero to a bit over four billion. Quite the improvement over 0-255.

You can also use sizeof(someVariable) rather than listing the number of bytes (so ROM_EEPROMRead(someVariable,10,sizeof(someVariable)); instead of 4) this is useful if youre using an array with more than one variable in it.
What I really like about this method is you can stick an entire array in just as easily, rather than the single member array we declared above you can declare an arbitrarily long array. Say 30 members. Then the exact same ROM_EEPROM calls store that entire array.
It does start to get tricky if youre using a number of addresses, the above example code uses address 10 as its starting point, it also uses address 11, 12 and 13, as the address is done by the number of bytes used. That 30 memory long array would use 120 bytes / address slots.
If you arent paying attention and write something else to the middle of that range youre going to be unhappy with the results!
You get 32kB worth on the basic Tiva-C, and 256kB on the Connected Tiva-C, so you can afford to be lavish.
The really entertaining part to me is that if you use the Arduino style EEPROM calls on the TI chips, the EEPROM library is converting them into the unsigned long flavor of call to interface with the TI MCU itself. That means that if youre storing an unsigned long using the Arduino method on TI chips, youre bitshifting it manually into bytes, then the library is bitshifting it back into unsigned longs and storing it. Bit of a crackup if you ask me.

When you do use EEPROM it is a good idea to think about how often it will be written to, if you write to it once per second you only get 27 hours of operation before you hit the rated lifespan. Real world testing of Arduino (Atmega328 MCU) EEPROM has shown it to typically get to well over 1,000,000 writes before it starts throwing errors. Atmel and TI are not willing to guarantee that youll get a million writes though.
Reads are free, read the EEPROM as often as you want, but try to keep the writes within reason. If you write once per minute youll get ~69 days of operation per the spec, or 694 days if your EEPROM does the >1 million writes many seem to. Once an hour on average gives you a very long lifespan indeed, a bit over 4,000 days per spec or 40,000 if youre lucky. Thats 11 to 110 years, which should be enough.

If you made it this far through this wall of text, congratulations! My next post will have more pictures.
I hope this was an interesting read and/or helped, look for a blog post about the Humboldt Laser Harp coming in the near future. This coming blog post will include some (most? all?) of the code for the laser harp, including the EEPROM bits.

--Ed Smith

**********
Read More..

Senin, 25 April 2016

Humboldt Makers Group At Eureka Craft Fair

The Humboldt Makers Group had a tech demo and information table today at the Humboldt Makers Street Fair, an arts and craft fair in Eureka, California.

The arts and craft street fair was organized by Origin Design Lab from Eureka, and it was the 4th annual fair for them. Several blocks of 2nd Street in the Old Town section of Eureka hosted arts and crafts booths and a variety of local musicians. The Humboldt Makers Group had a table there to raise the visibility of the group in the local community and to encourage participation in the Humboldt Makers monthly meetings from 6 to 8 PM at 1385 8th Street in Arcata. We also had the brand new Humboldt Laser Harp (HLH) on the table to amaze and entertain passersby.

Although most of the public walking around to the different booths and tables appeared to be tourists or shoppers looking at the arts and crafts for sale, rather than makers, it was worthwhile for us to have a table at the event. We did talk with a few people who seemed interested enough in the maker group to come to future monthly meetings. These interested people ranged from young students who wanted to learn about electronics but didnt have much money or drivers license to people who took a smartphone picture of the Humboldt Makers Group sign and said they wanted to come to meetings to people who seemed interested in the makers but didnt appear committed to getting involved with the group.

Having these people stop by the table to talk with us simply reinforced what Ive found to be true in many places. Every maker event and tech unconference Ive participated in over the past ten years has involved talking with people at the event who say they just heard about the event (which was of high interest to them) the day before, or they ask how long weve been around and why its so hard to find out about us, or they tell me they were sure there were no other people like them (a maker or a tech enthusiast) in the area because they sure didnt know of any. Im firmly convinced that a combination of three things can greatly strengthen and expand the community of makers or tech enthusiasts in an area.
  1. Establishing regular in-person events for either the maker community or the tech enthusiast community.
  2. Organizing and facilitating event activities which are of interest to the people who show up and participate in the event.
  3. Extensively promoting, communicating and marketing the events and the groups behind the events so that as many potentially-interested people as possible find out about them. A big part of this involves personal invitations to people to participate in an event.
Maker Faire -- Bay Area, CA
No one I talked to at todays event knew what the maker movement is and only a couple had heard of the Maker Faire in the Bay area. This was partly because people at todays event were there for an arts and craft street fair. But the lack of awareness also shows a need for more promotion and education about makers and Maker Faire. A dedicated core group of people can greatly raise the visibility in Humboldt County of the maker movement, but we one or two new people in the group who are good at marketing and promotion, and we need sponsors that enable us to effectively promote the Humboldt Makers Group.

First public display of Humboldt Laser Harp
The HLH demo went fairly well, especially considering that physical construction of the harp was started last week, and it first became playable yesterday. Having an outdoor, midday venue to demo it also presented challenges, especially in terms of the changing sunlight affecting the light sensors and their correct calibration. Concerns about burning out the dollar store lasers used in the HLH caused us to periodically power down the lasers to try and make them last longer. Powering down the lasers creates an interesting phenomenon. Within ~ two minutes of powering down the lasers, someone would come to our table and ask "Whats the Humboldt Laser Harp?" Which, of course, meant we had to power them back up! It was worth it though, because it was fun to watch them play the harp and be amazed at how it works. A robust and versatile harp will be an excellent promotional tool for the Humboldt Makers Group and should be displayed to the general public as much as possible. 

Ed Smith and I thought of quite a few improvements wed like to make on the Grip-Strut version of the HLH. Ed is much more familiar with both the hardware and software of the HLH than am I, so Ill let him explain to Nick and others what will be most effective at improving the HLH. However, below is my understanding of HLH stuff we should figure out and work on.
  1. Reduce ambient light reaching the light sensors.
  2. Improve alignment of lasers.
  3. Modify software so the twelve lasers can all be calibrated to have the same sensitivity or span or whatever the correct term is.
  4. Find better quality, but still reasonable cost, lasers to replace the dollar store lasers.
  5. Make a dark enclosure for the HLH to reduce daylight hitting light sensors and to make laser beams (more) visible outdoors during daytime demos.
  6. Equip the HLH with LEDs that are influenced by the music or breaking of the laser beams.
  7. Add hardware and software that gives improved musical capabilities to the HLH.
  8. Consider building two small laser harps for display with the HLH so three people can experiment with laser beam music at the same time during public demos.
Well probably have the HLH at next weeks Humboldt Microcontrollers Group meeting on Thursday. So if you want to see it in action (and hear it in action), or if you want to contribute in some way to the HLH group project, consider participating in this Thursdays meeting.

**********
Read More..