<?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: Generating a 9MHz signal</title>
		<link>http://forums.leaflabs.com/topic.php?id=1222</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:24:06 +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=1222" rel="self" type="application/rss+xml" />

		<item>
			<title>matsalleh on "Generating a 9MHz signal"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1222#post-7454</link>
			<pubDate>Tue, 27 Dec 2011 19:21:12 +0000</pubDate>
			<dc:creator>matsalleh</dc:creator>
			<guid isPermaLink="false">7454@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;Sorry for the late reply.&#60;/p&#62;
&#60;p&#62;I've not actually looked at the datasheet yet, but it sounds as though I'll have enough timers.&#60;/p&#62;
&#60;p&#62;I read the maple guide on timers, and it's terribly written. I don't understand it at all.&#60;/p&#62;
&#60;p&#62;Can you give me some example code?&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;Chris.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Generating a 9MHz signal"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1222#post-7417</link>
			<pubDate>Wed, 21 Dec 2011 22:17:57 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7417@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;Yes, when I talk about 'the pulse', I'm talking about a 50% duty 9MHz signal.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Okay - too fast for interrupts. Better to use hardware timers, or poll in a very carefully written, carefully tested, very tight loop.&#60;/p&#62;
&#60;p&#62;You could probably use digitalWrite for the sync signals, but there is quite a lot of latency (i.e. it is slow), though IIRC, the latency is consistent (deterministic). You might want to get an idea how slow by timing:&#60;br /&#62;
'for (int i=0; i&#38;lt;1000000;i++) { digitalWrite(...); }`&#60;/p&#62;
&#60;p&#62;I can't imagine why I would do that unless I'd run out of timers.&#60;br /&#62;
A downside of doing pulses with digitalWrite is the program will suffer interrupts, but it (really the LCD) might not be very tolerant to interrupts. This can be hard to debug.&#60;/p&#62;
&#60;p&#62;Sensitivity to interrupts can be a bit of a pain in the nether-regions. For example to use USB for debug messages, their are likely to be interrupts, which might *cause* new bugs. So a technique you might use to debug your code, might trigger new bugs which are not there when you aren't debugging it (a kind of Heisenberg uncertainty principle w.r.t. bugs :-)&#60;/p&#62;
&#60;p&#62;I think I'd use timers as much as I could.&#60;br /&#62;
If timers were in short supply (because they are being used for other things), I'd either get a RET6 (and get more timers:-) or use a timer for the faster sync, or reprogram a timer on the fly and use it for either sync.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Could using an external clock work?&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;What kind of external clock? What jobs is it doing? Is it just standing in for a lack of free timers on the MCU, or is it doing something more?&#60;br /&#62;
If there is a ready-made chip that drives the LCD, that would be good.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>matsalleh on "Generating a 9MHz signal"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1222#post-7414</link>
			<pubDate>Wed, 21 Dec 2011 05:18:04 +0000</pubDate>
			<dc:creator>matsalleh</dc:creator>
			<guid isPermaLink="false">7414@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Okay, thanks for all your information, I'll dig through libmaple and the manual tonight.&#60;/p&#62;
