Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

TI MSP430 Project

Status
Not open for further replies.

OutToLunch

New Member
I've been playing around with a little development kit from TI for the MSP430 MCUs called the eZ430-F2013 (Link: **broken link removed**). The kit is about the size of a thumb drive, you just plug it into a USB port and you can program it from a development platform. Pretty easy stuff, really. Been a while since I did any coding, though, so it took a while to do this.

OK, so what I did is nothing earth shattering. The concept here is that I have LED lighting set up on my motorcycle and right now it is either on or off. I have it set up in three sections - lighting the front wheel, lighting the motor and then lighting the rear wheel. I wanted to make it a little more interesting, so I programmed the mcu to flash some LEDs. I added some LEDs driven by 2n7000 fets off of the mcu pins and also wired in some switches to the mcu pins.

There are 9 selectable flashing modes for the 3 LED sections:
- All Flash
- Chase Left-Right
- Chase Right-Left
- Alternate Flash
- All Fade
- Chase Left-Right Fading
- Chase Right-Left Fading
- Alternate Fade
- Run Thru (goes thru each of the 8 above modes for a short period of time)

I also have a control for speeding up or slowing down the flash/fade rate.

So the ultra exciting video below shows it in action. The button on the left is the MODE select button. The Middle button is for slowing down the flash/fade rate and the Right button is to speed up the flash/fade rate. There may be a few little bugs in it, but overall it works just the way i wanted it to and doesn't lock itself up.

The mcu is running on its own - I have the kit plugged into the USB port just for power. Follow the link below for the video...

YouTube - LED Flash

I'll post the code in a reply to this cuz it's too long otherwise...
 
part 1 of the code...

Code:
;*******************************************************************************
;   LED Fader
;   OutToLunch
;
;   Written with IAR Workbench V4.11
;   For use on MSP430F2013
;
;   DESCRIPTION
;   This code controls 3 LED sets. The LEDs sets are brightened and dimmed
;   in an alternating manner. The brightness/dimmness is a result of increasing
;   or decreasing a PWM control signal. Each LED set is to be out of phase with
;   the other LED sets. Ramp rate and phasing is to be controlled externally.
;
;*******************************************************************************
;   Special Function Registers and their uses   
;   R4 holds the TimerA Register value (TAR) during TimerA interrupts
;   R5 
;   R6 
;   R7 
;   R8 
;   R9 
;   R10 
;   R11 
;   R12
;   R13
;   R14
;   R15
;-------------------------------------------------------------------------------
;   Define Variables for ease of reading code
;   RAM Address Range (128 Byte): 0x027F - 0x0200
;   
;--- Global variables
#define     Option    (0x0200)              // Option Byte for selecting modes
                                            //  Only 1 Bit should be set at any time
                                            //   Bit 0: Fader Mode
                                            //   Bit 1: Blink Mode
                                            //   Bit 3: Walk Thru Mode
                                            //   Bit 4: Reserved
                                            //   Bit 5: Reserved
                                            //   Bit 6: Reserved
                                            //   Bit 7: Reserved
#define     Ctrl      (0x0201)              // Control Byte
                                            //   Bit 0: Up/Down flag for LEDA
                                            //   Bit 1: Up/Down Flag for LEDB
                                            //   Bit 2: Up/Dpwn Flag for LEDC
                                            //   Bit 3: LED Period Check Flag
                                            //   Bit 4: Reserved
                                            //   Bit 5: Reserved
                                            //   Bit 6: Reserved
                                            //   Bit 7: Reserved
//#define     Fade_Clk  (0x0202)              // Peak count for TimerA in Fade Mode
#define     PerLED    (0x0204)              // Period for LEDs - same for all Channels
#define     Period    (0x0206)              // Global Period for counting LED Periods
#define     PerCtr    (0x0208)              // Counter for Global Period
#define     Counter   (0x020A)              // Counter for TimerA Interrupts
#define     THold     (0x020E)              // Hold time - delay before inc/dec from peak/trough of duty cycle
#define     Phase     (0x0210)              // Phase angle between channels
#define     DutyLEDA  (0x0212)              // Duty Cycle for LED Ch A
#define     DutyLEDB  (0x0214)              // Duty Cycle for LED Ch B
#define     DutyLEDC  (0x0216)              // Duty Cycle for LED Ch C
// --------
#define     BlinkCfg  (0x0218)              // Blink Mode Configure Word
                                            //    Only 1 bit of the 1st four set at a time
                                            //      Bit 0: All Blink
                                            //      Bit 1: Forward Chase
                                            //      Bit 2: Reverse Chase
                                            //      Bit 3: Ch A/C in Phase, Ch B 180 Out of phase
                                            //      Bit 4: Reserved
                                            //      Bit 5: Reserved
                                            //      Bit 6: Reserved
                                            //      Bit 7: ChA On Flag
                                            //      Bit 8: ChB On Flag
                                            //      Bit 9: ChC On Flag
                                            //      Bit 10: Reserved
                                            //      Bit 11: Reserved
                                            //      Bit 12: Reserved
                                            //      Bit 13: Reserved
                                            //      Bit 14: Reserved
                                            //      Bit 15: Reserved
