<?xml version="1.0" encoding="UTF-8"?><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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: LogoChip Port A, setbit/clearbit, and analog inputs</title>
	<atom:link href="http://www.neufeld.newton.ks.us/electronics/?feed=rss2&#038;p=127" rel="self" type="application/rss+xml" />
	<link>http://www.neufeld.newton.ks.us/electronics/?p=127</link>
	<description></description>
	<lastBuildDate>Sun, 08 Dec 2024 17:19:24 -0600</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Todd S.</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=127&#038;cpage=1#comment-20987</link>
		<dc:creator>Todd S.</dc:creator>
		<pubDate>Tue, 13 Nov 2007 21:42:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=127#comment-20987</guid>
		<description>Many THANKS for this exchange.  (PS: Will test your example, as actually seeing something really drives in the point.)

I also look forward to more articles on your site.  They are much appreciated.

Todd S.</description>
		<content:encoded><![CDATA[<p>Many THANKS for this exchange.  (PS: Will test your example, as actually seeing something really drives in the point.)</p>
<p>I also look forward to more articles on your site.  They are much appreciated.</p>
<p>Todd S.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Neufeld</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=127&#038;cpage=1#comment-20986</link>
		<dc:creator>Keith Neufeld</dc:creator>
		<pubDate>Tue, 13 Nov 2007 21:38:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=127#comment-20986</guid>
		<description>Yup, I assume they mention it because of the side effects.

I&#039;d have to think carefully to make sure this is right, but here&#039;s another possible side effect:

Set a port as all outputs and write values to the lines.  Now set bits 4-7 as inputs, clear bit 0, then set 4-7 as outputs again.

You&#039;d expect bits 4-7 to still have the same values they did the last time you set them as outputs.  In fact, they&#039;re going to have the values of their &lt;em&gt;inputs&lt;/em&gt; at the time you cleared bit 0, thanks to read-modify-write.

Hardware side effects can be tricky. :-)</description>
		<content:encoded><![CDATA[<p>Yup, I assume they mention it because of the side effects.</p>
<p>I&#8217;d have to think carefully to make sure this is right, but here&#8217;s another possible side effect:</p>
<p>Set a port as all outputs and write values to the lines.  Now set bits 4-7 as inputs, clear bit 0, then set 4-7 as outputs again.</p>
<p>You&#8217;d expect bits 4-7 to still have the same values they did the last time you set them as outputs.  In fact, they&#8217;re going to have the values of their <em>inputs</em> at the time you cleared bit 0, thanks to read-modify-write.</p>
<p>Hardware side effects can be tricky. <img src='http://www.neufeld.newton.ks.us/electronics/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd S.</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=127&#038;cpage=1#comment-20985</link>
		<dc:creator>Todd S.</dc:creator>
		<pubDate>Tue, 13 Nov 2007 21:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=127#comment-20985</guid>
		<description>I see.  I guess what confused me about Microchip stating this fact (i.e. that internally the write&#039;s are read-modify-write) is why it would be of use to the end-user -- did they feel they had to mention it because of side-effects that this operation could have?  Other than saying &quot;that&#039;s interesting&quot; when reading the datasheet, what am I supposed to do w/ this fact when I&#039;m programming the chip?

Thanks -

Todd S.</description>
		<content:encoded><![CDATA[<p>I see.  I guess what confused me about Microchip stating this fact (i.e. that internally the write&#8217;s are read-modify-write) is why it would be of use to the end-user &#8212; did they feel they had to mention it because of side-effects that this operation could have?  Other than saying &#8220;that&#8217;s interesting&#8221; when reading the datasheet, what am I supposed to do w/ this fact when I&#8217;m programming the chip?</p>
<p>Thanks -</p>
<p>Todd S.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Neufeld</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=127&#038;cpage=1#comment-20983</link>
		<dc:creator>Keith Neufeld</dc:creator>
		<pubDate>Tue, 13 Nov 2007 21:19:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=127#comment-20983</guid>
		<description>I feel so old-fashioned . . . I guess the term opcodes has gone out of vogue in favor of instruction set, or some such?

So now I&#039;m looking at the PIC18F2320 instruction set, and there &lt;em&gt;are&lt;/em&gt; instructions to manipulate single bits in registers.  But at a microcode level -- how that instruction is implemented in the chip&#039;s hardware -- I&#039;m quite certain it doesn&#039;t have access to address a single bit within a register.  Rather, it reads the whole register, ORs it with the bit to set or ANDs it with the inverse of the bit to clear, and writes it back.

Even though it may be atomic and happen in a single clock cycle, it&#039;s still easier to build the chip to manipulate bits via read-modify-write (which shares microcode circuitry with other operations) than to make microcode that can directly access a single bit without touching the rest of the byte.

Internally, the data bus is eight bits wide.  (Maybe it&#039;s sixteen, but whatever.)  Think about what it would mean for bus design if you could specify not only an address to access, but also a single bit for the bus to access, and the bus would only enable reads/writes to that individual line on the bus.  Much more complex than read-modify-write.</description>
		<content:encoded><![CDATA[<p>I feel so old-fashioned . . . I guess the term opcodes has gone out of vogue in favor of instruction set, or some such?</p>
<p>So now I&#8217;m looking at the PIC18F2320 instruction set, and there <em>are</em> instructions to manipulate single bits in registers.  But at a microcode level &#8212; how that instruction is implemented in the chip&#8217;s hardware &#8212; I&#8217;m quite certain it doesn&#8217;t have access to address a single bit within a register.  Rather, it reads the whole register, ORs it with the bit to set or ANDs it with the inverse of the bit to clear, and writes it back.</p>
<p>Even though it may be atomic and happen in a single clock cycle, it&#8217;s still easier to build the chip to manipulate bits via read-modify-write (which shares microcode circuitry with other operations) than to make microcode that can directly access a single bit without touching the rest of the byte.</p>
<p>Internally, the data bus is eight bits wide.  (Maybe it&#8217;s sixteen, but whatever.)  Think about what it would mean for bus design if you could specify not only an address to access, but also a single bit for the bus to access, and the bus would only enable reads/writes to that individual line on the bus.  Much more complex than read-modify-write.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd S.</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=127&#038;cpage=1#comment-20982</link>
		<dc:creator>Todd S.</dc:creator>
		<pubDate>Tue, 13 Nov 2007 21:03:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=127#comment-20982</guid>
		<description>Keith, thanks for the response.

As I understand it, &quot;read-modify-write&quot; is an atomic operation performed by the chip itself.  During this operation, the user code does not have an opportunity to intervene.  Am I correct?

As for the opcodes you mention, I am not clear what you are referring to.  (Are opcodes related to the LogoBoard?)

Todd S.</description>
		<content:encoded><![CDATA[<p>Keith, thanks for the response.</p>
<p>As I understand it, &#8220;read-modify-write&#8221; is an atomic operation performed by the chip itself.  During this operation, the user code does not have an opportunity to intervene.  Am I correct?</p>
<p>As for the opcodes you mention, I am not clear what you are referring to.  (Are opcodes related to the LogoBoard?)</p>
<p>Todd S.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keith Neufeld</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=127&#038;cpage=1#comment-20981</link>
		<dc:creator>Keith Neufeld</dc:creator>
		<pubDate>Tue, 13 Nov 2007 20:50:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=127#comment-20981</guid>
		<description>Hi, Todd!

If you&#039;re intending to write the whole (byte-wide) port register, I can&#039;t think of any reason it should read first.

If you&#039;re modifying a single bit, rather than creating a new opcode (or microcode) to twiddle one bit of a port register, it makes more sense to read in the register contents, manipulate them with traditional bitwise logic to set/clear the bit you want to change, and write them back out (all using common, existing opcodes).  I &lt;em&gt;think&lt;/em&gt; that&#039;s what they mean when they say read-modify-write.

Does that help any?</description>
		<content:encoded><![CDATA[<p>Hi, Todd!</p>
<p>If you&#8217;re intending to write the whole (byte-wide) port register, I can&#8217;t think of any reason it should read first.</p>
<p>If you&#8217;re modifying a single bit, rather than creating a new opcode (or microcode) to twiddle one bit of a port register, it makes more sense to read in the register contents, manipulate them with traditional bitwise logic to set/clear the bit you want to change, and write them back out (all using common, existing opcodes).  I <em>think</em> that&#8217;s what they mean when they say read-modify-write.</p>
<p>Does that help any?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd S.</title>
		<link>http://www.neufeld.newton.ks.us/electronics/?p=127&#038;cpage=1#comment-20980</link>
		<dc:creator>Todd S.</dc:creator>
		<pubDate>Tue, 13 Nov 2007 20:42:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.neufeld.newton.ks.us/electronics/?p=127#comment-20980</guid>
		<description>Hi Keith,

Thanks for publishing this information.  I have a simple question - a PIC datasheet from MicroChip mentions that &quot;All write operations are read-modify-write&quot; which is also what you point out on this page.  Why is this?  If I am outputting a &quot;1&quot; through a pin, why do I need to know what is currently on that pin?

Many thanks -

Todd S.
Sr Sw Eng (but a noob in Electronics)</description>
		<content:encoded><![CDATA[<p>Hi Keith,</p>
<p>Thanks for publishing this information.  I have a simple question &#8211; a PIC datasheet from MicroChip mentions that &#8220;All write operations are read-modify-write&#8221; which is also what you point out on this page.  Why is this?  If I am outputting a &#8220;1&#8243; through a pin, why do I need to know what is currently on that pin?</p>
<p>Many thanks -</p>
<p>Todd S.<br />
Sr Sw Eng (but a noob in Electronics)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
