Sunday 27 September 2020

MSP430 with a DC motor

The explanation for this project can be found here: Video explanation

Subscribe to the channel for more such content.

Below is the code:


#include <msp430g2553.h>

int count = 0;
void main()
{
WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

P1DIR |= BIT6|BIT2;
P1SEL |= BIT6; //P1.6 TA0.1 output signal for DC motor
P1OUT &= ~(BIT2);  //P1.2 for DC motor 

P1DIR &= ~BIT3; //Button P1.3
P1REN |= BIT3;
P1OUT |= BIT3;
P1IE |= BIT3;
P1IES |= BIT3;
CCR0 = 1000-1;
CCTL1 = OUTMOD_7;

__enable_interrupt();
__low_power_mode_0();



}
#pragma vector=PORT1_VECTOR
__interrupt void P1_Func()
{
int i = 0;
count = count + 1;
switch (count)
{
case 1: CCR1 = 850-1;
TACTL = TASSEL_2 + MC_1;
break;
case 2: CCR1 = 250-1;
count = 0;
break;
}

while(i<500)
{
if((P1IN&BIT3))
i++;
else
i=0;
}
P1IFG &= ~BIT3;
}