#define     BlkCtr   (0x021A)               // Counter for Blinker Period
#define     BlkPer   (0x021C)               // Blinker Period
#define     LoopCtr  (0x021E)               // Counter for looping through Blink Modes
#define     Blk_Clk  (0x0220)               // Peak count for TimerA in Blink Mode
#define     WlkCtr   (0x0222)               // Counter for Mode Walk Through
#define     FdWlkCtr (0x0224)               // Coutner for cycling through Fader Phasing during Walk Thru Mode
#define     NoPhase  (0x0226)               // Phase Constant for Zero Phase Fader Mode
#define     PhsAng2  (0x0228)               // Phase Constant Two Phase Fader Mode
#define     PhsAng3  (0x022A)               // Phase Constant Three Phase Fader Mode
;-------------------------------------------------------------------------------
#include    "msp430x20x3.h"
;-------------------------------------------------------------------------------
            ORG     0F800h                  ; Program Reset
;-------------------------------------------------------------------------------
RESET       mov.w   #0280h,SP               ; Initialize stackpointer
StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
SetupCLK    mov.b   &CALBC1_16MHZ,&BCSCTL1  ; Set Internal Clock Rate
            mov.b   &CALDCO_16MHZ,&DCOCTL   ;   to 16MHz
;-------------------------------------------------------------------------------
; Set up the P1 Port for Inputs and Outputs
;-------------------------------------------------------------------------------
SetupP1     mov.b   #007h,&P1DIR            ; P1.0, P1.1 and P1.2 output; P1.3, P1.4, P1.5 Are Inputs
            bis.b   #038h,&P1IES            ; Set up For Hi to Low Transition Interrupts
            mov.b   #038h,&P1IE             ; Set up Interrupt Enable on P1.3,4,and 5
;-------------------------------------------------------------------------------
; Set up Variables
;-------------------------------------------------------------------------------
            clr.b   Option                  ; Clear Option register
;**** Configurable Variable ****************************************************
            bis.b   #005h,Option            ; Set Option
                                            ;  3 Choices:
                                            ;    01h = Fader Mode
                                            ;    02h = Blink Mode
                                            ;    04h = Walk Thru Mode
                                            ;           05h = Walk Thru @ Fader
                                            ;           06h = Walk Thru @ Blinker
;*******************************************************************************
//            mov.w   #0000fh,Fade_Clk        ; Set up TimerA peak count (Do Not Alter)
;-------------------------------------------------------------------------------
; Set up for Fader Mode
;-------------------------------------------------------------------------------
;**** Configurable Variable ****************************************************
MAINPER     mov.w   #00006h,Period          ; Set Global Period
                                            ;  For Fader Mode:
                                            ;      25h is slowest rate
                                            ;      01h is fastest rate
;*******************************************************************************
LED_PER     mov.w   #0005fh,PerLED          ; Set Global LED Period (Do Not Alter)
            clr.w   NoPhase                 ; Set 0 degree Ohase Fader Constant
            mov.w   #00040h,PhsAng2         ; Set Phase Angle for 2 Phase Fading
            mov.w   #00041h,PhsAng3         ; Set Phase Angle for 3 Phase Fading
;**** Configurable Variable ****************************************************
PHASE       mov.w   PhsAng3,Phase          ; Set Phase angle
                                            ;  For Ramp Up/Down Mode:
                                            ;       PerLED = 5fh:
                                            ;         00h = In Phase
                                            ;         40h = 2 or 3 Channel Phasing
                                            ;           In 3 Ch Phasing, Ch3 is in downward direction
;*******************************************************************************
;**** Configurable Variable ****************************************************
            mov.w   #00008h,LoopCtr         ; This sets Loop Counter for Walk Thru Mode
;*******************************************************************************
;-------------------------------------------                                            
            clr.w   PerCtr                  ; Clear Period Counter
            clr.w   Counter                 ; Clear TimerA Counter
            clr.w   WlkCtr                  ; Clear Walk Thru Counter
            clr.b   FdWlkCtr                ; Clear the Fade Walker Counter
            mov.b   #007h,Ctrl              ; Set Bits in Ctrl Register (U/D bits)
            clr.w   DutyLEDA                ; Clear Duty Cycle for LED A
            clr.w   DutyLEDB                ; Clear Duty Cycle for LED B
            clr.w   DutyLEDC                ; Clear Duty Cycle for LED C
            add.w   Phase,DutyLEDB          ; Set initial Duty Cycle Ch B
            cmp.w   PhsAng3,Phase           ; 3 channel phasing?
            jne     BlinkSetup              ; 
            add.w   Phase,DutyLEDC          ; Set initial Duty Cycle Ch C
            bic.b   #004h,Ctrl              ; Set DutyC to decrement