&#60;p&#62;What I need to count, is the rising edge of the pulse. Eg, after 10, I digitalWrite(VSYNC, HIGH); to reset the scan position, or after 41, I digitalWrite(HSYNC, HIGH); to write the line...&#60;/p&#62;
&#60;p&#62;Yes, when I talk about 'the pulse', I'm talking about a 50% duty 9MHz signal.&#60;/p&#62;
&#60;p&#62;Ideally, I'd like to be able to call a function that produces the correct amount of pulses:&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
void (unsigned int i){&#60;br /&#62;
   for(; i &#38;gt;= 0; --i)&#60;br /&#62;
      pulse;&#60;br /&#62;
}&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;But I expect that would take far too many clock cycles to start/return the function, like you said...&#60;/p&#62;
&#60;p&#62;Could using an external clock work?&#60;/p&#62;
&#60;p&#62;I think that VSYNC and HSYNC are low enough frequency that I can use digitalWrite(); Providing I can interrupt the clock to do the write...&#60;/p&#62;
&#60;p&#62;What's your next suggestion?&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;Chris.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Generating a 9MHz signal"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1222#post-7407</link>
			<pubDate>Tue, 20 Dec 2011 14:34:47 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7407@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Chris - Okay, so you have experience of how to program microcontrollers. I think that is enough to make this work.&#60;br /&#62;
You will likely need to read the RM0008 manual to understand and use all the features of the timers you need.&#60;br /&#62;
You might want to start by reading the libmaple code for the timers. Quite a lot of ideas are demonstrated in that code, and you can use some of it without change (e.g. setting pinMode, prescaler and reload values).&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Would I be able to actually count individual pulses though?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;What needs to be counted, and what is it you need to measure?&#60;br /&#62;
Every timer can operate in several modes.&#60;br /&#62;
An external signal can be used to drive the timers counter, so that can count pulses.&#60;br /&#62;
Or, an external signal can be used to trigger a copying of the timers counter, so that can time an external pulse.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;For example I need to pulse the LCD 10 times with vSync low to reset the scan position. However to write a line I need to pulse the LCD 41 times with hSync high.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I'm not sure what rate is being used for the pulse, is it the 9MHz?&#60;/p&#62;
&#60;p&#62;A common way to generate a fixed number of pulses is to use a short interrupt service routine which gets called every pulse. It counts down the number of pulses, subtracting one each time, until it reaches zero, when it triggers the code to carry out the final action. In this case, that might be nothing at all; let the main loop() code wait on the pulse count to reach zero, then it goes ahead and does whatever is necessary. The nice thing about this approach is it is very simple. The bad thing is it is too slow if you want to count 9MHz pulses. It is good enough for something around a Mhz or slower (it takes about 24 cycles to enter and return from an interrupt routine).&#60;/p&#62;
&#60;p&#62;Timers can be 'chained' so the output of one timer (say generating a 9Mhz square wave) can be fed directly (inside the chip) into another timer to drive the 'slave' timer's counter.&#60;br /&#62;
Have a look at RM0008 section 15.3.15 &#34;Timer synchronization&#34;&#60;/p&#62;
&#60;p&#62;So the second 'chained' timer would count at 9MHz, and a channel's compare value would be the number of pulses to count, in your example 10 or 41. I haven't thought enough about this, but the timers can operate in 'one shot' modes as well as 'continuous' modes, so you might be able to use the channel's output pin to drive the LCD signal directly.&#60;/p&#62;
&#60;p&#62;I would be tempted to set up two extra timers, one to generate the Vsync, and the other the Hsync.&#60;/p&#62;
&#60;p&#62;(Full disclosure: I am not a member of LeafLabs staff.)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>matsalleh on "Generating a 9MHz signal"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1222#post-7406</link>
			<pubDate>Tue, 20 Dec 2011 10:48:01 +0000</pubDate>
			<dc:creator>matsalleh</dc:creator>
			<guid isPermaLink="false">7406@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;That's great, thanks!&#60;/p&#62;
&#60;p&#62;Would I be able to actually count individual pulses though?&#60;/p&#62;
&#60;p&#62;For example I need to pulse the LCD 10 times with vSync low to reset the scan position. However to write a line I need to pulse the LCD 41 times with hSync high.&#60;/p&#62;
&#60;p&#62;Is this feasible?&#60;/p&#62;
&#60;p&#62;I've done a fair bit of programming in C with arduino, and some stuff with uART on PICs, but that's about it.&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;Chris.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Generating a 9MHz signal"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1222#post-7400</link>
			<pubDate>Mon, 19 Dec 2011 14:16:46 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">7400@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;matsalleh - It might help to explain your familiarity with microcontroller programming.&#60;/p&#62;
&#60;p&#62;The STM32F103 microcontrollers are described in detail in the manual RM0008:&#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;The Maple has 4 timers. Any one of them could generate the 9MHz signal you want.&#60;br /&#62;
They are autonomous hardware, so once setup, they will continue to generate the signal without any further software intervention.&#60;br /&#62;
The approach is to set the timer to count at a base frequency of 9MHz, which is 72MHz/9MHz = a count of 8&#60;br /&#62;
then set a timer 'channel' to drive a pin with a square wave, which will have a 9MHz frequency when the channel 'compares' a value of half the count.&#60;/p&#62;
&#60;p&#62;Each timer has three or four pins which can output a signal.&#60;br /&#62;
This tells you which pins are connected to which timers:&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/docs/hardware/maple.html#timer-pin-map&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple.html#timer-pin-map&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;This is the reference for the HardwareTimer:&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/docs/lang/api/hardwaretimer.html#lang-hardwaretimer&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/lang/api/hardwaretimer.html#lang-hardwaretimer&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Assuming you know quite a lot about MCU programming:&#60;br /&#62;
set the prescaler to 1 so that it counts at 72MHz,&#60;br /&#62;
the overflow value to 8 so that it starts again after 8 72Mhz counts, and&#60;br /&#62;
the channel corresponding to the output pin to a compare value of 4, so it triggers half way through the cycle.&#60;/p&#62;
&#60;p&#62;Set the mode of the channel to TIMER_OUTPUT_COMPARE.&#60;br /&#62;
You could set the timer mode TIMER_PWM, but the overflow count and compare values need to be halved as the effective frequency is halved.&#60;/p&#62;
&#60;p&#62;Feed the pin corresponding to the timer channel to the thing that needs 9MHz.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>matsalleh on "Generating a 9MHz signal"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1222#post-7387</link>
			<pubDate>Sat, 17 Dec 2011 20:41:48 +0000</pubDate>
			<dc:creator>matsalleh</dc:creator>
			<guid isPermaLink="false">7387@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;I'd like to develop a driver for this LCD: &#60;a href=&#34;http://www.sparkfun.com/datasheets/LCD/LCD-08335-1.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.sparkfun.com/datasheets/LCD/LCD-08335-1.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;One of the logic requirements is a 9MHz clock.&#60;/p&#62;
&#60;p&#62;The period of this less than 1 microsecond, so I can't use:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
digitalWrite();&#60;br /&#62;
delay;&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;How can I produce a 9MHz clock (without using assembly language)?&#60;/p&#62;
&#60;p&#62;If I can't produce a clock signal, is there a way I can use an external clock and count the pulses?&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;Chris.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
