Pages

Tampilkan postingan dengan label uno. Tampilkan semua postingan
Tampilkan postingan dengan label uno. Tampilkan semua postingan

Selasa, 03 Mei 2016

Programming Arduino Uno Hardware Memory Types

In a previous post, I referenced a Linux Journal article looking at Arduino code development from a programmer’s viewpoint. Today’s ‘Arduino programming’ post will address what types of memory hardware are in the Arduino Uno and a little bit about how those different types of memory are used.
Arduino Uno hardware components (from Zenbike.com)

All the memory of a standard Arduino Uno R3 board is found in the Atmel ATmega328P microcontroller (MCU). If you look at the Arduino Uno Zenbike photo on the right that has the Arduino hardware components labeled, you can see where the microcontroller is located on the board. To begin understanding Arduino programming from a hardware standpoint, we need to know what chunks of memory hardware are inside that Atmel MCU.

The ATmega328P has three types of memory hardware:

  • 32 KB of In-System Programmable (ISP) Flash program memory
  • 2 KB of SRAM (Static Random-Access Memory)
  • 1 KB of EEPROM (Electrically Erasable Programmable Read-Only Memory) 

Memory and CPU from ATmega328P block diagram
ISP flash memory is where most of programming is stored. The Atmel MCU in the Arduino Uno has 32 KB of ISP flash. This is more room for program storage than some MCUs, especially other 8-bit MCUs, but there are many MCUs that have more memory. So if you’re working with a complex program on the Arduino Uno and run out of storage space, one option might be to use a different MCU that has more program memory capacity. For more info regarding the specifics of ISP flash on the Atmel AVR MCUs, see Atmels application note about that topic. Heres how Adafruit describes the ATmega328s flash:
“Flash memory is used to store your program image and any initialized data. You can execute program code from flash, but you cant modify data in flash memory from your executing code. To modify the data, it must first be copied into SRAM. Flash memory is the same technology used for thumb-drives and SD cards. It is non-volatile, so your program will still be there when the system is powered off. Flash memory has a finite lifetime of about 100,000 write cycles.”
The ATmega328P’s 2 KB of SRAM is used in three main ways in the Arduino (info from above Adafruit link):
  • “Static Data - This is a block of reserved space in SRAM for all the global and static variables from your program. For variables with initial values, the runtime system copies the initial value from Flash when the program starts.
  • Heap - The heap is for dynamically allocated data items. The heap grows from the top of the static data area up as data items are allocated. 
  • Stack - The stack is for local variables and for maintaining a record of interrupts and function calls.”
If you’ve gotten to the point where your MCU project’s program is controlling many items, receiving lots of inputs and just generally doing a lot of work, you might start taxing the SRAM. If that happens, or maybe to prevent that from happening, you might want to read Adafruit’s guide to optimizing use of SRAM, which says,
“SRAM is the most precious memory commodity on the Arduino...SRAM shortages are probably the most common memory problems on the Arduino...If your program is failing in an otherwise inexplicable fashion, the chances are good you have crashed
Hackaday -- CPLD shield with 2 MB SRAM
the stack due to a SRAM shortage. There are a number of things that you can do to reduce SRAM usage. These are just a few guidelines
...”
If you think you’ve crashed your Arduino because of program complexity, especially a program which might be expecting a lot in the areas of static data, heap and stack, try some of Adafruit’s suggestions for improving SRAM use. Also, because SRAM is the “most precious memory commodity on the Arduino,” you may want to consider a shield that provides more SRAM. Hackaday has a post showing a CPLD (Complex Programmable Logic Devices) shield that increases SRAM from the standard 1 KB by three orders of magnitude up to 2 MB.

Tronixstuff.com has a pretty good post about what the 1 KB of EEPROM in the Arduino Uno can be used for.
“EEPROM...is a form of non-volatile memory that can remember things with the power being turned off, or after resetting the Arduino...we can store data generated within a sketch on a more permanent basis...where data that is unique to a situation needs a more permanent home. For example, storing the unique serial number and manufacturing date of a commercial Arduino-based project – a function of the sketch could display the serial number on an LCD, or the data could be read by uploading a ‘service sketch’. Or you may need to count certain events and not allow the user to reset them – such as an odometer or operation cycle-counter.”  
If you find yourself needing more than 1 KB for storing data, there are EEPROM shields like the one shown at the left. However, as mentioned above, if memory capacity becomes an issue, you should first determine if a different MCU with more internal memory might be more appropriate for your use case.

Arduino beginners don’t need to be too concerned about where the different parts of their programs and data are being stored while they’re learning how to make an LED blink or doing the early Blum tutorials. As your Arduino programs get larger and more complex, however, you’ll probably want to put more effort into managing memory use on your Arduino. If this memory hardware guide for your Arduino doesn’t point you to a helpful resource for that memory management, you can put Google to work finding other resources for you.

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

Rabu, 13 April 2016

Arduino Uno vs TI LaunchPad MSP430 edition

[Post today by Ed Smith, Member of the Humboldt Microcontrollers Group]

Today Im going to compare the well known Arduino platform to a relative newcomer, the Texas Instruments (TI) LaunchPad.

Im writing this with the assumption that you, the reader, have at least a vague idea what a microcontroller is and are curious about them.

Arduino Uno (Atmega328P)

