Texas Instruments Mixed Signal Processor Tutorial Abstract This tutorial goes through the process of writing a program that uses buttons to manipulate LEDs. One LED will be hard connected to the output of a compare register, yielding a PWM blinking at 1KHz. The other 3 LEDs will simply toggle on or off, as a demonstration how to directly write to the port. Two buttons will allow to increment and decrement the duty cycle. The two other buttons toggle the remaining 3 LEDs.
Texas Instruments Mixed Signal Processor Tutorial Marshall Taylor marshall.taylor@vandals.uidaho.edu Contents 0.1 Physical connections 0.2 Block diagram The Process 1.0 Creating a workspace 1.1 Program code 1.2 Debugging
0.1 Physical connections On the expanded MSP USB stick, 8 I/0 pins are used: P1.0 through P1.7 on the above diagram. The 4 LEDs are connected P1.0 through P1.3, and are active on logic '1' on the port register P1OUT. The 4 buttons on P1.4 through P1.7 are active low, pushing a button yields a '0' on the port register P1IN. These buttons should not be pressed if the port is set to output rather than input, as it will BLOW THE LOGIC. Notice that pin 4 is labeled P1.2/TA1/A2. This signifies that the pin can be either P1.2, Timer A output, or Analog input 2. For this tutorial the pin is configured as timer A output, so it's never explicitly asserted but still lights. It is to note that manipulating the P1OUT register has no effect on this pin in timer A mode, as the pin is physically disconnected from P1OUT completely. 0.2 An example block diagram Texas instruments is a company founded by the top engineers that money can buy, resulting in technical documents that are dryer than this one. There are 2 documents required to program any device: slau144e.pdf overviews the entire family of MSP processors. Here, the logic blocks of internal hardware resources are examined. All potential hardware modules of the family are described, though individual chips only employ a handful. msp430f2012.pdf outlines the specifics of the f2012 device plugged into the thumb stick. It contains block diagrams of the individual pin logic and gives specifics on which hardware modules are actually present in the f2012. Here is the block diagram to a commonly used piece of hardware, timer A. It has been copied directly from slau144e.pdf
In this diagram, black squares signify control lines which are combined into control registers, described again in slau144e.pdf. Here's a rundown of basic modules. TAR: Is a counter, incrementing with the timer clock TASSELx: Selects the clock source, see the module of 'basic clock module+' for more info. IDx: Has the ability to divide the clock (or not) TACCR0, TACCR1, TACCR2: Contains compare registers, SEE slau144e.pdf!!!!! OUT2: This gets connected to P1.2 for hardware operation, SEE MSP430f2012.pdf!!! Ok, just read the documentation. All of the modules are laid out like this.
1.0 The Process 1.1 Creating a workspace Install the tools from the disk. Reading the installed material will direct you to a simple blinking light example, this is a good place to start. After starting the tools, a window will appear. Choose to start a new project in the current workspace. Next you will be prompted to use a template. Don't bother. Start an empty project and name it something, I used 4light. Now you are given the blank project. File-New document. Start by saving this, I chose 4light.c, the c is required. Right click on the main file in the left hand exploration bar. Expand Add to discover that your file 4light.c is an option to be added. Add it. Save the workspace. 1.2 Setting up the tool Drop down project and choose options. Two settings must be changed. Change the generic device to the one being used. Under debugger, change simulate to FET debugger (the thumb tool) 1.3 Program code Now the tool is ready to go (is the USB stick plugged in?) Enter this code in the c file you made: Source code should exist in this document s folder.
//Tutorial demonstration #include "msp430x20x2.h" interrupt void btn_isr(void); //The routine called upon interrupt. int press_cnt; int main(void) WDTCTL = WDTPW + WDTHOLD; enable_interrupt(); press_cnt = 10; //1:1 counter for button presses // Stop watchdog timer // Enables GIE, general interrupt bit P1DIR = BIT3 + BIT2 + BIT1 + BIT0;// Set P1 output direction (bit mask) 0=in, 1=out P1SEL = BIT2; // Connect output to timer P1IES = BIT7 + BIT6 + BIT5 + BIT4; // Set Interrupt Edge Select to "high to low" on bit3 (bit mask) P1IE = BIT7 + BIT6 + BIT5 + BIT4; // Enable interrupts on P1 (bit mask) BCSCTL2 = 0x00; //Select divide by one TACCTL0 = BITB; //Set compare 0 TACCR0 = 0x03E8; //Set.001 second interval TACCTL1 = BITB + BIT7 + BIT6 + BIT5; //Set compare 1 TACCR1 = 0x012C; //Default pulse width TACTL = BIT9 + BIT4 + BIT2; //SMCLK, /1, up, reset, disable TimerA interrupt while(1) //NOP #pragma vector=port1_vector interrupt void btn_isr(void) if(p1ifg & BIT4) //This checks for bit4 in the interrupt register if(press_cnt!= 0) press_cnt--; //If not too small, decrement else if(p1ifg & BIT5) //Check bit5 if(press_cnt < 19) press_cnt++; //If not too big, increment else if((p1ifg & BIT6) (P1IFG & BIT7)) //Check other two buttons P1OUT ^= (BIT3 + BIT1 + BIT0); //Toggle the other LEDs, (xor) else press_cnt = 10; //Counter get lost? return to 10 TACCR1 = (press_cnt * 50) + 25; //LOAD THE COMPARE VALUE P1IFG = 0x00; //reset the interrupt register. 1.4 Debugging Push ctrl-d or choose project-debug to start the debugger. This allows single stepping of the program and a bunch of other things. This bar controls execution, hover-over style.
The red dot to the right is a break point, stopping any free running program. Double clicking on the gray bar will toggle the break points (2 max) The Register and Watch windows can be turned on and off in the view menu (only in debug mode). The register allows viewing of the registers explained within slau144e.pdf. Red values are new since the previous program break. Interesting variables can be right clicked on and added to the watch window. These debug windows will not be updated unless the program is halted.