<?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: Could anyone told me How to make the timer work on the PWM mode?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1046</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:20:56 +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=1046" rel="self" type="application/rss+xml" />

		<item>
			<title>gulu2065 on "Could anyone told me How to make the timer work on the PWM mode?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1046#post-6435</link>
			<pubDate>Tue, 20 Sep 2011 14:41:04 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6435@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;HardwareTimer timer(1);&#60;br /&#62;
void setup() {&#60;br /&#62;
pinMode (6, PWM);&#60;br /&#62;
Timer1.setPrescaleFactor(1);&#60;br /&#62;
Timer1.setOverflow(44);&#60;br /&#62;
Timer1.setMode(TIMER_CH1,TIMER_PWM);&#60;br /&#62;
Timer1.setCompare(1,22);&#60;br /&#62;
}&#60;br /&#62;
void loop() {&#60;br /&#62;
}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "Could anyone told me How to make the timer work on the PWM mode?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1046#post-6434</link>
			<pubDate>Tue, 20 Sep 2011 14:40:24 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6434@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;poslathian&#60;br /&#62;
I have got 1.6Mhz signal with your code.&#60;br /&#62;
Thanks a lot.&#60;br /&#62;
Here is the code. I hope could help others!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Could anyone told me How to make the timer work on the PWM mode?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1046#post-6414</link>
			<pubDate>Tue, 20 Sep 2011 11:54:23 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">6414@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gulu, you should be able to use the setPeriod function to get very high output frequencies. Something like 1.6MHz should be doable. First, find out what timer the PWM pin you are using is attached to. For example, for Maple, this table is here: &#60;a href=&#34;http://leaflabs.com/docs/hardware/maple.html#maple-timer-map&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple.html#maple-timer-map&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If you were using Pin 6 as your output, you can see from the table that this is attached to Timer1, channel 1. &#60;/p&#62;
&#60;p&#62;To get the timer running *really* fast, use the &#34;setPrescaleFactor&#34; function:&#60;br /&#62;
&#60;code&#62;Timer1.setPrescaleFactor(1);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;That should get the timer going at 72MHz. &#60;/p&#62;
&#60;p&#62;Now, lets say you wanted a 50% square wave at 1.6MHz, 72MHz/1.6MHz = 45, conveniently an even number! So set your overflow to 45&#60;/p&#62;
&#60;p&#62;&#60;code&#62;Timer1.setOverflow(45);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Notice that since we overflow at 45, your max PWM value will be 45, not 255 or 65535! Assuming you set pin 6 in pwmOutput mode, you should be able to just do pwmWrite(22) to get your 50% wave at 1.6MHz. To manually set this up, you could do:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;Timer1.setMode(TIMER_PWM);
Timer1.setCompare(1,22);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Let me know if this works as I didnt actually run this!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "Could anyone told me How to make the timer work on the PWM mode?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1046#post-6411</link>
			<pubDate>Tue, 20 Sep 2011 11:37:02 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6411@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;robodude666, Thanks.&#60;br /&#62;
Do you mean the timer.setPeriod(). But with this I could only reach a low frequency, maybe at most 1Mhz.&#60;br /&#62;
Do you know how to configure the timer directly on the PWM mode and produce higher frequency I want?&#60;br /&#62;
Thanks
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "Could anyone told me How to make the timer work on the PWM mode?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1046#post-6404</link>
			<pubDate>Tue, 20 Sep 2011 10:16:19 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">6404@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I would recommend looking at the &#60;a href=&#34;http://leaflabs.com/docs/pwm.html&#34;&#62;PWM&#60;/a&#62; documentation, and more specifically the &#60;a href=&#34;http://leaflabs.com/docs/lang/api/pwmwrite.html#lang-pwmwrite&#34;&#62;pwmWrite&#60;/a&#62; function.&#60;/p&#62;
&#60;p&#62;The pwmWrite function is similar to analogWrite, except that it uses the STM32's full 12-bit capability. The duty cycle is based on a value from 0 to 65535. Setting it to 32767 will give you a roughly 50% duty cycle. If you desire a different frequency, the &#60;a href=&#34;http://leaflabs.com/docs/lang/api/analogwrite.html#difference-4-pwm-frequency&#34;&#62;documentation&#60;/a&#62; describes how it can be changed as well.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "Could anyone told me How to make the timer work on the PWM mode?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1046#post-6395</link>
			<pubDate>Mon, 19 Sep 2011 16:52:28 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6395@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Anybody can help?&#60;br /&#62;
Thanks!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gulu2065 on "Could anyone told me How to make the timer work on the PWM mode?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1046#post-6389</link>
			<pubDate>Sun, 18 Sep 2011 21:20:44 +0000</pubDate>
			<dc:creator>gulu2065</dc:creator>
			<guid isPermaLink="false">6389@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I want the timer work at the PWM mode and produce a 1.6Mhz frequency.&#60;/p&#62;
&#60;p&#62;This is the code I write.&#60;br /&#62;
However, it do not work correctly and only produce a 549.5 Hz frequency.&#60;br /&#62;
which is the initial PWM frequency, I guess. The timer do not work.&#60;br /&#62;
Could anyone told me how to fix it?&#60;/p&#62;
&#60;p&#62;#include &#38;lt;timer.h&#38;gt;&#60;br /&#62;
HardwareTimer timer(4);&#60;br /&#62;
void setup() {&#60;br /&#62;
pinMode(0, PWM);&#60;br /&#62;
pinMode(24, PWM);&#60;br /&#62;
pinMode(28, PWM);&#60;br /&#62;
Timer4.pause();&#60;br /&#62;
Timer4.setPrescaleFactor(1);&#60;br /&#62;
Timer4.setOverflow(45);&#60;br /&#62;
Timer4.setChannel4Mode(TIMER_PWM);&#60;br /&#62;
Timer4.resume();&#60;br /&#62;
Timer4.refresh();&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void loop() {&#60;/p&#62;
&#60;p&#62;}
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
