<?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: Issue with PWM and timer setup</title>
		<link>http://forums.leaflabs.com/topic.php?id=1130</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:24:49 +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=1130" rel="self" type="application/rss+xml" />

		<item>
			<title>bart_dood on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-7008</link>
			<pubDate>Wed, 26 Oct 2011 18:22:16 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">7008@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hey, I am fairly close to being finished. My timed interrupt works perfectly now, all the math functions for the timed interrupt happen in around 55-60 microseconds so time to spare. My external interrupts only add a small amount of time onto this, around 5 microseconds so perfectly acceptable.&#60;br /&#62;
I've checked different cases and the numbers coming out make sense for the PWM duty cycles, I want to double check this though.&#60;/p&#62;
&#60;p&#62;It still might take me a few weeks to turn a motor, I'll start doing some temporary wiring from my control box to the rest of the electronics over the new week.&#60;/p&#62;
&#60;p&#62;I'll be happy to have everything working by christmas, it would be great to get it running sooner than that though.&#60;/p&#62;
&#60;p&#62;The code is surprisingly compact, I don't even use library functions. Library functions don't save any cycles (in fact they seem to increase time lag a little), perhaps once this code is out in the public domain others will tidy it up and maybe break it into libraries.&#60;br /&#62;
However the code I wrote does have some specific things in it so for generic use it will need modification.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-6996</link>
			<pubDate>Wed, 26 Oct 2011 14:08:04 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6996@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bart_dood - I am pleased you've got it going. So have you a prototype BDC control close to working?&#60;/p&#62;
&#60;p&#62;BTW - I have an STM32F4 evaluation board. Hardware Floating point is so quick, and the timers are capable of running much quicker too, so it seems like a good fit for this sort of thing.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-6991</link>
			<pubDate>Wed, 26 Oct 2011 10:17:58 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">6991@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi, I have made all the changes to the timer setup and interrupt time and everything seems to work as it should.&#60;br /&#62;
Having a PWM range of 0-3600 instead of 0-7200 isn't a show stopper after thinking it over some more.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-6983</link>
			<pubDate>Tue, 25 Oct 2011 15:53:45 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6983@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bart_dood - sorry I didn't get any email.&#60;/p&#62;
&#60;p&#62;Yes, 50microseconds * 72MHz = 3600, and if you want a symmetric (up/down count) PWM, half that :-(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-6964</link>
			<pubDate>Mon, 24 Oct 2011 19:04:01 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">6964@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi gbulmer, I actually just wrote an e-mail I think you were copied on. I wasn't sure I'd get an answer on the forum because its not a regular question to ask.&#60;/p&#62;
&#60;p&#62;My prescalar is already 1 so I can't lower it, so the only thing left to change is the overflow number, its currently 7200 so I can change it to 3600. The bad news is I effectively lose bit resolution which is why I was hoping to find another way around this. Its probably ok though.&#60;/p&#62;
&#60;p&#62;I also will have to change my timed interrupt from 100 microseconds to 50 as this is running twice as slow as well.&#60;/p&#62;
&#60;p&#62;Thanks for the help.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-6962</link>
			<pubDate>Mon, 24 Oct 2011 18:43:02 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6962@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;bart_dood - centre-aligned/symmetric PWM runs at half the frequency because the timer's counter counts up (one cycle) then counts down (second cycle) to create a single symmetric pulse. So it uses &#60;strong&#62;two&#60;/strong&#62; cycles to make each pulse.&#60;br /&#62;
(Think of a triangle wave, and the state of the pin flips on each compare match.)&#60;/p&#62;
&#60;p&#62;Double the frequency by halving the prescaler, and you'll be back to where (I think) you want to be.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-6957</link>
			<pubDate>Mon, 24 Oct 2011 12:54:59 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">6957@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi Folks, I've been doing a little searching and found this set of code inside the 'timers.h' file:&#60;/p&#62;
&#60;p&#62;/**&#60;br /&#62;
 * Used to configure the behavior of a timer channel.  Note that not&#60;br /&#62;
 * all timers can be configured in every mode.&#60;br /&#62;
 */&#60;br /&#62;
