<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ISR PWM Motor Control &#8211; The Longhorn Engineer</title>
	<atom:link href="https://longhornengineer.com/tag/isr-pwm-motor-control/feed/" rel="self" type="application/rss+xml" />
	<link>https://longhornengineer.com</link>
	<description>Robotics, Pinball, Hacking, Portables</description>
	<lastBuildDate>Tue, 20 Dec 2022 20:35:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>ISR PWM Motor Control</title>
		<link>https://longhornengineer.com/2013/01/14/isr-pwm-motor-control/</link>
		
		<dc:creator><![CDATA[Parker]]></dc:creator>
		<pubDate>Tue, 15 Jan 2013 02:13:12 +0000</pubDate>
				<category><![CDATA[HW/SW Hacks]]></category>
		<category><![CDATA[PCBA & ENG]]></category>
		<category><![CDATA[ISR PWM Motor Control]]></category>
		<guid isPermaLink="false">https://longhornengineer.com/?p=2629</guid>

					<description><![CDATA[This code runs the Low Voltage Motor Booster Pack for the MSP-430 with the MSP430G2553 chip but could easily be adapted to any microcontroller. This uses Timer1_A0 to make a timing interrupt. Using the timing interrupt it changes the duty cycle of the PWM. Supports reverse by sending the &#8220;move_motors&#8221; command negative values. Default is &#8230; <a href="https://longhornengineer.com/2013/01/14/isr-pwm-motor-control/" class="more-link">Continue reading <span class="screen-reader-text">ISR PWM Motor Control</span> <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>This code runs the <a href="https://longhornengineer.com/projects/pcb/motor-driver-booster-pack/">Low Voltage Motor Booster Pack</a> for the MSP-430 with the MSP430G2553 chip but could easily be adapted to any microcontroller. This uses Timer1_A0 to make a timing interrupt. Using the timing interrupt it changes the duty cycle of the PWM. Supports reverse by sending the &#8220;move_motors&#8221; command negative values.</p>
<p>Default is P2.0, P2.1, P2.2, and P2.3 for controlling the motor driver. P1.0 is toggled (on board LED) in the ISR.</p>
<h2>Code: CCS V5</h2>
<hr>
<p><a href="https://longhornengineer.com/code/MSP430/ISR_MOTOR_PWM_CONTROL/isr_motor_pwm.c">isr_motor_pwm.c</a><br />
<a href="https://longhornengineer.com/code/MSP430/ISR_MOTOR_PWM_CONTROL/isr_motor_pwm.h">isr_motor_pwm.h</a><br />
<a href="https://longhornengineer.com/code/MSP430/ISR_MOTOR_PWM_CONTROL/ISR_MOTOR_PWM_CONTROL_Ver1_0.zip">Project File Ver1.0</a></p>
<p><pre><code>
/*
*isr_motor_pwm.c
*Version: 1.0
*Parker Dillmann
*The Longhorn Engineer (c) 2013
*www.longhornengineer.com
*
*Check bottom of file for License.
*
*/</code></pre></p>
<p><pre><code>#include &quot;msp430g2553.h&quot;
#include &quot;isr_motor_pwm.h&quot;

#define Motor_DIR P2DIR
#define Motor_OUT P2OUT

#define Motor_A1 BIT0
#define Motor_A2 BIT1
#define Motor_B1 BIT2
#define Motor_B2 BIT3

volatile int Motor_Speed_A;
volatile int Motor_Speed_B;

volatile int Motor_isr_cnt;

void init_motors(void)
{
TA1CCTL0 = CCIE;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Enable the CCR0 interrupt
TA1CCR0 = 50000;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Set the interrupt register to &quot;trip&quot; each 50000 cycles&quot;

TA1CTL = TASSEL_2 + MC_2 + TACLR;&nbsp;&nbsp;&nbsp;&nbsp; //Timer_A Source Select; Set source to SMCLK, continuous mode, clear TAR

P1DIR |= 0x41;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// P1.0 output

Motor_DIR |= (Motor_A1 | Motor_A2 | Motor_B1 | Motor_B2);&nbsp;&nbsp;&nbsp;&nbsp;//Set Motors to output
Motor_OUT &amp;amp;= ~(Motor_A1 | Motor_A2 | Motor_B1 | Motor_B2);&nbsp;&nbsp;&nbsp;&nbsp;//Set Motor outputs to 0

Motor_isr_cnt = 1;

return;
}

void move_motors(int Speed_A, int Speed_B)
{
Motor_Speed_A = Speed_A;
Motor_Speed_B = Speed_B;
return;
}

void stop_motors(void)
{
Motor_Speed_A = 0;
Motor_Speed_B = 0;
return;
}

#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer1_A0_ISR(void)
{
//Upkeep Time
Motor_isr_cnt++;
if (Motor_isr_cnt == 512)
{
Motor_isr_cnt = 1;
}

//Motor_A PWM
if (abs(Motor_Speed_A) &amp;gt;= Motor_isr_cnt)
{
if (Motor_Speed_A &amp;gt; 0)
{
Motor_OUT |= Motor_A1;
Motor_OUT &amp;amp;= ~(Motor_A2);
}
else
{
Motor_OUT |= Motor_A2;
Motor_OUT &amp;amp;= ~(Motor_A1);
}
}
else
{
Motor_OUT &amp;amp;= ~(Motor_A1 + Motor_A2);
}

//Motor_B PWM
if (abs(Motor_Speed_B) &amp;gt;= Motor_isr_cnt)
{
if (Motor_Speed_B &amp;gt; 0)
{
Motor_OUT |= Motor_B1;
Motor_OUT &amp;amp;= ~(Motor_B2);
}
else
{
Motor_OUT |= Motor_B2;
Motor_OUT &amp;amp;= ~(Motor_B1);
}
}
else
{
Motor_OUT &amp;amp;= ~(Motor_B1 + Motor_B2);
}

</code></pre><pre><code>&nbsp;&nbsp;P1OUT ^= 0x40;&nbsp;&nbsp;&nbsp;&nbsp;// Toggle P1.0
TA1CCR0 += 500;&nbsp;&nbsp;//Add offset to CCR0
}
</code></pre></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
