Thursday, March 15, 2012

Using ACLK and the 32kHz Crystal

The other day I decided to build a timer to control some lights in my apartment. As I hope to expand this mini project into a full-fledged home automation system built around the CC430, a simple light timer from Walmart would not do! Obviously, the LaunchPad is the perfect tool for the job.

For example, let's say that I wanted to keep my lights on for 5 hours at night while I am on vacation. The first thing you will need is a way to tell time; this requires some sort of real-time clock. Since the high frequency clock sources on the MSP430 are not accurate enough to keep reliable time over a large period of time (anything greater than 1 minute in my opinion), a lower frequency clock will be needed. Though many of the newer MSP430s have built in 32kHz clocks, such as the the MSP430F5510, the value line series does not!

The 32.768kHz Crystal

The first step for building this project is to install the 32.768kHz crystal onto the LaunchPad. From this point onward I will just be calling this 32kHz for simplicity. You might be wondering why a real time clock is based on 32.768kHz; 32768 is exactly 2^15. This number can be divided down using binary values to give you a frequency of 1Hz, or a period of 1 second. This is why 32kHz is the standard frequency used in real-time clocks.


The above image shows the crystal soldered onto my LaunchPad. There are many methods you can use to solder this on, one of which is nicely documented on Justin's Tech blog. I ended up soldering the base of the crystal first, ensuring that the clock was positioned correctly before I soldered the small leads. Use any method that works for you.

The LED Hello World

The first thing you should do once you have this soldered onto your board, is test it. Making sure that everything works before you start a complicated project is very important. Let's make an LED turn on every two seconds, for one second. Instead of changing the timer output pins directly as we did in an earlier post, lets blink the LED manually so that we can easily expand the functionality of this program in a future post. There are a few things you should notice in the code below.

In this code we divide the clock by 64 (lines 26 and 37) which causes the timer to increment 512 times a second (512Hz). Once the clock counts up to 512 511 (this is because we start counting at 0), one second has gone by, and an interrupt is thrown. Now that we are entering an interrupt routine instead of automatically toggling the output, we can use this interrupt routine in the future to expand the functionality of this code.

The last important line of code is line 27, where a capacitance value is set. This value matches the capacitors that come installed on your LaunchPad. In the next section, I will elaborate slightly on what this capacitance is.

Edit: This statement is actually incorrect. A big thank you goes out to Jens-Michael Gross for pointing it out to me.
"The capacitance setting is an internal switch that enables some silicon capacitors on the MSP die. The selection has to match the required load capacitance of the used watch crystal. You can set it to minimum (plain parasitic pin capacitance) and apply external capacitors of the proper value, if you want. However, the available options are sufficient for the most watch crystals, so external capacitors are unnecessary, even counterproductive. And external capacitors have a large tolerance that affects the crystal frequency. The LaunchPad I just got has no capacitors installed (the C21 and C22 pads are empty, as it should be if the XCAP options are used."
Custom Design

One thing I wanted to mention before this post comes to a close, is how you can take this design off the LaunchPad and make it your own. Many projects work out so well that you just want to create a PCB or make it permanent in some other way.

Working with crystals can be tricky for beginners, as there is one thing you must look out for. All crystals require a load capacitance to remain stable, Wikipedia (Pierce Oscillator) and Texas Instruments both have some quality information on the topic. The value of these two capacitors depend on which crystal you use. Even two crystals with the same frequency which are made by the same manufacture might require different load capacitor values. Please check the crystal's datasheet for this information. For example, the LaunchPad uses 12pF capacitors to load the crystal we just installed, yet many crystals require 22pF.

Edit: This statement is actually incorrect. Another big thank you goes out to Jens-Michael for pointing it out to me. Thanks for reading!
"12pF is the typical load for most crystals I've ever seen. But due to the electric connection, a 12pF load means [there will be 2] 24pF capacitance on each of the crystals sides. Reason is that (seen from the crystal), the two capacitors are in series to each other and parallel to the crystal. […] Subtract the ~2pF pin capacitance of the MSPs pins and you get [two separate] 22pF [for] external capacitors, resulting in 12pF load. The XCAP settings already include pin capacitance and the /2 factor."
A bit more information and great advice from Jens-Michael!
"Experiments have shown that the G devices (in opposition to the AFE2x and some other x2 family devices without HFXT1 input) will accept a high-frequency TTL clock signal (e.g. from a self-oscillating quartz oscillator) on the XTIN pin, when in bypass mode. The Datasheet limits external clock to 50kHz, but there were no problems with 16MHz."
Conclusion

As you can see by the following screenshot from my oscilloscope, this timer is pretty darn accurate.


