Download presentation
Presentation is loading. Please wait.
1
Storing a Program and Data
PICAXE-08M2 Memory Storing a Program and Data Before you can begin programming your Temperature Logger, you will need to understand the three types of memory inside the PICAXE-08M2
2
Three Types Program Memory Random Access Memory (RAM) Data Memory
The PICAXE-08M2 microcontroller inside the Temperature Logger uses three types of memory. These are the Program Memory, RAM, and Data Memory.
3
Bits and Bytes Bit – a single 0 or 1 Byte – eight bits
All data and programs stored in PICAXE memory are written as bits. A bit is a single one or zero. This is the same as a yes and a no or a on and a off. Inside the PICAXE-08M2, each bit is stored as a voltage or no voltage within a memory cell. A bit is very limited, it can only represent a zero or one. We need to store larger numbers than that, so eight bits are grouped together in what is called a byte. The smallest byte is eight zeros, or The largest byte is eight ones, or Although not commonly used in the PICAXE, four bits grouped together is called a nibble. This makes one nibble half the size of one byte (get it?). Since the largest single digit in a bit is one, it is called the base two or binary numbering system. Recall that we use the base ten or decimal counting system, so our largest single digit is nine. Any base ten number can be represented as a base two number. You won’t need to know how this is done in order to use your Temperature Logger, but you will find it is a useful ability as you develop your programming skills. Suffice to say, a byte of represents a zero in base ten and a byte of represents a 255 in base ten. The largest number that can be stored in a nibble is 15. All the memory in the PICAXE is accessed, with a few exceptions, in whole bytes. When using your Temperature Logger, you will only work with whole bytes of data or programs.
4
Program Memory Used to store the operational program Non-volatile
Bytes not accessible The Temperature Logger’s directions about how to operate is called a program. The program is created by you on a PC and then downloaded into the PICAXE. You need to keep a copy on your PC because you can’t upload a PICAXE’s program back to a PC. Once you are happy with a program, you don’t normally change it in the PICAXE. Also, your program does not change the program memory. Your program is static until you create a new program and download it into the PICAXE. Once downloaded into a PICAXE, the program remains in memory even when the battery is disconnected. As soon as the battery is reconnected, the PICAXE begins carrying out the instructions in its program. Since data stored in Program Memory doesn’t get erased when the power is removed, it is called non-volatile memory. The specific form used in the PICAXE is called electrically erasable programmable read-only memory, or EEPROM. EEPROM has the benefit of permanently storing the program while also being capable of being overwritten with a new program. The number of times that you can overwrite your program is limited to at least 100 thousand times. You can also expect your Temperature Logger program of remaining viable for at least ten years. Normally you won’t access each byte in Program Memory. So when you create a program and download it to the PICAXE, software on the PC will take care of which bytes each program instruction is stored. The Program Memory in the PICAXE-08M2 is 2,048 bytes in size. That’s enough room to store a program with 600 lines of instruction. You will only need a small amount of the Program Memory for the Temperature Logger.
5
RAM Memory Used to collect sensor readings
Used to perform mathematical operations Volatile Accessible Random access memory, or RAM is a type of memory that is fast and updated often. The program inside the Temperature Logger will use RAM all the time to store the results of a temperature reading. And since RAM memory is broken into one byte chunks, the largest number that can be stored in a single RAM location is 255. It cannot be used to store negative numbers or fractions. When a PICAXE program needs to perform a mathematical operation, like multiplying two numbers, the results are stored in RAM. So anywhere when numbers need to be created or updated, the results are stored in RAM. The problem with RAM is that a number stored in it evaporates away when the power is removed. If it is important to remember a number for a long period of time, then it must be copied from RAM and into EEPROM. Because a number stored in RAM is erased when the power is removed, this type of memory is called volatile. Since the program needs to know where it is creating and manipulating data, the memory locations in RAM are named. The names are actually addresses and each memory location has a unique address. Think of RAM as being a house. Each house can contain contents and each house has an address. Following this model, we can say that a program will create a number and then specify which house to store the number. The address scheme used in RAM memory names each byte location in RAM with a B followed by a number. So the first memory location in RAM is called B0 (b-zero). The next one is called B1. There are 28 different bytes in RAM that can be directly accessed like this. That implies the last byte in RAM has an address of B27. Don’t get the address of a RAM byte confused with the number stored inside of it. So B0 could store a 15 while B1 could store a 213. The program can change and update each RAM location as often as it needs to. For example, B5 could initially store a value of 178. Later in the program, it could add 15 to the value stored in B5 to make it a 192. When you become a more sophisticated programmer, you will discover there are additional bytes in RAM. However, these are not accessed the same way that bytes B0 to B27 are accessed.
6
Data Memory Used to permanently store data Non-volatile Accessible
The last kind of PICAXE memory is used by the Temperature Logger to store all the temperature readings. There is 256 bytes in Data Memory and since each temperature reading is one byte in size, the Temperature Logger can store 256 temperature readings. Data Memory is EEPROM, so it retains data even when the battery is disconnected. This permits the Temperature Logger to download temperature readings days, months, or even years later. The Data Memory has a limited number of times that it can be used, something over 100,000 times. This memory is like RAM in that each byte has an address that the program can reference. To write to a Data Memory location, the program uses the WRITE command. To read from a Data Memory location, the program uses the READ command. In normal operation, data written into Data Memory comes from the number stored in a RAM byte. When the data is read from Data Memory, it will be transferred to a RAM byte. To write the number stored in RAM byte B5 into Data Memory location 150, the command is WRITE 150,B5. The READ command is similar. To copy the number stored in Data Memory byte 81 into RAM byte B12, the command is READ 81,B12. It’s important to move numbers from Data Memory to RAM because while the numbers are stored only in Data Memory, humans cannot see them. Once the numbers are moved into RAM, they can be displayed on a PC.
7
Connecting all the Pieces
A program must be written in order to make the Temperature Logger function. It is very unlikely the Temperature Logger will ever run out of Program Memory. It simply doesn’t take 600 lines of instructions to make the Temperature Logger function. The editing software used to create the Temperature Logger’s program will make all the arrangements to store the program into Program Memory. You need not concern yourself with the byte locations in Program Memory. Each byte in RAM can be accessed by the program stored in Program Memory. This is a two-way connection, the program can write a number into each RAM byte and can also read the number stored in each RAM byte. The program access each byte in RAM by using the address (or name) of the byte. So for example, B0, B1, etc. The data stored in each RAM byte is at the mercy of the battery. If it is disconnected, the number stored in each RAM byte vaporizes. If the program is to safe-guard the data, it must be stored in Data Memory. There are only 28 bytes of RAM. Data Memory is permanent until the program erases or overwrites the data. There are 256 bytes of Data Memory and the program access them with the READ and WRITE commands. The name or address of each byte in Data Memory is just a number, so 0, 1, 2, etc. Data Memory cannot directly access RAM and RAM cannot directly access Data Memory. The only way to move data between them is by using a program. The only data that can be displayed for human consumption is that data stored in RAM. Each temperature reading is created in RAM. So it is necessary to move temperature readings from RAM to Data Memory after each temperature reading. It is also necessary to move readings stored in Data Memory into RAM in order to display the readings.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.