;            mov.w   #00000h,THold          ; Set the Hold Time (not active yet)
;-------------------------------------------------------------------------------
; End Fader Mode Set up
;-------------------------------------------------------------------------------
; Blinker Mode Set up
;-------------------------------------------------------------------------------
BlinkSetup  mov.w   #000f0h,Blk_Clk         ; Setup Timer A Counter Peak (Do Not Alter)
            mov.w   #00011h,BlinkCfg        ; Configure Blink Mode - Default All Blink
;**** Configurable Variable ****************************************************
            mov.w   #00fffh,BlkPer          ; Modify this for Speed
                                            ;    8 Speeds: 
                                            ;      0: efffh (slowest)
                                            ;      1: cfffh
                                            ;      2: afffh
                                            ;      3: 8fffh
                                            ;      4: 6fffh
                                            ;      5: 4fffh
                                            ;      6: 2fffh
                                            ;      7: 0fffh (fastest)
;*******************************************************************************
            clr.w   BlkCtr                  ;
;-------------------------------------------------------------------------------
; End Blinker Mode Set up
 
part 2 of the code...

Code:
;-------------------------------------------------------------------------------
; Set up Timer A
;-------------------------------------------------------------------------------
SetupTA     mov.w   #CCIE,&CCTL0            ; CCR0 interrupt enabled
            bit.b   #001h,Option            ;
            jz      BlinkClk                ;
            mov.w   Blk_Clk,R4              ; 
            mov.w   R4,&CCR0                ; Set TACCR0 for ramp up period
            jmp     TAGo                    ;
BlinkClk    mov.w   Blk_Clk,R4              ; 
            mov.w   R4,&CCR0                ; Set TACCR0 for ramp up period for Blinker            
TAGo        mov.w   #0210h,&TACTL           ; SMCLK, Upmode
;-------------------------------------------------------------------------------
; Main program - turns on LED and then shuts off CPU and waits for interrupts
;-------------------------------------------------------------------------------
Mainloop    mov.b   #007h,&P1OUT            ; Turn LED on
            bis.w   #CPUOFF+GIE,SR          ; CPU off, interrupts enabled
            nop                             ; Required only for debugger
                                            ;
;-------------------------------------------------------------------------------
TA0_ISR;    Timer A Interrupt Routine
;-------------------------------------------------------------------------------
            bic.w   #00030h,TACTL           ; turn off Timer A
            mov.w   TAR,R4                  ; Save current TimerA value
            bit.b   #001h,Option            ; Fader or Blinker Mode?
            jz      BlinkMode               ; If Blink Mode, jump to BlinkMode
;-------------------------------------------------------------------------------
; Fader Mode
; Duty Cycle and Period Testing Channel A -- LED is On during D, Off during 1-D
;-------------------------------------------------------------------------------
FadeMode    bit.b   #004h,Option            ; Walk Thru Mode?
            jz      ChA                     ; No?, Then Goto Normal Fader Routine
            cmp.w   LoopCtr,WlkCtr          ; Has Loop Count been passed?
            jn      ChA                     ; No, Goto Fader Mode
FdPh1       cmp.b   #000h,FdWlkCtr          ; If 0, then Phase=0
            jne     FdPh2                   ; Not 0? Then goto FdPh2
            inc.b   FdWlkCtr                ; Increment the Fade Walk Counter
            mov.w   NoPhase,Phase           ; Set Phase to 0
            mov.b   #007h,Ctrl              ; Set Bits in Ctrl Register (U/D bits)
            clr.w   DutyLEDA                ; Clear Duty Cycle for LED A
            clr.w   DutyLEDB                ; Clear Duty Cycle for LED B
            clr.w   DutyLEDC                ; Clear Duty Cycle for LED C
            add.w   Phase,DutyLEDB          ; Set initial Duty Cycle Ch B
            jmp     PreA                    ; 
FdPh2       cmp.b   #001h,FdWlkCtr          ; If 1, then 3 Ch Phasing
            jne     FdPh3                   ; 
            inc.b   FdWlkCtr                ; Increment FdWlkCtr
            mov.w   PhsAng2,Phase           ; Set 2 Ch Phasing
            mov.b   #007h,Ctrl              ; Set Bits in Ctrl Register (U/D bits)
            clr.w   DutyLEDA                ; Clear Duty Cycle for LED A
            clr.w   DutyLEDB                ; Clear Duty Cycle for LED B
            clr.w   DutyLEDC                ; Clear Duty Cycle for LED C
            add.w   Phase,DutyLEDB          ; Set initial Duty Cycle Ch B
            jmp     PreA                    ;
