Jump to content

  • Log In with Google      Sign In   
  • Create Account

Follow us at the 2014 NY Maker Faire on twitter or the sidebar. We will be there with Eric(spirilis) and Rob(Robg). We'll be updating vine as well as twitter.


Photo

DC PWM motor control


  • Please log in to reply
4 replies to this topic

#1 Astrom27

Astrom27

    Member

  • Members
  • PipPip
  • 10 posts

Posted 15 May 2011 - 08:47 PM

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 <msp430.h>
#include <msp430g2231.h> 
/*
 * ======== Grace related includes ========
 */
#include <ti/mcu/msp430/csl/CSL.h>

/*
 *  ======== 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

#2 bluehash

bluehash

    Site Admin

  • Administrators
  • 5,428 posts

Posted 15 May 2011 - 08:53 PM

Thanks for sharing astrom27. Make sure you add this to the Project of the Month Contest. A pic of your setup will also be nice.

Stellarisiti - Join the new Tiva-C/Stellaris ARM Forums discussing Tiva-C(Stellaris) Microcontrollers.

C2kCentral - C2000 News, Projects and Forums
43oh - MSP430 Discussion, News, Projects and Hacks
MachineGrid - Robots, Hacks and Technology!


#3 Astrom27

Astrom27

    Member

  • Members
  • PipPip
  • 10 posts

Posted 15 May 2011 - 09:11 PM

I made a quick paint schematic for it..

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

Attached Thumbnails

  • Motor.JPG


#4 C_Coffie

C_Coffie

    Noob Class

  • Members
  • 5 posts

Posted 16 May 2011 - 01:50 AM

What motor are you driving with this?

#5 Astrom27

Astrom27

    Member

  • Members
  • PipPip
  • 10 posts

Posted 16 May 2011 - 09:44 AM

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.

[img]http://www.google.com/url?source=imgres&ct=img&q=http://www.mpja.com/images/12798.jpg&sa=X&ei=bfHQTdy8HYv6sAOp6rSoCw&ved=0CAQQ8wc&usg=AFQjCNElQgFhyw_Fdy2xYzUoOT9_C78HPg[/img]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users