<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I.D.E.A. &#187; PIC</title>
	<atom:link href="http://www.2-bit-toys.com/category/physical-computing/pic/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.2-bit-toys.com</link>
	<description>Inspirations, Dreams, Explorations, Addictions</description>
	<lastBuildDate>Sun, 15 Jan 2012 06:59:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PIC Timer Interrupts</title>
		<link>http://www.2-bit-toys.com/2005/10/14/pic-timer-interrupts/</link>
		<comments>http://www.2-bit-toys.com/2005/10/14/pic-timer-interrupts/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 19:00:42 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[PIC]]></category>

		<guid isPermaLink="false">http://2-bit-toys.com/wordpress/?p=17</guid>
		<description><![CDATA[Here&#8217;s a very basic program to use TMR0 and an interrupt for TMR0 to do something every second. I&#8217;m using a 4Mhz clock. We are setting up the PIC so that everytime TMR0 reaches it&#8217;s max value(this is configurable), a Timer Interrupt occurs. ---------------------------------------------------------------------------------------- 'Works w/ 18Fxx2 - James Tu 06/01/2004 'This program sets up [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a very basic program to use TMR0 and an interrupt for TMR0 to do something every second.<br />
I&#8217;m using a 4Mhz clock.</p>
<p>We are setting up the PIC so that everytime TMR0 reaches it&#8217;s max value(this is configurable), a Timer Interrupt occurs.</p>
<pre>
----------------------------------------------------------------------------------------

'Works w/ 18Fxx2 - James Tu 06/01/2004

'This program sets up a TMR0 interrupt
'The interrupt happens every 1 sec!
'I timed it...it's pretty precise

'It changes the state of an LED every second.

led var PORTB.4
ledstate VAR BIT

ledstate = 1

INTCON2.7 = 0 'Enable PORTB pullups...18Fxx2

'setup TIMER0
'set the high and low bytes of TMR0...
'we'll be using it in 16-bit mode
'This is equal to 65535 - 62500 = 3035...
'Calculated to give us 1 sec interrupts with 1:16 prescalar
TMR0H = $0B
TMR0L = $DB

'Enables TMR0, set to 16-bit
'Enable Pre-scalar
'Set prescalar value 1:16
T0CON = %10000011

On Interrupt Goto myint ' Define interrupt handler
'Enable Timer0 Interrupt
'Turn on INTCON.7(GIE) and INTCON.5 (TMR0IE)
INTCON = %10100000

TRISB.4 = 0

loop:

led = ledstate

Goto loop ' Do it forever

' Interrupt Service Routine
Disable ' No interrupts past this point
myint:
if ledstate == 1 THEN
ledstate = 0
ELSE
ledstate = 1
ENDIF
INTCON.2 = 0 ' Clear TMR0 interrupt flag
TMR0H = $0B ' put 3035 in TMR0 for 1 sec interrupts
TMR0L = $DB
Resume ' Return to main program
Enable

----------------------------------------------------------------------------------------
</pre>
<p>Instead of changing the state of the LED, you can increment a variable&#8230;If have you have a variable called<br />
SECONDS, you can add 1 to SECONDS when this timer interrupt occurs. This will allow you to keep time&#8230;for time event driven processing.</p>
<p>TMR0 can hold a 16-bit value or an 8-bit value<br />
TMR0 has a pre-scalar that can be set to either 2,4,8,16,32,64,128, or 256.<br />
(What the pre-scalar do is that it slows down the counting of TMR0. If the pre-scalar is set to 32, TMR0 increments by 1 every 32 PIC clock &#8220;ticks&#8221;)</p>
<p>Here&#8217;s the math&#8230;</p>
<ul>
<li>4Mhz crystal means an internal clock of 1Mhz</li>
<li>1Mhz means there&#8217;s an internal clock &#8220;tick&#8221; every .000001 sec.</li>
<li>TMR0 can hold either a 16-bit(65536) or an 8-bit(256) value&#8230;I chose 16 (therefore TMR0 can count from 0 to 65535)</li>
<li>If we just left it like this, TMR0 counts from 0 to 65535 and the TMR0 Interrupt will happen every 0.065536 sec (65536 * 0.000001) .</li>
<li>We want TMR0 to interrupt every 1 sec.</li>
<li>If we set the pre-scalar to 16, TMR0 will interrupt every&#8230;0.065536 * 16 = 1.048576 sec&#8230;pretty close to 1 sec.
<ul>
<li>If you want you can leave it at this. If you want really precise timing, you have to do the following&#8230;you have to fill TMR0 with a starting value.(TMR0 is just a register so you can set it to any value.)</li>
<li>We want the solution to the equation:
<ul>
<li>value * 0.000001 * pre-scalar = 1.0 sec</li>
<li> value = 1.0/(0.000001 * 16) = <strong>62500</strong></li>
</ul>
</li>
<li>So we want TMR0 to count 62500 not 65536. What we can do is to set TMR0 to 65535-62500 = 3035. So it actually counts from 3035 to 65535 which is <strong>62500</strong>! We do this at the beginning of the program and every time an interrupt happens.</li>
<li>TMR0 is a 16-bit register in my example, so we have to write two bytes&#8230;one is written to TMR0H (high byte) and TMR0L (low byte).</li>
</ul>
</li>
</ul>
<p>That&#8217;s it!</p>
<p>The table below shows the interrupt intervals you can expect from a 4Mhz clock, and a 16-bit TMR0.</p>
<table border=1 cellpadding=0 cellspacing=0>
<tr>
<td>prescalar</td>
<td>2</td>
<td>4</td>
<td>8</td>
<td>16</td>
<td>32</td>
<td>64</td>
<td>128</td>
<td>256</td>
</tr>
<tr>
<td>TMR0 INT happens every (sec)
</td>
<td>0.131</td>
<td>0.262</td>
<td>0.524</td>
<td><b>1.05</b></td>
<td>2.09</td>
<td>4.19</td>
<td>8.38</td>
<td>16.77</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.2-bit-toys.com/2005/10/14/pic-timer-interrupts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Open-collector&#8221;, &#8220;Open-drain&#8221; demystified</title>
		<link>http://www.2-bit-toys.com/2005/10/14/open-collector-open-drain-demystified/</link>
		<comments>http://www.2-bit-toys.com/2005/10/14/open-collector-open-drain-demystified/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 18:35:54 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[ICs & Controller Boards]]></category>
		<category><![CDATA[PIC]]></category>

		<guid isPermaLink="false">http://2-bit-toys.com/wordpress/?p=16</guid>
		<description><![CDATA[You&#8217;ll come across the terms &#8220;open-collector&#8221; and &#8220;open-drain.&#8221; These are used sometimes to describe how a particular IC&#8217;s pins are implemented internally. This and also this are good explanations of what those terms actually mean and why an IC&#8217;s pin would be designed as open-collector or open-drain.]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ll come across the terms &#8220;open-collector&#8221; and &#8220;open-drain.&#8221; These are used sometimes to describe how a particular IC&#8217;s pins are implemented internally. </p>
<p><a href="http://www.acroname.com/robotics/info/concepts/opn_clct.html">This</a> and <a href="http://zone.ni.com/devzone/conceptd.nsf/webmain/9739E26BBE06286586256C3A007A7839?opendocument">also this</a> are good explanations of what those terms actually mean and why an IC&#8217;s pin would be designed as open-collector or open-drain.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.2-bit-toys.com/2005/10/14/open-collector-open-drain-demystified/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PIC IR remote</title>
		<link>http://www.2-bit-toys.com/2005/10/14/pic-ir-remote/</link>
		<comments>http://www.2-bit-toys.com/2005/10/14/pic-ir-remote/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 18:26:01 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[Communication]]></category>
		<category><![CDATA[Physical Computing]]></category>
		<category><![CDATA[PIC]]></category>

		<guid isPermaLink="false">http://2-bit-toys.com/wordpress/?p=14</guid>
		<description><![CDATA[Here&#8217;s the info on how to control a SONY TV. (caveat you may need to do some debugging.) You need a 555 timer to generate the 40 Khz for you. Your pic just turns on or off the 555 to transmit the appropriate data. Circuit link. SIRC codes explained. SIRC code data format My PICBasicPro [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the info on how to control a SONY TV. (caveat you may need to do some debugging.)</p>
<p>You need a 555 timer to generate the 40 Khz for you.<br />
Your pic just turns on or off the 555 to transmit the appropriate data.</p>
<p>Circuit <a href="http://jap.hu/electronic/irtx_pic1.gif">link</a>.</p>
<p><a href="http://www.geocities.com/sila1999/sircs.htm">SIRC codes</a> explained.</p>
<p>SIRC code <a href="http://www.geocities.com/sila1999/S3.jpg">data format</a></p>
<p>My PICBasicPro <a href="http://www.2-bit-toys.com/pic/sony_code.bas">code</a> to implement this protocol.</p>
<p>Update:</p>
<p>Found a simpler solution. Use this <a href="http://www.rentron.com/remote_control/TX-IR.htm">IC from rentron</a>. It will generate either a 40 or 38KHz carrier frequency for you. Use the PIC program above and connect the PIC pin to DATA IN of this IC. You need a 4Mhz clock, some pullup/down resistors, and the circuit to drive your IR LED&#8230;that&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.2-bit-toys.com/2005/10/14/pic-ir-remote/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