FdPh3       clr.b   FdWlkCtr                ; If FdWlkCtr <> 0 or 1, then it is 2
            mov.w   PhsAng3,Phase           ; Set 3 Ch phasing
            mov.b   #007h,Ctrl              ; Set Bits in Ctrl Register (U/D bits)
            clr.w   DutyLEDA                ; Clear Duty Cycle for LED A
            clr.w   DutyLEDB                ; Clear Duty Cycle for LED B
            clr.w   DutyLEDC                ; Clear Duty Cycle for LED C
            add.w   Phase,DutyLEDB          ; Set initial Duty Cycle Ch B
            add.w   Phase,DutyLEDC          ; Set initial Duty Cycle Ch C
            bic.b   #004h,Ctrl              ; Set DutyC to decrement
PreA        clr.w   WlkCtr                  ; Clear Walk Thru Counter
            bic.b   #001h,Option            ; End Fader Mode
            bis.b   #002h,Option            ; Start Blinker Mode
ChA         cmp.w   PerLED,PerCtr           ; Test if LED Period reached
            jn      ChkDutyA                ; Jump if NOT reached (ChAPerCtr < PerLED)
            bis.b   #008h,Ctrl              ; Set LED Period Check flag
            clr.w   PerCtr                  ; Period reached, count from 0 again
            jmp     LEDs_ON                 ; Period reached, Turn LEDs On
ChkDutyA    cmp.w   DutyLEDA,PerCtr         ; Test if Duty Cycle A reached
            jn      LEDA_ON                 ; Jump if NOT reached (PerCtr < DutyLEDA)
LEDA_OFF    bic.b   #001h,&P1OUT            ; Turn LED A OFF
            jmp     ChkDutyB                ; Jump to look at Duty Cycle B
LEDA_ON     bis.b   #001h,P1OUT             ; Turn LED A On
ChkDutyB    cmp.w   DutyLEDB,PerCtr         ; Test if Duty Cycle B reached
            jn      LEDB_ON                 ; Jump if NOT reached (PerCtr < DutyLEDB)
LEDB_OFF    bic.b   #002h,&P1OUT            ; Turn LED B OFF
            jmp     ChkDutyC                ; Jump to look at Duty Cycle C
LEDB_ON     bis.b   #002h,P1OUT             ; LED B On
ChkDutyC    cmp.w   DutyLEDC,PerCtr         ; Test if Duty Cycle C reached
            jn      LEDC_ON                 ; Jump if NOT reached (PerCtr < DutyLEDC)
LEDC_OFF    bic.b   #004h,&P1OUT            ; Turn LED C Off
            jmp     ChkMainPer              ; Jump to look at Main Period
LEDC_ON     bis.b   #004h,P1OUT             ; LED A On
            jmp     ChkMainPer              ; Jump to look at Main Period
LEDs_ON     bis.b   #007h,&P1OUT            ; Turn LEDA, B, C On
;-------------------------------------------------------------------------------
; Look at the Duty Cycle and Increment/Decrement if necessary
;-------------------------------------------------------------------------------
ChkMainPer  cmp.w   Period,Counter          ; Test if counter has reached max
            jn      CtrIncr                 ; If NOT, then goto increment counter
            clr.w   Counter                 ; Counter reached max, reset to zero
            inc.w   PerCtr                  ; Increment Period Counter
            jmp     DutyDir                 ; Done, Check LED Duty Cycle
CtrIncr     inc.w   Counter                 ; Increment Ch A counter
DutyDir     bit.b   #008h,Ctrl              ; Was the LED Period reached?
            jz      EndInt                  ; If, NOT reached, then End Interrupt
ChkDtyA     bit.b   #001h,Ctrl              ; Is Duty Cycle A Incrementing?
            jz      ChkDutyALow             ; If not, Check if Duty Cycle = 0
            cmp.w   PerLED,DutyLEDA         ; Is Duty Cycle < Period?
            jn      DutyAIncr               ; If Yes, go to increment Duty Cycle
            bic.b   #001h,Ctrl              ; If No, then Duty Max'd, Clr Incr Bit 
            inc.w   WlkCtr                  ; Walk Thru Counter Increment
            jmp     DutyADecr               ; Jump to Decrement Duty Cycle
ChkDutyALow cmp.w   #00000h,DutyLEDA        ; Is Duty Cycle at its minimum?
            jne     DutyADecr               ; No, then goto decrement Duty Cycle
            bis.b   #001h,Ctrl              ; Set to increment Duty Cycle
DutyAIncr   inc.w   DutyLEDA                ; Increment Duty Cycle
            jmp     ChkDtyB                 ; Jump to Clear Check Duty Cycle B
DutyADecr   dec.w   DutyLEDA                ; Decrement Duty Cycle A
ChkDtyB     bit.b   #002h,Ctrl              ; Is Duty Cycle B Incrementing?
            jz      ChkDutyBLow             ; If not, Check if Duty Cycle = 0
            cmp.w   PerLED,DutyLEDB         ; Is Duty Cycle < Period?
            jn      DutyBIncr               ; If Yes, go to increment Duty Cycle
            bic.b   #002h,Ctrl              ; If No, then Duty Max'd, Clr Incr Bit 
            inc.w   WlkCtr                  ; Walk Thru Counter Increment
            jmp     DutyBDecr               ; Jump to Decrement Duty Cycle
