<?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: Advanced Timer Complementary Output Setup</title>
		<link>http://forums.leaflabs.com/topic.php?id=2000</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:23:50 +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=2000" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "Advanced Timer Complementary Output Setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2000#post-11502</link>
			<pubDate>Mon, 02 Jul 2012 15:03:36 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11502@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;hi emburl,&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
For now I'll post the code
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;thanks for posting! i've often wondered about using the complementary outputs myself, so it's nice to have some working code out there. for longer code listings like your first one, though, please follow the &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=994&#34;&#62;guidelines for posting&#60;/a&#62; and use pastebin (or something like it) instead of posting them directly.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>emburl on "Advanced Timer Complementary Output Setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2000#post-11483</link>
			<pubDate>Sun, 01 Jul 2012 22:26:33 +0000</pubDate>
			<dc:creator>emburl</dc:creator>
			<guid isPermaLink="false">11483@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;So as it turns out, the only thing that was making this problematic was the shared output on pin55. I haven't worked out how to disable at setup time, but to get a complimentary output for testing all thats needed is to initalise both pins as PWM using pinMode and set the CCER bits:&#60;/p&#62;
&#60;p&#62;Which looks alot nicer..&#60;/p&#62;
&#60;p&#62;void setup(){&#60;br /&#62;
      HardwareTimer timer8 = HardwareTimer(8);&#60;/p&#62;
&#60;p&#62;      timer8.setPrescaleFactor(1);&#60;br /&#62;
      timer8.setOverflow(65535/4);&#60;/p&#62;
&#60;p&#62;      pinMode(13, PWM);     //Ideally these would be done as bit wise as I dont know exactly whats being set here..&#60;br /&#62;
      pinMode(55, PWM);&#60;/p&#62;
&#60;p&#62;      timer_dev *t = TIMER8;          //refers t to Timer 8 memory location, how to read back?&#60;br /&#62;
      timer_reg_map r = t-&#38;gt;regs; &#60;/p&#62;
