Sign in to follow this  
Followers 0
Astrom27

DC PWM motor control

5 posts in this topic

HI

I wanted to share the project i am working on, it is for a small dc motor pwm controller.

I have got it working and it works pretty good. It does not use the pwm of the timer control,

but a separate ratio type control in the main function. It Uses the grace gui so i dont know if i have to

attach at the files or not if that is needed ,but here is the main part of the code that should contain enough

to work off of. Idont have the schematic right now ill work on one soon, it just uses a 3904 transistor for the

motor to have enough current, and some resistors for the bias. It uses p1.1 , p1.3 with external buttons for the

input speed change. They are tied to ground at the button and use the pull down resistors on the msp, they connect

to vcc on the button pushes to pull them high and cause the interrupt to change the speed.The TA timer is used for

button de-bounce.

 

I can include the other grace files if they are wanted..

 

Chris

 

/*
Chris Mansfield *** Pwm Dc motor control for msp430
*/


/*
* ======== Standard MSP430 includes ========
*/
#include 
#include 
/*
* ======== Grace related includes ========
*/
#include 

/*
*  ======== main ========
*/

int pwm=200;
int max;

#define MaxPwm 250
#define PWMStep 5

void main(void)
{
   CSL_init();                     // Activate Grace-generated configuration
   __enable_interrupt();           // Set global interrupt enable

   WDTCTL = WDTPW + WDTHOLD;

   int i=0;				// Jump start for motor requires more current to get 
   for(i=0;i<10000;i++)    // started.
   P1OUT= BIT0; // ** was 0 a mistake **** 

   P1IFG=0; // clear the interrupt flag

 while(1)
 {
 	if(pwm != MaxPwm)
 	{
 for(max=0;max<=MaxPwm;max+=PWMStep)
 	 {
 		if(max < pwm)
 		 P1OUT = BIT0;//output on
 		else
 		P1OUT = 0;// output 0 off 	
    }
 	}
    else
    P1OUT = BIT6 | BIT0; // max output

 }

}

volatile int pin;
volatile char depin;

void port1(void)
{
P1OUT=0;
pin=P1IN;

if(pin & BIT3)
{
 P1IFG&= ~BIT3; // clear p1.3 flag
 pwm+=PWMStep; //increase pwm
	if(pwm >= MaxPwm)
	pwm=MaxPwm; // limit max pwm 100%


  P1IE &= ~BIT3;	// debouce
  depin=1;
  TACTL = TASSEL_1 + ID_0 + MC_1 + TACLR;
  TACCR0 = 3500;
}

 if(pin& BIT1)
    {	
  P1IFG&= ~BIT1 ; // clear p1.1 flag
  pwm-=PWMStep; //	decrease pwm
	if(pwm <= 0)
	pwm=0; // limit min pwm 0%

  P1IE &= ~BIT1;	// debouce
  depin=1;
  TACTL = TASSEL_1 + ID_0 + MC_1 + TACLR;
  TACCR0 = 3500;
 }

 if(P1IFG) //clears any other flags
 P1IFG=0;
}

void WTD_ISR()
{

}

void TA_ISR()
{
if(depin == 1) // re-enable pin interuppt	
{
 P1IE |= BIT1;
 P1IE |= BIT3;
 depin=0;
}

TACTL  = MC_0;// disable clock
TACCR0 = 0;  // zero counter
}

bluehash and C_Coffie like this

Share this post


Link to post
Share on other sites

I made a quick paint schematic for it..

 

i caught a mistake .. 3904 transistor is the actual number , sorry.

post-2410-135135499703_thumb.jpg

Share this post


Link to post
Share on other sites

It is a 3v small toy motor that is common in most toys. I found a google img that is like it. Ill

try to get my camera to work and try to make a little video.

 

Im sure you could drive a larger motor if you had a motor driver for it and use the msp for the input signal. But the

3v one is good to use as it has the same voltage as the msp.

 

I just saw the small mistake on the circuit too... its a 3904 small sig trans. not a 3940......and caught a small

mistake on the code at the jump start . duh should be motor on not off.... something got mangled.* see code i fixed

it.

 

12798.jpg&sa=X&ei=bfHQTdy8HYv6sAOp6rSoCw&ved=0CAQQ8wc&usg=AFQjCNElQgFhyw_Fdy2xYzUoOT9_C78HPg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0