Hopefully you enjoyed this post and found it informative. I am going to try to keep things a bit more bite-sized from now on. Let me know what you think.

Post links to your projects which use the ACLK or the 32kHz crystal in the comment section below!

Thursday, October 27, 2011

Programming the DEV.BO and External Targets with a LaunchPad

Many readers have been asking me how to program the DEV.BO with the LaunchPad. Likewise, many of you are also wondering how to program the newer MSP430 microcontrollers with the LaunchPad, such as the MSP430F55xx series.

Since this seems to have sparked quite a bit of confusion, I want to make this post complete and thorough. There are two ways to program an MSP430: the first is using four-wire JTAG, the second is using two-wire JTAG. The LaunchPad can only use the two-wire JTAG method, which is also known as Spy-Bi-Wire (SBW). For the rest of this post, I will be referring to the two-wire JTAG as SBW and four-wire JTAG as just JTAG.

I want to make sure this is clear before I continue; JTAG and SBW are two separate methods for programming an MSP430. The LaunchPad can program MSP430s using SBW, not JTAG. That being said, not all MSP430s can be programmed using SBW, some of the older MSP430s can only be programmed using JTAG. TI has a document, SLAU157, which shows which chips support either just JTAG or both JTAG and SBW.

Now that we know JTAG and SBW are different methods of programming newer MSP430s, how do we use the LaunchPad to program all these cool devices? Spy-Bi-Wire needs two wires to program an MSP430: RST and TEST. The image below shows where you can find these two pins on the Launchpad.
The programming pins on the LaunchPad
The RST pin is shown by a yellow square, TEST is shown by a green square, and all of the GND pins are shown by blue squares. What about power? Well, you can either use the LaunchPad to power the DEV.BO (or your target MSP430 that supports SBW) or use an external power source. Regardless of how you power the target, you will need to also connect the LaunchPad's GND pin to the target. This is because you need a common reference for the data pins (RST and TEST); so technically you actually need a minimum of three wires to program an MSP430.

DEV.BO programming header
For this post we will use the LaunchPad to not only program the DEV.BO, but to also power it during programming. The image above shows which signals make up the programming header on the DEV.BO. There is a reason that I designed the programming header pins in that order. They are the same order as the LaunchPad; this is very important. What about the GND pin on the LaunchPad? Though there is no GND pin on the programming header, the LaunchPad does have a few GND pins available on board. Depending on what you have to connect the boards together, determines which GND you should choose.

The programming connection on the LaunchPad's side
The image above shows how I connect the DEV.BOs header to the LaunchPad. That nice six pin rainbow connector is available here at SparkFun and it works great for this task. Notice how I am using female connectors on this LaunchPad which makes it easy for me to connect GND to the rainbow connector using just a short breadboard wire. If you don't have access to this nice rainbow ribbon cable, you can use any method to connect these pins together.

Hopefully that should clear up any confusion on how to program the DEV.BO. Using this method, you can also program any other MSP430 that supports SBW; just connect up the necessary pins and you can program away.

I have two last things I want to mention. The RXD and TXD pins are not needed for programming but I included them on the DEV.BO in case they are ever needed for a project. The second thing is that you need to make sure the correct chip is selected in CCS or whatever IDE you use when programming the MSP430, otherwise it probably won't work.

I hope this clears up any confusion on how to program external MSP430s, including the DEV.BO, using the LaunchPad. Please leave a comment if you have any questions about this post. Don't forget to check out the DEV.BO, which is available in my online store.

Comment away!

Wednesday, October 26, 2011

Bluetooth Breakout and Free Shipping

I would like add yet another product to my online store, NJC's Bluetooth breakout board. I would also like to announce that there is now free shipping on all orders within the contiguous United States for items on my online store.

This board is based off of the RN-42 module which is very easy to use and add to your current projects. A few weeks ago I actually wrote a post on how to add Bluetooth to your MSP430 project that mentioned this breakout board. The circuit board is a modified design of SparkFun's Bluetooth breakout board which adds status LEDs and all the passive components needed to make this board "plug and play" right into your project while keeping all the important yet non-essential pins available. The module is also small enough that it can be added to existing projects with ease.

Populated Bluetooth breakout board
You have two options when buying this board, either completely assembled or as a bare PCB. The completely assembled board is a good option for those of you who don't want to fuss with surface mount components, and want a guaranteed working board. The bare PCB is a great option for those of you who have no problem soldering surface mount components and who want to add Bluetooth to their project while spending as little as possible.

Top of the PCB with each pin labeled