ChkDutyBLow cmp.w   #00000h,DutyLEDB        ; Is Duty Cycle at its minimum?
            jne     DutyBDecr               ; No, then goto decrement Duty Cycle
            bis.b   #002h,Ctrl              ; Set to increment Duty Cycle
DutyBIncr   inc.w   DutyLEDB                ; Increment Duty Cycle
            jmp     ChkDtyC                 ; Jump to Clear Check Duty Cycle C
DutyBDecr   dec.w   DutyLEDB                ; Decrement Duty Cycle B
ChkDtyC     bit.b   #004h,Ctrl              ; Is Duty Cycle C Incrementing?
            jz      ChkDutyCLow             ; If not, Check if Duty Cycle = 0
            cmp.w   PerLED,DutyLEDC         ; Is Duty Cycle < Period?
            jn      DutyCIncr               ; If Yes, go to increment Duty Cycle
            bic.b   #004h,Ctrl              ; If No, then Duty Max'd, Clr Incr Bit 
            inc.w   WlkCtr                  ; Walk Thru Counter Increment
            jmp     DutyCDecr               ; Jump to Decrement Duty Cycle
ChkDutyCLow cmp.w   #00000h,DutyLEDC        ; Is Duty Cycle at its minimum?
            jne     DutyCDecr               ; No, then goto decrement Duty Cycle
            bis.b   #004h,Ctrl              ; Set to increment Duty Cycle
DutyCIncr   inc.w   DutyLEDC                ; Increment Duty Cycle
            jmp     EndInt                  ; Jump to End Interrupt
DutyCDecr   dec.w   DutyLEDC                ; Decrement Duty Cycle C
            jmp     EndInt                  ; Jump to End Interrupt
;-------------------------------------------------------------------------------
; End Fader Mode
;-------------------------------------------------------------------------------
; Blink Mode
;-------------------------------------------------------------------------------
BlinkMode   bit.b   #004h,Option            ; Is Walk Thru Mode Set?
            jz      Blk_Per                 ; No? Then Go to Normal Routine
            cmp.w   LoopCtr,WlkCtr          ; Has Loop Count been hit?
            jne     Blk_Per                 ; No, Goto Current Blink Mode
            clr.w   WlkCtr                  ; Clear Walk Thru Counter
            bit.w   #00001h,BlinkCfg        ; Current Blink Mode All?
            jz      BlkWlkFwd               ; No? See if it is Fwd Mode
            bic.w   #0000fh,BlinkCfg        ; End All Blink Mode
            bis.w   #00002h,BlinkCfg        ; Start Fwd Mode
            jmp     Blk_Per                 ; Goto Current Blink Mode
BlkWlkFwd   bit.w   #00002,BlinkCfg         ; Is Current Blink Mode Fwd?
            jz      BlkWlkRev               ; No? See if it is Rev Mode
            bic.w   #0000fh,BlinkCfg        ; End Fwd Mode
            bis.w   #00004h,BlinkCfg        ; Start Rev Mode
            jmp     Blk_Per                 ; Goto Current Blink Mode
BlkWlkRev   bit.w   #00004,BlinkCfg         ; Is Current Blink Mode Fwd?
            jz      BlkWlkPhs               ; No? Must be Phase Mode, Go there
            bic.w   #0000fh,BlinkCfg        ; End Rev Mode
            bis.w   #00008h,BlinkCfg        ; Start Phase Mode
            jmp     Blk_Per                 ; Goto Current Blink Mode
BlkWlkPhs   bic.w   #0000fh,BlinkCfg        ; End Phase Mode
            bis.w   #00001h,BlinkCfg        ; Start All Blink Mode
            bic.b   #002h,Option            ; End Blink Mode
            bis.b   #001h,Option            ; Start Fader Mode
Blk_Per     cmp.w   BlkPer,BlkCtr           ; Has Counter Reached Period?
            jne     EndBlk                  ; If NO, then goto increment counter
            clr.w   BlkCtr                  ; If Yes, then Clear Counter
            inc.w   WlkCtr                  ; Increment Walk Counter (only used in walk thru mode)
AllBlk      bit.w   #00001h,BlinkCfg        ; All Blink?
            jz      ChkFwd                  ;
            bit.w   #00100h,BlinkCfg        ; LEDs On? (Only need to check if one is on)
            jz      BlkAllOn                ; If Off, then turn them On
BlkAllOff   bic.w   #00700h,BlinkCfg        ; Else, turn them all off
            jmp     LEDsA
BlkAllOn    bis.w   #00700h,BlinkCfg        ; Set All LEDs to ON
            jmp     LEDsA                   ;
ChkFwd      bit.w   #00002h,BlinkCfg        ; Forward Chase?
            jz      ChkRev                  ;
            bit.w   #00100h,BlinkCfg        ; LEDA on?
            jz      FwdCkB                  ; No, Check LEDB
            bic.w   #00500h,BlinkCfg        ; LEDA Off (turn LEDC off for good measure)
            bis.w   #00200h,BlinkCfg        ; LEDB On
            jmp     LEDsA                   ;