There are a lot of Arduinos out there (link), were going to focus on the Uno as its the gold standard of Arduinos. You can get smaller Arduinos, cheaper Arduinos, more powerful Arduinos, but it all centers on the Uno. This is an Uno (photo from Arduino.cc):


For the full specs, click here.

An Arduino Uno will run you between $25 and $30 depending on where you buy it. This gets you an Arduino Uno only; youll need to buy a USB-A to USB-B cable to plug it into your computer, so figure $30-$35 for Uno+Cable.

This gets you 20 IO pins, 6 of which do analog input and 6 of which can do PWM output (pulse width modulation). Should your code crash or you have other reasons to need it, there is a RESET button on the board. There is an LED built into pin 13 for easy testing and/or status reports and/or the MCU version of Hello World!. Disabling this LED if you want to use pin 13 for something the LED interferes with requires cutting a trace or de-soldering the LED.

Arduinos have a lot of expansion options. Boards called shields can be stacked on top of the Arduino board to add features. Ethernet? Sure! Motor control? You bet! WiFi? Yup. GSM Cell Radio? Why not? The full list is too large to list here. Many of them can be stacked on top of other shields as well. Arduinos start to look pretty funny after two or three shields are stacked on them, but its a wonderful ability.

The really cool bit about Arduinos though is the IDE (which stands for something Im sure, but I dont know what). It takes the opaque (to me, anyway) mess of the AVR C language and turns it into a fairly simple, fairly logical language.

Also worth noting is that Arduino is a separate entity from the company that manufacturers the actual microcontroller chip. Atmel makes the microcontroller chip, then Arduino buys the chip and assembles the single-board microcontroller and sells it.

Texas Instruments MSP430 LaunchPad

Now that weve met the Arduino, lets meet the TI LaunchPad (MSP430). One of the more important differences relates to who makes the MCU on the LaunchPad. TI makes it. TI is big, TI is bloody huge. This means that TI can make a microcontroller development board (what an Arduino is too, as a note) for a lot less money than a relatively small company like Arduino can.
This is a TI LaunchPad (MSP430G):
For full specs, click here.

A TI LaunchPad (MSP430) costs $10 with free shipping from TI directly. Thats pretty amazingly cheap. This gets you the LaunchPad, a USB cable (Mini-USB, just like cameras and such) and, in the case of the units I bought in 2012, three MSP430G chips of varying complexity and speed. Ill be talking about the MSP430G2553 in this article, as it is the most powerful of the three and what you officially get with the board. I do not know if you still get the extras now (2014).

You get 16 IO pins, of which 8 can do analog input and 7 can do PWM. You also get a green LED connected to a PWM pin and a red LED connected to a digital IO pin. Both LEDs can be detached from their pins by removing a pair of jumpers. You get a RESET button just like the Arduino, as well as an extra pushbutton that you can use in your projects.

TI puts out an IDE (actually a couple) for programming the MSP430. I have attempted to use it and failed miserably. If youre fluent in C you may have better luck. Thankfully the folks at Energia.ru have ported the Arduino IDE to work with LaunchPads! Theyve ported many libraries as well, so many Arduino programs can be moved between the two platforms very easily. Its not quite a simple copy/paste as the pin names are different, but its close. The LaunchPad also has expansion boards, TI calls them BoosterPacks. They add all sorts of features, just like the Arduino shields do. The BoosterPacks do not, however, stack.

Now that weve met the two, lets compare directly! Im going to list the advantages that each platform has; this is not a comprehensive list.

TI LaunchPad MSP430 Advantages: 
  • Much lower cost. $10+tax and youre set. Ardunos $25+tax+shipping+buy-a-USB-cable cant compare.
  • Better built in LEDs, and a button.
  • Standard header spacing for pins, no odd 0.05" gap to foil breadboard/perfboard projects.
  • Much more flexible PWM controls. The MSP430G2553 uses a 16 bit timer for PWM rather than the Atmega328Ps 8bit timer.
  • Very good low power draw features for long battery life.
  • Replacement chips dont need pre-programming/bootloading before working with the Energia IDE.

Arduino Uno Advantages:
  • Massively huge community support. This is not to be under-estimated.
  • Stackable shields mean the sky is the limit for feature expansion.
  • Capable of 40mA source/sink per pin; this is enough for very bright LEDs. The MSP430 LaunchPad caps out at ~ 4mA.
  • Can run at 5V or 3.3V (or anywhere between 1.8V and 5V if you change oscillators). The MSP430 caps out at 3.6V.
  • More IO pins, 20 vs 16. It might not seem like a huge difference, but I have projects where Ive used 18 of those pins after using a pin expander to gain 8 more.

Either board is an excellent choice for people just starting out in the microcontroller world. Personally I prefer the MSP430 LaunchPad for most things due to the button, LEDs, and cheap replacement cost if I blow it up. I have many, many Arduinos, however, and use them quite often as well.

Its worth noting that both TI and Atmel make a lot of different microcontrollers. TI makes a number of snazzier LaunchPads, and Arduino makes a number of snazzier Arduinos as well. Many of the LaunchPads are Energia compatible; all of the Arduinos are Arduino IDE compatible of course. Many other Atmel MCUs are also Arduino IDE compatible with modifications/expansions of said IDE.

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