&#60;p&#62;      bitSet(r.adv-&#38;gt;CCER,0);         //this should enable complimentary outputs&#60;br /&#62;
      bitSet(r.adv-&#38;gt;CCER,2);&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;void loop(){&#60;/p&#62;
&#60;p&#62;  pwmWrite(13, 15000);  //should complement on pin55 (Native)&#60;br /&#62;
  pwmWrite(55, 0);      //this is just to hold timer3 channel 2 low&#60;/p&#62;
&#60;p&#62;}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>emburl on "Advanced Timer Complementary Output Setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2000#post-11482</link>
			<pubDate>Sun, 01 Jul 2012 21:27:20 +0000</pubDate>
			<dc:creator>emburl</dc:creator>
			<guid isPermaLink="false">11482@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Cheers Crenn&#60;/p&#62;
&#60;p&#62;I have been working through the reference manual, (the beefy 1023 document that it is..). not datasheet as I said. I've got it complementing now, although I need to declare both pins as PWM using the pinMode() command, then bitbash away in the registers (its not very elegant at this stage). &#60;/p&#62;
&#60;p&#62;My issue now is that the complemented output is changing, where the non complement is static, as though the compare value is incrementing for the complemented channel, once it exceeds the threshold. I'll think about it some more and post when I work it out, it probably trivial.&#60;/p&#62;
&#60;p&#62;For now I'll post the code, Ive set and cleared individual bits explicitly so I could keep track of what was being changed. It may help someone else looking at this. &#60;/p&#62;
&#60;p&#62;void setup(){&#60;br /&#62;
      HardwareTimer timer8 = HardwareTimer(8);&#60;/p&#62;
&#60;p&#62;//    timer8.pause();&#60;br /&#62;
      timer8.setPrescaleFactor(1);&#60;br /&#62;
      timer8.setOverflow(65535/4);&#60;br /&#62;
      timer8.setCount(0);&#60;br /&#62;
//    timer8.refresh();   &#60;/p&#62;
&#60;p&#62;    pinMode(13, PWM);                 //Not sure what this is seting in the reg's&#60;br /&#62;
    pinMode(55, PWM);&#60;/p&#62;
&#60;p&#62;      timer_dev *t = TIMER8;          //refers t to Timer 8 memory location, how to read this back?&#60;br /&#62;
      timer_reg_map r = t-&#38;gt;regs; &#60;/p&#62;
&#60;p&#62;      bitClear(r.adv-&#38;gt;CR1,0);        //disable clock to set centre alligned mode&#60;br /&#62;
      bitClear(r.adv-&#38;gt;BDTR,8);       //unnlock BDTR register, could probably keep lock level 1 on&#60;br /&#62;
      bitClear(r.adv-&#38;gt;BDTR,9);&#60;br /&#62;
      bitClear(r.adv-&#38;gt;CCER,0);       // clear TIM8_CCER bit 0 to set CCMR bits&#60;/p&#62;
&#60;p&#62;      bitClear(r.adv-&#38;gt;CCMR1,0);      //This should configure channel1 of Timer8 as an output&#60;br /&#62;
      bitClear(r.adv-&#38;gt;CCMR1,1);&#60;br /&#62;
      bitSet(r.adv -&#38;gt;CCMR1,4);       //Set PWM mode2 channel 1 timer8&#60;br /&#62;
      bitSet(r.adv -&#38;gt;CCMR1,5);&#60;br /&#62;
      bitSet(r.adv -&#38;gt;CCMR1,6);&#60;br /&#62;
      bitSet(r.adv -&#38;gt;CCMR1,3);       //Set OCPE bit to enable auto reload register&#60;/p&#62;
&#60;p&#62;      bitSet(r.adv -&#38;gt; CR1,7);        //Buffer reload register&#60;br /&#62;
      bitSet(r.adv-&#38;gt;CR1,5);          //These two bits specify one of three centre aligned PWM options&#60;br /&#62;
      bitSet(r.adv-&#38;gt;CR1,6);          //&#60;br /&#62;
      bitSet(r.adv-&#38;gt;EGR,0);          //initialise all registers&#60;/p&#62;
&#60;p&#62;      bitSet(r.adv-&#38;gt;CCER,0);         //this should enable complimentary outputs&#60;br /&#62;
      bitSet(r.adv-&#38;gt;CCER,2);&#60;/p&#62;
&#60;p&#62;      bitSet(r.adv-&#38;gt;BDTR,11);        // OSSR bit&#60;br /&#62;
      bitSet(r.adv-&#38;gt;BDTR,15);        // MOE bit Cleared by software, probably dont need to set                &#60;/p&#62;
&#60;p&#62;      bitSet(r.adv-&#38;gt;CR1,0);          //clock back on                          &#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;void loop(){&#60;/p&#62;
&#60;p&#62;  pwmWrite(13, 15000);  //should complement on pin55&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;Some of the bit operations are probably redundant due to the pinMode(), p340 and 307 of the STM32F reference manual give alot of info on the required registers
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Advanced Timer Complementary Output Setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2000#post-11480</link>
			<pubDate>Sun, 01 Jul 2012 20:31:19 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">11480@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I haven't used the feature before, but believe you may need to manipulate the timer registers to get the complementary outputs out. For this information, I'd look at the Reference Manual for STM32F1 located here:&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;pinMode() is located in (IDE_Folder)&#38;gt;hardware&#38;gt;leaflabs&#38;gt;cores&#38;gt;maple&#38;gt;wirish_digital.cpp
&#60;/p&#62;</description>
		</item>
		<item>
			<title>emburl on "Advanced Timer Complementary Output Setup"</title>
			<link>http://forums.leaflabs.com/topic.php?id=2000#post-11478</link>
			<pubDate>Sun, 01 Jul 2012 19:59:35 +0000</pubDate>
			<dc:creator>emburl</dc:creator>
			<guid isPermaLink="false">11478@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi&#60;/p&#62;
&#60;p&#62;Im a relatively new user to the Maple ide (v0.0.12) using a Native board to implement switching control.&#60;/p&#62;
&#60;p&#62;Ive been looking at the advanced timer functions available on timer1 and 8, in particular the complementary outputs designed for PWM driving of bridge circuits. &#60;/p&#62;
&#60;p&#62;I started playing with the registers, setting bit values in my Setup() routine following the STM32 datasheet. &#60;/p&#62;
&#60;p&#62;While I have been able to have some effect on the output on pin 13 (for timer 8 channel 1), I have not been able to produce the output complement on pin 55 (where timer 8 channel1N is mapped to). &#60;/p&#62;
&#60;p&#62;(I have tried to disable the counter output of timer 3 channel 2 that shares the pin)&#60;/p&#62;
&#60;p&#62;a) Has anyone been able to access this feature?&#60;/p&#62;
&#60;p&#62;b) This could be very obvious but I cant find it, where can I see the source code for the pinMode() routines?&#60;/p&#62;
&#60;p&#62;If there is a better way to do this, Im all ears (Im sure there is)
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