FwdCkB      bit.w   #00200h,BlinkCfg        ; LEDB on?
            jz      FwdC                    ; No, Then C Must be On, Jump There
            bic.w   #00300h,BlinkCfg        ; LEDB Off (turn LEDA off for good measure)
            bis.w   #00400h,BlinkCfg        ; LEDC On
            jmp     LEDsA                   ;
FwdC        bic.w   #00600h,BlinkCfg        ; LEDC Off (turn LEDB off for good measure)
            bis.w   #00100h,BlinkCfg        ; LEDA On
            jmp     LEDsA                   ;
ChkRev      bit.w   #00004h,BlinkCfg        ; Reverse Chase?
            jz      BlinkPhase              ; If not, then it must be Blink Out of Phase
            bit.w   #00100h,BlinkCfg        ; LEDA on?
            jz      RevCkC                  ; No, Check LEDC
            bic.w   #00300h,BlinkCfg        ; LEDA Off (turn LEDB off for good measure)
            bis.w   #00400h,BlinkCfg        ; LEDC On
            jmp     LEDsA                   ;
RevCkC      bit.w   #00400h,BlinkCfg        ; LEDC on?
            jz      RevB                    ; No, Then B Must be On, Jump There
            bic.w   #00500h,BlinkCfg        ; LEDC Off (turn LEDA off for good measure)
            bis.w   #00200h,BlinkCfg        ; LEDB On
            jmp     LEDsA                   ;
RevB        bic.w   #00600h,BlinkCfg        ; LEDB Off (turn LEDC off for good measure)
            bis.w   #00100h,BlinkCfg        ; LEDA On
            jmp     LEDsA                   ;
BlinkPhase  bit.w   #00100h,BlinkCfg        ; Is LEDA On?
            jz      BlkPhsB                 ; NO - LEDB is On, Goto Turn LEDA On with LEDC
BlkPhsAC    bic.w   #00500h,BlinkCfg        ; Turn LEDA and LEDC Off
            bis.w   #00200h,BlinkCfg        ; Turn LEDB On
            jmp     LEDsA                   ;
BlkPhsB     bic.w   #00200h,BlinkCfg        ; Turn LEDB Off
            bis.w   #00500h,BlinkCfg        ; Turn LEDs A and C On
LEDsA       bit.w   #00100h,BlinkCfg        ; Is LEDA to be ON?
            jz      LEDsAoff                ; No, Goto Turn A Off
            bis.b   #001h,&P1OUT            ; Turn LEDA On
            jmp     LEDsB                   ;
LEDsAoff    bic.b   #001h,&P1OUT            ; Turn LEDA Off
LEDsB       bit.w   #00200h,BlinkCfg        ; Is LEDB to be ON?
            jz      LEDsBoff                ; No, Goto Turn B Off
            bis.b   #002h,&P1OUT            ; Turn LEDB On
            jmp     LEDsC                   ;
LEDsBoff    bic.b   #002h,&P1OUT            ; Turn LEDB Off
LEDsC       bit.w   #00400h,BlinkCfg        ; Is LEDC to be ON?
            jz      LEDsCoff                ; No, Goto Turn C Off
            bis.b   #004h,&P1OUT            ; Turn LEDC On
            jmp     EndInt                  ;
LEDsCoff    bic.b   #004h,&P1OUT            ; Turn LEDC Off
            jmp     EndInt                  ;
EndBlk      inc.w   BlkCtr                  ; Increment Counter
;-------------------------------------------------------------------------------
; End of Interrupt Routine
 
part 3 of the code...

Code:
; Turn TimerA back on after restoring its count
;-------------------------------------------------------------------------------
EndInt      bic.b   #008h,Ctrl              ; Clear Main Period and LED Period Check Flags
            mov.w   R4,TAR                  ; Reset Timer A Register
            bis.w   #00010h,TACTL           ; Turn on Timer A
            reti                            ; Return from interrupt
                                            ;
;-------------------------------------------------------------------------------
; Button A Interrupt Routine
;-------------------------------------------------------------------------------
PORT1_ISR   bic.w   #00030h,TACTL           ; turn off Timer A
            mov.w   TAR,R4                  ; Save current TimerA value
BA_PUSH     bit.b   #008h,&P1IFG            ; Was Button A pushed?
            jz      BB_PUSH                 ; If not, Check if Button B was pushed
            bit.b   #004h,Option            ; In Walk Thru Mode?
            jz      TST_FDR                 ; If not, is it in Blink Mode?
            mov.b   #001h,Option            ; Set Fader Mode - Out of Walk Thru Mode
            mov.w   NoPhase,Phase           ; Set All Fade Mode
            mov.b   #007h,Ctrl              ; Set Bits in Ctrl Register (U/D bits)
            clr.w   DutyLEDA                ; Clear Duty Cycle for LED A
            clr.w   DutyLEDB                ; Clear Duty Cycle for LED B
            clr.w   DutyLEDC                ; Clear Duty Cycle for LED C
            jmp     END_P1_ISR              ;