The picture above shows the pinout of the board, which should make it very easy for you to incorporate into your project. You just need to connect the RX, TX, 3.3V, and GND to your project, and you are ready to go. The full schematic of the board can be downloaded below.

Interested? Pick one up at my online store!

Please let me know if you have any questions!


Documentation
RN-42 Datasheet
RN-42 User Manual
NJC Bluetooth Breakout Schematic

Thursday, October 13, 2011

Introducing the MAVRK

What is the MAVRK? MAVRK stands for Module and Versatile Reference Kit. It is a new hardware platform developed by Texas Instruments which will allow you to evaluate almost any configuration of Texas Instruments' products. I have been given the opportunity to evaluate this kit before it is released and will be generating content for the community. This post will introduce you to the MAVRK and give a brief explanation of what the kit is.

While I am still not sure who Texas Instruments is targeting with this board , I think that professionals, students, and hobbyists all will be able to find some interesting uses for this system.
MAVRK with two modules installed.
This is a picture of the MAVRK board with two modules installed. I think it's pretty cool looking!

Instead of trying to explain exactly what the MAVRK is, I will give you a scenario in which you would want to use the MAVRK. Imagine you want to build a quadcopter that can be monitored and/or controlled wirelessly from a nearby computer. Instead of taking lots of time and money building prototype after prototype till you get the design right, you can use the MAVRK. First you would need a motor module, a wireless module (say Wi-Fi for example), an MSP430 module, and a few analog or digital input modules. All of these things TI apparently plans on offering at quite low prices.

You would plug everything in to the motherboard, hook any accelerometers you have to the input modules, hook a few test motors up to the motor module, and start programming away. The MAVRK programming tool chain is supposed to make the integration of these modules easy and quick. If all goes to plan, you should have a working model within days, not weeks. Now all that is left is to take the MAVRK setup, and turn your working design into a custom PCB; this step should also be easy considering the MAVRK and all the modules are open source, including the hardware.

I will be started a separate blog about the MAVRK system which will go into more detail about the kit and how to get started with the kit. Stay tuned! Let's see what this baby can do!

Wednesday, August 24, 2011

DEV.BO on eBay

After receiving some emails from a few readers, I have decided to also sell some of my boards on eBay. I understand that this might be a more comfortable and care-free way of buying my boards. Currently I have posted a DEV.BO and will be posting some others soon (the list below will be updated as I post boards). If this works out well I will add other boards to my eBay account. Also, I will probably forget to remove the links when the items end; keep that in mind.

Click here for the DEV.BO!
Click here for the Bluetooth Breakout!

I have a few posts in the works but if anyone has a suggestion for a simple tutorial or guide, let me know.

Happy Bidding!!

Monday, August 8, 2011

Adding Bluetooth to your MSP430 Project

Most projects which I have seen input and output some sort of data: be it a multimedia stream, sensor data, or user inputs. In this post I will discuss how to easily make your project Bluetooth enabled. For hobbyists and professionals alike one of the most important aspects of any design is cost; in my own project I had three requirements for a Bluetooth Module, low cost, low size, and very easy to use.

The RN-42 module, which is available at SparkFun electronics and Mouser, is a very cheap and simple way to use Bluetooth in your project. The best part about the RN-42 module is that it has an integrated antennae and contains everything needed for the Bluetooth protocol. You would be surprised how many modules require a special external microcomputer that contains a Bluetooth stack to operate.

For how great the module may seen, there are a multitude of downsides. The first is not such a big deal and might not even be a downside for you. The device is in a surface mount package. For those of you who are not making your own PCBs, you can buy one at my online store and be done with it. For those of you on a budget, it is possible to solder wires onto each pad of the RN-42 even though I would not recommend it. The last, and my favorite solution, is to just make a custom PCB for your project and solder on the module yourself. The picture below is of a custom breakout board I made to evaluate the module. The schematic is shown later in this post.

My custom breakout board for the RN-42.
The other negative aspects of this module are its size and maximum baud rate. The module is a little bigger than I would like, but still reasonably small. The device also draws a bit more power than I would like, but all things considered it is not too bad for being a Bluetooth module. What bothers me the most about this device is that the maximum baud rate is very very low. I will discuss this in more detail after I show you how to integrate this device into your project.

Link Summary

RN-42 at SparkFun
RN-42 Breakout at SparkFun
RN-42 at Mouser
RN-42 Datasheet
Roving Networks User Manual
NJC's Software UART
RealTerm

Adding Bluetooth to your Project

The easiest way to send and receive data using this Bluetooth module is to use a UART connection. The first schematic below, which is based off of the datasheet and example schematic from SparkFun, is how I connected the module to my project.

