Msp430 Example Programs
Jul 19, 2010 We've gotten to the point now where we can program the MSP430 and make it respond by flashing an LED or two. To make the example work.
I finally have had the time to write up this post. Hopefully in a few more weeks I will have more time and can keep up a steady stream of posts like I was doing before. As promised in the last post, this post will discuss the basics of the ADC10 peripheral in the G2231 which comes with the LaunchPad. The code will allow the microcomputer to accept simple ASCII commands sent over the LaunchPad's UART from a computer, and act on those commands. Four commands are implemented for this post; there will be two more in the next post which will add streaming functionality to the code. The Functionality The first command tests the overall data throughput we can achieve with the microcomputer.
I think this is very important since it allows us to see how well our device is performing, and allows us to determine how fast the ADC should sample in real time. The second command uses a built in voltage divider to measure VCC in relation to an internal reference. The third command measures the internal temperature sensor in relation to a different internal reference. The final command measures the voltage on an external pin, in this case A3 in relation to VCC. Note that this code does not continually sample the ADC channels but will only sample once per command. The next post will discuss continuous sampling of a single channel, which will allow us to build a simple (slow) oscilloscope using only the LaunchPad. Computer Application To accompany the code on the MSP430 I have written a simple using C# which will allow us to easily interface with the device so we do not have to play around with terminal programs.
If any of your projects require a computer interface I highly recommend writing a custom application, I really hate fiddling around with terminal programs. Note: It seems that there are some problems with the installer. I have not figured out what causes the application to work on some computers and not on others. Hopefully it is just my laptop that is having trouble.
I recommend having the.NET 4.0 framework installed, even though I wrote the program for 3.5. The software allows you to connect to any COM port at any baud rate.
Download Livros Romances Gratis Pdf. The baud rate for this post will be 9600, considering that is the maximum of the LaunchPad, but can be changed if you want to use something like an FTDI chip. Make sure that your LaunchPad is plugged in and the VCP is ready before you run the software, the program does not constantly check which ports are available.
The GUI is pretty self explanatory; if you have any questions, bug reports, or suggestions feel free to post. There is also some additional functionality built into the program which is currently disabled; I will provide a second version of the code for the next post when we start streaming data. The Code As always the code is available as a gist. If anyone knows how to force the embedded code to show a vertical scroll bar please let me know. Going Through the Code Most of this code builds off of previous posts so I will not be going over it in great detail.
To read more about the UART please see. The code is broken down into multiple functions to increase readability. Receive(); is called when the main loop receives a new value from the software UART. This is not necessary, and might actually reduce the efficiency slightly since every function call requires an extra few assembly commands, but in my opinion it’s worth it since the code is more readable and much easier to modify. After initializing all the registers the device goes into its main loop. So far the ADC is not initialized, only the software UART is set up. The main loop will determine which command was sent and then calls the necessary functions; the loop will also send any converted ADC values out using the software UART.
As is true with most of the code I post, the chip goes into LPM0 when there is nothing to do. Before the CPU goes into low power mode it makes sure there are no flags waiting; this keeps the CPU from missing any events.
If this was not done it is possible that a second event would be missed, since the CPU was enabled while it was currently in a loop. The Receive() function will initiate different tasks depending on which command was sent to the computer. Bs 5839 Part 1 2002 Pdf Editor here.
The first command which is handled is used to test the speed at which the UART can send data. It will send 256 values, from 0x0000 to 0x00FF, as fast as it can; this data will be received by the computer application and is tested for errors; if there are no errors the speed of the transmission is displayed. It is important to note that 512 bytes are sent total because each value is a 16 bit word. This was chosen for two reasons. First, the MSP430 is a 16 bit processor; second the ADC measurement can not fit in one byte. The next three commands measure an external analog channel (A3), the temperature, and VCC. About the ADC I will not be going into how ADCs work, but I will provide some basic theory pertaining to the one in the G2231.