MSP430-assembly language part-2.1-TIMER

Photo of author

By Jackson Taylor

Home » Programming » MSP430-assembly language part-2.1-TIMER

Timer A — high speed blinking using up/down mode

Time  = (65000*2)+1/1.1MHz = 0.118182727

.include "msp430g2x31.inc"
org 0xf800                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_3|TAIE), &TACTL
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      bic #1,&TACTL
      xor.b #41h, &P1OUT
      reti
ORG     0FFF0h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Timer A — high speed blinking using up mode & CCIFG

.include "msp430g2x31.inc"
org f800h                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_1), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Timer A — high speed blinking using up/down mode & CCIFG

.include "msp430g2x31.inc"
org 0xf800                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_3), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Next    Arithmetic operations

http://jimmyjosep.blogspot.in/2013/12/msp430-assembly-language-part-3.html

.include "msp430g2x31.inc"
org 0xf800                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_3|TAIE), &TACTL
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      bic #1,&TACTL
      xor.b #41h, &P1OUT
      reti
ORG     0FFF0h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Timer A — high speed blinking using up mode & CCIFG

.include "msp430g2x31.inc"
org f800h                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_1), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Timer A — high speed blinking using up/down mode & CCIFG

.include "msp430g2x31.inc"
org 0xf800                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_3), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Next    Arithmetic operations

http://jimmyjosep.blogspot.in/2013/12/msp430-assembly-language-part-3.html

org f800h                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_1), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Timer A — high speed blinking using up/down mode & CCIFG

.include "msp430g2x31.inc"
org 0xf800                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_3), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Next    Arithmetic operations

http://jimmyjosep.blogspot.in/2013/12/msp430-assembly-language-part-3.html

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video
org 0xf800                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_3), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

Next    Arithmetic operations

http://jimmyjosep.blogspot.in/2013/12/msp430-assembly-language-part-3.html

org 0xf800                 
      mov #(WDTPW|WDTHOLD), &WDTCTL
      mov #0x280, SP
      mov.b #0x41,&P1DIR
      mov.b #0x41,P1OUT  
      mov #(TASSEL_2|MC_3), &TACTL
      mov #CCIE, &TACCTL0
      mov #65000, &TACCR0
      eint
jimmyloop:
      jmp jimmyloop          
jimmyisr:
      xor.b #41h, &P1OUT
      reti
ORG     0FFF2h                 
DW      jimmyisr
ORG     0FFFEh                 
DW      0xf800

How the Timer A examples differ

All the programs above blink the LEDs on P1.0 and P1.6 by toggling them inside an interrupt routine. The differences come from the counting mode and the interrupt flag each one uses.

  • Up mode (MC_1): the timer counts from 0 up to the value in TACCR0, then returns to 0. One full cycle is about TACCR0 + 1 clock ticks.
  • Up/down mode (MC_3): the timer counts from 0 up to TACCR0, then back down to 0. One full cycle takes roughly twice as long as in up mode with the same TACCR0 value, which is why the timing formula at the top multiplies 65000 by 2.
  • TAIFG (TAIE set in TACTL): this flag is set when the timer rolls over to 0. Its interrupt uses the shared Timer A vector at 0FFF0h. The first example clears the flag by hand with bic #1,&TACTL, otherwise the interrupt would fire again straight after reti.
  • CCIFG (CCIE set in TACCTL0): this flag is set when the timer reaches TACCR0. It has its own vector at 0FFF2h, and the hardware clears the flag when the interrupt is serviced, so no manual clearing is needed.
See also
LCD -8051

To work out the blink interval, divide the number of timer ticks per cycle by the timer clock. The examples select SMCLK (TASSEL_2), and the 1.1 MHz figure in the formula is the approximate default speed of the internal oscillator. If you change the clock source or add a divider in TACTL, the interval changes with it.

If your LEDs do not blink as expected, check three things: the interrupt vector address matches the flag you enabled, eint is executed after the timer is configured, and the stack pointer is set before any interrupt can occur.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works