TST_FDR     bit.b   #001h,Option            ; In Fader Mode?
            jz      BLK_MODE                ; If not, goto Blink Mode
            cmp.w   NoPhase,Phase           ; In All Fade Mode?
            jne     TST3PHS                 ; No? Test for 3 phase
            mov.w   PhsAng3,Phase           ; Set 3 Ch phasing
            mov.b   #007h,Ctrl              ; Set Bits in Ctrl Register (U/D bits)
            clr.w   DutyLEDA                ; Clear Duty Cycle for LED A
            clr.w   DutyLEDB                ; Clear Duty Cycle for LED B
            clr.w   DutyLEDC                ; Clear Duty Cycle for LED C
            add.w   Phase,DutyLEDB          ; Set initial Duty Cycle Ch B
            add.w   Phase,DutyLEDC          ; Set initial Duty Cycle Ch C
            bic.b   #004h,Ctrl              ; Set DutyC to decrement
            jmp     END_P1_ISR              ;
TST3PHS     cmp.w   PhsAng3,Phase           ; In 3 Phase Mode?
            jne     TST2PHS                 ; No? Test for 2 phase
            mov.w   PhsAng2,Phase           ; Set 2 Ch phasing
            mov.b   #007h,Ctrl              ; Set Bits in Ctrl Register (U/D bits)
            clr.w   DutyLEDA                ; Clear Duty Cycle for LED A
            clr.w   DutyLEDB                ; Clear Duty Cycle for LED B
            clr.w   DutyLEDC                ; Clear Duty Cycle for LED C
            add.w   Phase,DutyLEDB          ; Set initial Duty Cycle Ch B
            jmp     END_P1_ISR              ;
TST2PHS     bic.b   #001h,Option            ; Assume 2 Phase Mode, Goto All Blink Mode
            bis.b   #002h,Option            ; Set Blink Mode
            bic.w   #0000fh,BlinkCfg        ; Clear All Blink Modes
            bis.w   #00001h,BlinkCfg        ; Set All Blink Mode
            jmp     END_P1_ISR              ;
BLK_MODE    bit.w   #00008h,BlinkCfg        ; Assume Blink, OutPhase Mode?
            jz      ALLBLKTEST              ; If not then test for All Blink
            bic.w   #0000fh,BlinkCfg        ; Clear All Blink Modes
            bis.w   #00001h,BlinkCfg        ; Set All Blink Mode
            mov.b   #005h,Option            ; Set Walk Thru Mode
            jmp     END_P1_ISR              ;
ALLBLKTEST  bit.w   #00001h,BlinkCfg        ; All Blink Mode?
            jz      FWDTEST                 ; No? Go to Fwd Blink Test
            bic.w   #0000fh,BlinkCfg        ; Clear All Blink Modes
            bis.w   #00002h,BlinkCfg        ; Set Fwd Blink Mode
            jmp     END_P1_ISR
FWDTEST     bit.w   #00002h,BlinkCfg        ; Fwd Blink Mode?
            jz      REVMODESET              ; No? Go to Rev Blink Test
            bic.w   #0000fh,BlinkCfg        ; Clear All Blink Modes
            bis.w   #00004h,BlinkCfg        ; Set Rev Blink Mode
            jmp     END_P1_ISR              ;
REVMODESET  bic.w   #0000fh,BlinkCfg        ; Clear All Blink Modes
            bis.w   #00008h,BlinkCfg        ; Set Out of Phase Blink Mode
            jmp     END_P1_ISR              ;
;-------------------------------------------------------------------------------
; Button B Interrupt Routine - Increase Speed
;-------------------------------------------------------------------------------
BB_PUSH     bit.b   #010h,&P1IFG            ; Was Button B pushed?
            jz      BC_PUSH                 ; No? Then it was Button C...
            bit.b   #004h,Option            ; Walk Thru Mode?
            jz      BLKTESTBB               ; No? Go to Blink Test
            cmp.w   #00008h,LoopCtr         ; LoopCtr at min (max speed)?
            jeq     END_P1_ISR              ; If so, then exit out
            sub.w   #00008h,LoopCtr         ; Decrease LoopCtr By 1 Increment
            jmp     END_P1_ISR              ;
BLKTESTBB   bit.b   #002h,Option            ; In Blink Mode?
            jz      FDRSPDUP                ; No, then it must be Fader, Go there
            cmp.w   #007ffh,BlkPer          ; Is BlkPer at min (max speed)?
            jeq     END_P1_ISR              ;
            sub.w   #00800h,BlkPer          ; Decrease BlkPer by 1 Increment
            jmp     END_P1_ISR              ;
