<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Using timers to control length of PWM output for a stepper motor</title>
		<link>http://forums.leaflabs.com/topic.php?id=1086</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:26:21 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1086" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Using timers to control length of PWM output for a stepper motor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1086#post-6743</link>
			<pubDate>Mon, 03 Oct 2011 19:06:32 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6743@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;motor456 - I forgot to say, when I have done stepper motor experiments, I initially tried to 'stop' the motor instantly, i.e. in zero steps. Your code seems to be the same. &#60;/p&#62;
&#60;p&#62;My motor had a reasonable amounts of inertia, so if the speed was high enough,  it wasn't able to stop instantly, it bumped on a step or two. I had to slow it down by &#34;lengthening&#34; the final few steps.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Using timers to control length of PWM output for a stepper motor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1086#post-6741</link>
			<pubDate>Mon, 03 Oct 2011 18:16:46 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6741@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;motor456,&#60;/p&#62;
&#60;p&#62;Have you tried this using the latest version of Maple IDE? I seem to recall some timer bugs getting fixed since 0.0.9.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>motor456 on "Using timers to control length of PWM output for a stepper motor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1086#post-6740</link>
			<pubDate>Mon, 03 Oct 2011 18:08:01 +0000</pubDate>
			<dc:creator>motor456</dc:creator>
			<guid isPermaLink="false">6740@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have tried the pause/resumes and reversing order of timers, but still seem to have the same result. I need this to be pretty accurate so I can't have a chance of being off all the time. The USB interrupt is still on, but I will need it as I have a GUI that will get motor position and sends data to the Maple. &#60;/p&#62;
&#60;p&#62;Not sure if their is an interrupt queue for who gets in first? Maybe the PWM output is still at a floating voltage state when the interrupt happens and the stepper motor hardware changes based on this voltage?&#60;/p&#62;
&#60;p&#62;I think I will just make my own PWM function using loops instead of a timer and interrupt. Overhead maybe larger, but I am not going at fast speeds.&#60;/p&#62;
&#60;p&#62;Thanks for the help
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Using timers to control length of PWM output for a stepper motor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1086#post-6732</link>
			<pubDate>Sun, 02 Oct 2011 13:39:22 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6732@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Have you got any other interrupts on, like USB and Systick? They might be causing some jitter i they are not synchronised with the timers you are using.&#60;/p&#62;
&#60;p&#62;You can turn off the USB interrupt, but be aware Maple will need to be reset by hand to alow uploads (see &#60;a href=&#34;http://leaflabs.com/docs/lang/api/serialusb.html#lang-serialusb)&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/lang/api/serialusb.html#lang-serialusb)&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;You can turn off systick &#60;a href=&#34;http://leaflabs.com/docs/libmaple/api/systick.html#libmaple-systick&#34;&#62;&#60;code&#62;systick_disable()&#60;/code&#62;&#60;/a&#62;&#60;br /&#62;
If this reduces jitter, then they are likely a cause.&#60;/p&#62;
&#60;p&#62;Maybe the time it takes to set up the two timers might be a cause of the problem. If there is some jitter during setup, it would show up in the end results.&#60;br /&#62;
You could test that theory very quickly by reversing the order you set up the two timers. If it is the delay in setting things up, then the motor will underrun 1 or two steps.&#60;/p&#62;
&#60;p&#62;If that is the case, then there are a few options.&#60;br /&#62;
A  simples way is to pause both timers while you are setting them up, and do two resumes one immediately after the other.&#60;br /&#62;
There will still be a window of time to introduce a bit of jitter, but it should be less, and if it does improve the situation, increases the evidence that it is that delay.&#60;/p&#62;
&#60;p&#62;I am pretty certain one timer can be used to control another, so it may be feasible to set up the hardware in a way that works. How comfortable are you with microcontrollers? Is that something you'd feel okay to tackle? (I ask because I haven't any time to help)&#60;/p&#62;
&#60;p&#62;This technique, if it is practical, may be imune from interrupts &#38;amp; jitter.&#60;/p&#62;
&#60;p&#62;(full discolsure: I am not a member of LeafLabs staff)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>motor456 on "Using timers to control length of PWM output for a stepper motor"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1086#post-6731</link>
			<pubDate>Sun, 02 Oct 2011 10:30:15 +0000</pubDate>
			<dc:creator>motor456</dc:creator>
			<guid isPermaLink="false">6731@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;MAPLE Rev5, IDE 0.0.9&#60;/p&#62;
&#60;p&#62;Right now I have the PWM output working for the correct freq and Duty. I am trying to have the PWM output only run so long controlling the steps of a stepper motor. I know the number of steps, freq and duty. I tried using a second timer to control this, but it either over runs or not constant every time. Sometimes it works, but mostly 1 or more steps off.&#60;/p&#62;
&#60;p&#62;Below I have it run .8sec(200 steps for 1 turn of motor at 250hz per step), delay 2 sec and restart for testing. How can you make the interrupt more constant when nothing else is going on? Even if the interrupt has overhead and would be off, it should be off the same amount every time right?&#60;/p&#62;
&#60;p&#62;;&#60;br /&#62;
int pwmcount=0;&#60;br /&#62;
void PWM_STOP(void);&#60;/p&#62;
&#60;p&#62;void setup(){&#60;br /&#62;
  Timer3.setPeriod(4000); //.004sec,&#60;br /&#62;
  pinMode(28,PWM);        //pin 28 PWM output&#60;br /&#62;
  pwmWrite(28,57500);     //almost full duty&#60;/p&#62;
&#60;p&#62;  Timer4.setChannel1Mode(TIMER_OUTPUTCOMPARE);&#60;br /&#62;
  Timer4.setPeriod(.8*1000000); //1000000=1sec, 200step per turn, .004*200=.8 for 1 turn&#60;br /&#62;
  Timer4.setCompare1(1);&#60;br /&#62;
  Timer4.attachCompare1Interrupt(PWM_STOP);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void loop(){}&#60;/p&#62;
&#60;p&#62;void PWM_STOP(void)&#60;br /&#62;
{&#60;br /&#62;
  pwmcount=pwmcount+1; //easy way to stop start PWM&#60;/p&#62;
&#60;p&#62;  if((pwmcount%2)==0)  //stop the PWM&#60;br /&#62;
  {&#60;br /&#62;
    pinMode(28,INPUT); //stop PWM set as input&#60;br /&#62;
    Timer4.pause();    //pause timer interrupt&#60;br /&#62;
    delay(2000);       //delay 2 sec&#60;br /&#62;
    Timer4.generateUpdate();  //reset timer&#60;br /&#62;
    Timer4.resume();          //resume timer&#60;br /&#62;
  }&#60;br /&#62;
  else&#60;br /&#62;
    pinMode(28,PWM); //turn PWM back on&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;Thanks
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
