Jump to content
43oh

LaunchPad, DC Motor, PWM


Recommended Posts

Here's my little demo of how to use SN754410 with LaunchPad.

Timer's CCR1 is used to control duty cycle via P1.2

P1.0 and P1.1 to control direction (setting both to the same level, 0 or 1, will cause dynamic breaking.)

Vcc1 of SN754410 is connected to LP's Vcc, Vcc2 is connected to a separate power supply (6V in my case.)

Between outputs and Vcc/Vss I put some Schottky's just in case.

 

EDIT: SN754410 logic side (Vcc1) requires 5V, it may not work correctly when powered from LP's Vcc.

 

Next week I will add more examples with bigger motor and some MOSFETs.

 

 

post-197-135135498069_thumb.png

 

#include 

// DEMO counter
unsigned int demoCounter = 0;

void main(void) {
   WDTCTL = WDTPW + WDTHOLD;           // Stop WDT

   P1OUT |= BIT1;						// Direction control - left
   P1OUT &= ~BIT0;						// Direction control - right
   									// Both 0 or 1 - dynamic break
   P1DIR |= BIT0 + BIT1 + BIT2;		// Bit 2 is connected to enable and will be used for PWM

   P1SEL |= BIT2;                      // P1.2 TA1 option select
   CCTL0 = CCIE;                       // CCR0 interrupt enabled
   CCR0 = 1000;						// ~8ms
   CCTL1 = OUTMOD_3;                   // CCR1 set/reset
   CCR1 = 950;                         // CCR1 duty cycle, slow in the beginning
   TACTL = TASSEL_2 + MC_1 + ID_3;     // SMCLK/8, upmode

   _bis_SR_register(LPM0_bits + GIE);  // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void) {

   // DEMO movement
   demoCounter++;
   if(demoCounter == 800)
       CCR1 = 900;
   if(demoCounter == 1600)
       CCR1 = 500;
   if(demoCounter == 2000)
       CCR1 = 250;
   if(demoCounter == 2400)
       CCR1 = 0;
   if(demoCounter == 2800)
       CCR1 = 900;
   if(demoCounter == 3200) {
       P1OUT |= BIT0; // switch direction
       P1OUT &= ~BIT1;
   }
   if(demoCounter == 3600)
       CCR1 = 0;
   if(demoCounter == 4000)
       CCR1 = 900;
   if(demoCounter == 4400) {
       P1OUT |= BIT1; // switch direction
       P1OUT &= ~BIT0;
   }
   if(demoCounter == 4800) {
       P1OUT |= BIT0; // switch direction
       P1OUT &= ~BIT1;
   }
   if(demoCounter == 5200) {
       CCR1 = 500;
       P1OUT |= BIT1; // switch direction
       P1OUT &= ~BIT0;
       demoCounter = 0;
   }
   // END DEMO movement
}

Link to post
Share on other sites
  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Here's my little demo of how to use SN754410 with LaunchPad. Timer's CCR1 is used to control duty cycle via P1.2 P1.0 and P1.1 to control direction (setting both to the same level, 0 or 1, will cau

TP3 will give you 5V if not TP1 will I can't remember. I solder a socket so I can use it when ever I want.   (provided by gatesphere)

Have had the same problem off and on. I have needed to design a few H bridge implementations for several different projects, and while not all ran off the LaunchPad, all were MSP430 projects... so the

Posted Images

As I was working on my next experiment with 754410, it has suddenly stopped working. When I was testing it, everything was suggesting that the chip is fried. A quick look at the data sheet and the problem is solved, Vcc1, the logic side, requires 5V supply.

Logic inputs can still be driven with 3.3V levels, but the Vcc1 has to be 5V. That said, most of the times LP's power is enough, it's just sometimes that 754410 is not working.

Link to post
Share on other sites
  • 3 weeks later...

Have had the same problem off and on. I have needed to design a few H bridge implementations for several different projects, and while not all ran off the LaunchPad, all were MSP430 projects... so the same 3.3V issue. I have ended up using a buffer and inverter as standard practice to; A) separate the MCU from the rest of the circuit, and B) rectify the VCC issue, and cut pin count per motor down to 2 pins. The attached circuit doesn't even require a reference ground to the MCU. The final product in regards to that schematic has a pair of 24v 8Amp DC motors running off PWM output from a G2231 MCU.post-116-135135499042_thumb.jpg

Link to post
Share on other sites
  • 4 weeks later...
  • 5 months later...
  • 3 years later...

@mfpek: Could you please give a bit more detail? What do ou mean 'control it with buttons'? With a microcontroller? If so, MSP430 or a different one?  No microcontroller? I don't think anyone can really provide an answer without more information.

 

Is this for a school assignment? (if so, it is good practice tosay so and to tell us what school/course/level) Also, is English not your primary language? Again, that is something worth mentioning before you get the 'sounds like homework, ask your teacher' response.

Link to post
Share on other sites

It's very simple @@mfpek, just configure 2 pins as inputs with interrupts and add ISR

 

Something like this

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void) {

	if (P1IFG & SWITCH1_BIT) {
		//faster
		if(CCR1 < 1000) // CCR1 < CCR0
		    CCR1++;
		P1IFG &= ~SWITCH1_BIT;
	}

	if (P1IFG & SWITCH2_BIT) {
		//slower
		if(CCR1 > 0)
		    CCR1--;
		P1IFG &= ~SWITCH2_BIT;
	}
}
Link to post
Share on other sites

okey then first things first. i am an electronics engineering student, english is not my native tongue and i have a semester project about controlling a dc motor with msp430. project includes direction and pwm controlled acceleration. i've done the direction part using a l293d so far. circuit schema that i am using is in attachments and code is;

 

#include "io430.h"
#include "in430.h"
 
#define Button_forward P1IN_bit.P0
#define Button_reverse P1IN_bit.P1
#define Button_Stop P1IN_bit.P2
#define IN_1 P2OUT_bit.P0
#define IN_2 P2OUT_bit.P1
#define EN_A P2OUT_bit.P2
#define EN_B P2OUT_bit.P3
 
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
 
DCOCTL=CALDCO_1MHZ;
BCSCTL1=CALBC1_1MHZ;
 
P1DIR &= ~(BIT0 + BIT1 + BIT2);
P2OUT = 0x00;
P2DIR |= BIT0 + BIT1 + BIT2 + BIT3;
 
EN_A = 1;
EN_B = 0;
 
for(;;)
{
if(Button_forward)
{
IN_1 = 1;
IN_2 = 0;
}
else if(Button_reverse)
{
IN_1 = 0;
IN_2 = 1;
}
else if(Button_Stop)
{
IN_1 = 0;
IN_2 = 0;
}
}
}

 

i am not good at embedded coding so i am trying to keep it as possible as easy and understandable.

 

so here is the deal. i need two more buttons for slowing down and speeding up the motor. that's where i am lost.

post-39242-0-69935200-1418033252_thumb.png

Link to post
Share on other sites

Any pin you want to use that is not already in use will work  if you don't use interrupts. If you do use interrupts, then the pin must support that, which should include the unused P1 pins.

 

If you don't need the start-stop function, you could re purpose the existing buttons for increase forward/decrease reverse and increase reverse/decrease forward. If you need to keep the existing function, add two more. In and case, with the run forward and run reverse as it is, I would put in code to protect from changing direction while the motor is running, including a delay to insure that the motor is stopped before restart.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...