/* TODO TIMER_PWM_CENTER_ALIGNED, TIMER_INPUT_CAPTURE, TIMER_ONE_PULSE */&#60;br /&#62;
typedef enum timer_mode {&#60;br /&#62;
    TIMER_DISABLED, /**&#38;lt; In this mode, the timer stops counting,&#60;br /&#62;
                         channel interrupts are detached, and no state&#60;br /&#62;
                         changes are output. */&#60;br /&#62;
    TIMER_PWM, /**&#38;lt; PWM output mode. This is the default mode for pins&#60;br /&#62;
                    after initialization. */&#60;br /&#62;
    /* TIMER_PWM_CENTER_ALIGNED, /\**&#38;lt; Center-aligned PWM output mode. *\/ */&#60;br /&#62;
    TIMER_OUTPUT_COMPARE, /**&#38;lt; In this mode, the timer counts from 0&#60;br /&#62;
                               to its reload value repeatedly; every&#60;br /&#62;
                               time the counter value reaches one of&#60;br /&#62;
                               the channel compare values, the&#60;br /&#62;
                               corresponding interrupt is fired. */&#60;br /&#62;
    /* TIMER_INPUT_CAPTURE, /\**&#38;lt; In this mode, the timer can measure the */&#60;br /&#62;
    /*                           pulse lengths of input signals. *\/ */&#60;br /&#62;
    /* TIMER_ONE_PULSE /\**&#38;lt; In this mode, the timer can generate a single */&#60;br /&#62;
    /*                      pulse on a GPIO pin for a specified amount of */&#60;br /&#62;
    /*                      time. *\/ */&#60;br /&#62;
} timer_mode;&#60;/p&#62;
&#60;p&#62;This seems to have some code for center aligned PWM hidden in it, is this where I should be enabling center/symmetric PWM? Thanks
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bart_dood on "Issue with PWM and timer setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1130#post-6955</link>
			<pubDate>Mon, 24 Oct 2011 01:35:53 +0000</pubDate>
			<dc:creator>bart_dood</dc:creator>
			<guid isPermaLink="false">6955@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi Folks, I have this code in my setup to change the PWM frequency to 10khz. It seems to work fine normally, I use the pins 6,7,8 only for PWM output:&#60;/p&#62;
&#60;p&#62;timer1.pause();&#60;br /&#62;
timer1.setPrescaleFactor(1);&#60;br /&#62;
timer1.setOverflow(7200);&#60;br /&#62;
timer1.refresh();&#60;br /&#62;
timer1.resume();&#60;/p&#62;
&#60;p&#62;However I have to use center or symmetric PWM in my code not edge aligned PWM which is stock for the IDE.&#60;br /&#62;
To achieve this I modified the file 'boards.cpp' located at: maple/hardware/leaflabs/cores/maple for version 0.0.12&#60;/p&#62;
&#60;p&#62;I changed the line: &#60;/p&#62;
&#60;p&#62;regs-&#38;gt;CR1 = TIMER_CR1_ARPE;&#60;/p&#62;
&#60;p&#62;to&#60;/p&#62;
&#60;p&#62;regs-&#38;gt;CR1 = TIMER_CR1_ARPE&#124;(1&#38;lt;&#38;lt;5);&#60;/p&#62;
&#60;p&#62;Which works to make the PWM center/symmetric and I've confirmed this via a scope. The problem is that it seems to be changing the PWM frequency, so the setup code above now runs at half the speed, so 5khz instead of 10khz.&#60;br /&#62;
The other thing I've noticed is that I have a timed interrupt which normally runs every 100microseconds. This works fine normally until I make the change to the boards.cpp file (for center PWM). Then it runs at half speed. I have confirmed all this via the scope.&#60;/p&#62;
&#60;p&#62;Does anyone know why this is happening and is there any way around it? I can think of some work arounds but it involves a lower resolution in my PWM output etc. I'd rather try and fix the main problem first.&#60;/p&#62;
&#60;p&#62;Thanks for your time!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
