This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2533: Control Vibrating Mini Motor Disc with PWM in MSP430

Part Number: MSP430G2533
Other Parts Discussed in Thread: DRV2605L

Tool/software: Code Composer Studio

I'm new with PWM and MSP430. I'm trying to use a Vibrating Mini Motor Disc to control the vibration intensity with PWM using the MSP430 launchpad. This is the code I have so far. The code originally used to control the LEDs in the MSP430 launchpad with PWM. Can someone tell if I'm missing something?

main.c

#include <msp430.h> #include "timerA.h" #include "motor.h" // Global variable char LEDBit = LED1; volatile int Blink_Red = 1; volatile int Blink_Green = 0; // Function prototypes void ConfigureClockModule(void); void main(void) { // Stop the watchdog timer, and configure the clock module. WDTCTL = WDTPW + WDTHOLD; ConfigureClockModule(); // Configure timer A to generate the required interrupt. ConfigureTimerA(); _enable_interrupts(); // Infinite loop while (1) { } } void ConfigureClockModule(void) { // Configure Digitally Controlled Oscillator (DCO) using factory calibrations. DCOCTL = CALDCO_1MHZ; BCSCTL1 = CALBC1_1MHZ; BCSCTL2 |= DIVS_3; }
motor.h 

#ifndef MOTOR_H #define MOTOR_H #include <msp430.h> /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Motor #1 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #define LED1 1 #define MOTOR_BIT BIT0 #define MOTOR_PORT P1OUT #define MOTOR_DDR P1DIR #define SET_MOTOR_AS_AN_OUTPUT MOTOR_DDR |= MOTOR_BIT #define TURN_ON_MOTOR MOTOR_PORT |= MOTOR_BIT #define TURN_OFF_MOTOR MOTOR_PORT &= ~MOTOR_BIT #define TOGGLE_LED1 MOTOR_PORT ^= MOTOR_BIT // Prototypes void InitializeMotorPortPins(void); #endif
motor.c

#include "motor.h" void InitializeMotorPortPins(void) { // Initialize the value and port pin direction TURN_OFF_LED1; SET_MOTOR_AS_AN_OUTPUT; }
timerA.h

#ifndef TIMER_A_H #define TIMER_A_H #include <msp430.h> // Prototypes void ConfigureTimerA(void); #endif
timerA.c

#include <motor.h> #include "timerA.h" int direction = 1; int pause = 0; extern int Blink_Green, Blink_Red; void ConfigureTimerA(void) { TA0CTL = (MC_0 | TACLR); //Choose SMCLK, select //input divider //start in up mode TA0CTL |= (TASSEL_2 | MC_1 | ID_3 | TAIE); //Assign a value to Timer A0 Capture Compare Register 0 //0xF423 TA0CCR0 = 124; //set length of timer to 124 tick TA0CCR1 = 0; //start the point to turn off at value 0 in CCR1; //enable interrupt TA0CCTL0 |= CCIE; TA0CCTL1 |= CCIE; } #pragma vector = TIMER0_A0_VECTOR // Timer a interrupt service routine __interrupt void Timer0_A0_routine(void) { if (TA0CCR1 == 0) { direction = 1; } else if (TA0CCR1 == TACCR0) { direction = 0; } if (direction == 1 && pause == 0) { TA0CCR1 += 1; } else if (direction == 0 && pause == 0) { TA0CCR1 -= 1; } } #pragma vector = TIMER0_A1_VECTOR // Timer a interrupt service routine __interrupt void Timer0_A01_routine(void) { switch (TAIV) { case TA0IV_NONE: break; case TA0IV_TACCR1: if (TACCR1 != 0) { TURN_ON_MOTOR; } //TA0CCTL1 &= ~CCIFG; break; case TA0IV_TAIFG: if (TACCR1 != 0) { TURN_OFF_MOTOR; } break; default: for (;;) ; } }

**Attention** This is a public forum