A complicated example for hooking up the RN-42 to the MSP430F5510.
This shows how to connect the RN-42 to an MSP430. Please note that this is just an example and that it is much more complicated than the bare minimum; see the next schematic for the bare minimum needed. The first and most important thing I want to mention is that the device requires a supply voltage between 3V and 3.6V. Luckily I use 3.3V for most of my projects which is perfect for this module.

My custom breakout board for the RN-42
The figure above shows the schematic for the breakout board which I used for evaluating the device and shows what kind of connections the module needs in order to function properly. After testing the device thoroughly it was obvious to me that the device is so simple to use that I could have put it in my project right away. The range is quite good and the device is very reliable when using a baud rate of 115200.

Connecting

Hopefully by now it is clear that from the hardware side of things only a UART connection is needed between the Bluetooth module and your MSP430. What about from the other side of the data stream? The computer. Linking the module to the computer was surprisingly easy. On Windows 7 (I can’t speak for any other OS or version of Windows), it was plug and play. Within a few seconds the drivers were automatically installed and I could see which COM port the module was connected to in the device manager.

The device manager showing the RN-42 connected as COM6.
As I mentioned before, my terminal program of choice is Realterm. The first test I recommend completing when setting up the module is a simple echo test. Connect the RX and TX pins on the module together, then set the COM port to the correct port and the baud rate to 115200 baud in your terminal. Once everything is set up and the power is on, wait for the device to connect. If you have the status LEDs connected to the module (which are optional if you are worried about power consumption), the LED connected to PIO2 should turn on when the module is paired with the computer. The other status LED will blink if the device is not connected. Once connected, type a few characters in the terminal and you should receive back every character you typed into the terminal.

Note: If you are running off of a battery, which you probably are given that this is a post about Bluetooth, you will run into connection issues when the battery is getting low. The module will still turn on and the LEDs will still blink, but you will not be able to reliably connect. If you are having connection issues, check your battery.

That should be all that you need to know in order to add Bluetooth to your project. If you think there is something I have missed, let me know and I will add a section to this post.

Commands?

Yes, this module can accept commands which allow the user to change some important settings. I will not be discussing these commands in this post. You can find all the information you need on this topic in the Roving Networks User Manual.

Baud Rate Trouble

As I mentioned earlier I want to discuss the problems I have with the data rate of this device. My frustrations really arise from false claims on the specifications of the device from both the manufacturer and vendors. 
  • "Over air data rate of 721kbps to 2.0Mbps" - SparkFun product page
  • "Data Rate: 1200 bps to 921 Kbps" - Mouser
  • "Sustained SPP data rates - 240Kbps (slave), 300Kbps (master)" and "HCI data rates - 1.5Mbps sustained, 3.0Mbps burst in HCI mode" - Roving Networks Datasheet for the RN-42
The quotes above show where my frustrations originate. To be honest, I am not really sure where SparkFun got their numbers; if I am missing something, please point it out to me. To make things clear, this device really only functions in SPP mode, thus you have a max data rate of 240Kbps if the device is in slave mode. I'm not even sure if it's possible to put the device in HCI mode, apparently it must be done at the factory.

So the datasheet is clear about the max speeds in each mode, but I am frustrated that they do not make it abundantly clear that the device cannot work in HCI mode. I emailed Roving Networks inquiring about this dilemma I was having (I wanted to use 921600 baud sustained over the air) and though they were friendly, prompt, and reasonably helpful, I was/am not happy with how misleading their datasheets are.

“The HCI mode is a special build of firmware the needs to be programmed at the factory.” “Please understand that in HCI mode, the bluetooth stack is running on the external host processor and the module is acting as a radio.” All in all, I do commend them on their customer service, just keep in mind that realistically speaking, you will only be able to use SPP mode.

Conclusions

Despite my frustrations, this is a great solution for making your project wireless. I have found very few chips or modules that can be integrated into a project with such ease. I hope this post helps a few people successfully add Bluetooth to their projects. There are so many cool possibilities for projects when using Bluetooth; the possibilities are endless! Who wouldn't want to hook up a project to an Android phone?

Comment away! Let me know what projects you have added Bluetooth to!

Thursday, July 14, 2011

Update

It recently came to my attention that my webstore has not been working correctly. Instead of loading the shopping cart when an item was added, the PayPal homepage would be loaded. I believe that I have fixed everything, but please let me know if you have any more problems with the store.

I apologize to any of you who tried to place an order while the store was not working correctly.

For any inconvenience this may have caused, all orders placed in the next week will receive an automatic refund of 20% when the item(s) ship. This is valid from 07-14-2011 until 11:59PM-EST 07-21-2011.

Please let me know if you have any questions or concerns.