FDRSPDUP    cmp.w   #00001h,Period          ; Is Period at min (max speed)?
            jeq     END_P1_ISR              ;
            sub.w   #00002h,Period          ; Decrease Period by 1 Increment
            jmp     END_P1_ISR              ;
;-------------------------------------------------------------------------------
; Button C Interrupt Routine - Decrease Speed
;-------------------------------------------------------------------------------
BC_PUSH     bit.b   #004h,Option            ; Walk Thru Mode?
            jz      BLKTESTBC               ; No? Go to Blink Test
            cmp.w   #00108h,LoopCtr         ; LoopCtr at max (min speed)?
            jeq     END_P1_ISR              ; If so, then exit out
            add.w   #00008h,LoopCtr         ; Increase LoopCtr By 1 Increment
            jmp     END_P1_ISR              ;
BLKTESTBC   bit.b   #002h,Option            ; In Blink Mode?
            jz      FDRSPDDWN               ; No, then it must be Fader, Go there
            cmp.w   #0dfffh,BlkPer          ; Is BlkPer at max (min speed)?
            jeq     END_P1_ISR              ;
            add.w   #00800h,BlkPer          ; Increase BlkPer by 1 Increment
            jmp     END_P1_ISR              ;
FDRSPDDWN   cmp.w   #00025h,Period          ; Is Period at max (min speed)?
            jeq     END_P1_ISR              ;
            add.w   #00002h,Period          ; Increase Period by 1 Increment
            jmp     END_P1_ISR              ;
;-------------------------------------------------------------------------------
; End Button Push ISR
;-------------------------------------------------------------------------------
END_P1_ISR  bic.b   #038h,&P1IFG            ; Reset Interrupt Flags
            mov.w   R4,TAR                  ; Reset Timer A Register
            bis.w   #00010h,TACTL           ; Turn on Timer A
            reti                            ; Return from interrupt
                                            ;
;-------------------------------------------------------------------------------
;           Interrupt Vectors
;           These lines set up the vectors for the defined interrupts
;-------------------------------------------------------------------------------
            ORG     0FFFEh                  ; MSP430 RESET Vector
            DW      RESET                   ;
            ORG     0FFE4h                  ; Port1 Vector
            DW      PORT1_ISR               ;
            ORG     0FFF2h                  ; Timer_A0 Vector
            DW      TA0_ISR                 ;
            END
 
Cool. Thanks for sharing. I keep thinking I'm going to order that kit, but quite frankly, I have too much stuff to work on as it is that I'm not getting done.

That and the individual chips seem expensive for the functionality you get. The only thing I would get this for now, is if I really needed the low power attributes, which are really nice. Running everything off of a coin cell for a year or more is cool.
 
Last edited:
coll stuff but why o why in asm ?! ... the MSP430F2013 is more then adequate for C ... mspgcc is free and easy ... the source would be "much" smaller & easier to read + unexplainably easier to administer / change

I guess I'm not a big C fan when it comes to microcontrollers. Maybe if the operations were more complicated or the program was really crazy I might want to go to C. From my perspective it just adds another layer of complexity.
 
Cool. Thanks for sharing. I keep thinking I'm going to order that kit, but quite frankly, I have too much stuff to work on as it is that I'm not getting done.

That and the individual chips seem expensive for the functionality you get. The only thing I would get this for now, is if I really needed the low power attributes, which are really nice. Running everything off of a coin cell for a year or more is cool.

I scammed the kit from work. Someone went to a seminar a while back and the kit was just sitting around forever collecting dust so I commandeered it.
 
go to C. From my perspective it just adds another layer of complexity.
More like simplifies everything. Though I love assembly programming, I love the speed and ease of C programming even more.

I have one of those MSP430 EZ things too, as well as a couple other MSP430 chips/boards, but before I really got going with them much, ARMs distracted me and I haven't done too much with my MSP430s.
 
I scammed the kit from work. Someone went to a seminar a while back and the kit was just sitting around forever collecting dust so I commandeered it.

Well, it's only $30 for the eZ430, so even if you can't borrow one from work, it still doesn't cost a first born to get into it, which is nice. I did quite a bit of investigation into it a while ago, but like Futz, I'm way too distracted right now, and I'm also working with ARM chips.

When I say the individual chips are expensive, I mean the individual chips. An MSP430f2013 on it's own costs about $4 on Mouser and has 2k flash memory and 128B RAM. For $4, I can get a z8 Encore! with 24k flash and 2K RAM, and a host of peripherals. The only benefit I get from the MSP430 is the low power usage, which is still a big benefit, if it's needed.
 
I guess it all boils down to motivation. I wasn't really looking for a micro to play with, but there was one available, so I did. I haven't programmed in ASM or C for maybe 14 years (and that was just college lab work), so just learning how the micro worked through looking at the asm code seemed like enough for me. Relearning C and then trying to figure out how to code it would have ended up with it on a shelf somewhere...

so, it is what it is - if I ever get the urge to do another micro project, I'll definately look into using C and seeing what other controllers are out there.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top