<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: 908QY4 output compare in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/908QY4-output-compare/m-p/126173#M967</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Think I found it...&lt;/P&gt;&lt;P&gt;Has to do with the setting of the mode select 0 A (MS0A) bit in TSC0. In the datasheet, if ELS0B:A == 00, &amp;nbsp;it's described as "pin under port control; initial output level high" if MS0A is '0' and "pin under port control; initial output level low" if MS0A is high. I was initializing this register to 0x00 and so, I presume, when I turned on the OC by writing 0x5C to the TSC0 register, it attained a "high"&amp;nbsp;initial level.&lt;/P&gt;&lt;P&gt;Ensuring that MS0A is '1' seems to have fixed my problem.&lt;/P&gt;&lt;P&gt;&lt;FONT face="Helvetica" size="1"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Aug 2006 20:30:37 GMT</pubDate>
    <dc:creator>BlkStang</dc:creator>
    <dc:date>2006-08-10T20:30:37Z</dc:date>
    <item>
      <title>908QY4 output compare</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/908QY4-output-compare/m-p/126172#M966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Tearing my hair out here trying to figure out what my little 908QY4 is doing with respect to an output compare on TCH0.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Basically, I want to set up an OC to occur at some point from "now" (i.e. 20uS from now...) to initiate a cascade of OCs to transmit a simple serial stream. The pin idles low and the first OC to get the ball rolling will set it high. Here's a code snippet:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/PRE&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //finish up bit stream configuration...&amp;nbsp;&amp;nbsp;&amp;nbsp; g_PID1Message |= ((unsigned int)(FW_REVISION &amp;amp; 0x07));&amp;nbsp;&amp;nbsp;&amp;nbsp; g_TCH0BitMask = 0x8000;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //send 16 bits MSB first&amp;nbsp;&amp;nbsp;&amp;nbsp; g_TCH0NextDelay = KTCH0MSG_FRMNOM;&amp;nbsp; //so ISR knows how long to hold this state&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DisableInterrupts;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //disable system interrupts&amp;nbsp;&amp;nbsp;&amp;nbsp; //configure TSC0 for output compare, rising edge to occur with interrupt.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 7 0 CH0F&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 6 1 CH0IE --enable interrupts&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 5 0 MS0B&amp;nbsp; --B:A == 01 means output compare&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 4 1 MS0A&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 3 1 ELS0B --B:A == 11 means set pin next compare&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 2 1 ELS0A&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 1 0 TV0&amp;nbsp;&amp;nbsp;&amp;nbsp; //bit 0 0 CH0MAX&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TCH0 = TCNT + KTCH0INITDLY;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //compute time of message start&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TSC0_CH0F = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //clear any pending OC interrupt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TSC0 = 0x5C;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //enable the OC interrupt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EnableInterrupts;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //re-enable system interrupts&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //ISR will handle remaining bit transmission and will shut itself off when done.}//ProcessOutgoingDSPMessagePID0&lt;/PRE&gt;&lt;PRE&gt;.&lt;/PRE&gt;&lt;PRE&gt;.&lt;/PRE&gt;&lt;PRE&gt;.&lt;/PRE&gt;&lt;DIV&gt;&lt;BR /&gt;KTCH0INITDLY is a constant equal to 64 ticks of the 312.5nS system clock which, should in theory, set the TCH0 output compare to match up at the current time (TCNT) plus 20uS.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The constant KTCH0MSG_FRMNOM is equal to 300uS worth of clock ticks (i.e. I want the first pulse to be 300uS long and the variable g_TCH0NextDelay is used in the ISR to set when the next OC (clearing the pin) will occur.)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The problem I'm encountering is that as soon as the "TSC0 = 0x5C" is executed, the pin transitions high &lt;STRONG&gt;&lt;EM&gt;immediately&lt;/EM&gt;&lt;/STRONG&gt; and stays high for 320uS (i.e. 20uS delay is added to the&amp;nbsp;desired 300uS pulse width...) It doesn't appear to wait for TCNT to equal TCH0...it just immediately OCs. From that point on, my serial stream is dead nuts on and the ISR-driven OCing operates exactly as expected...until the next message is to go out, then it repeats this again.&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;What am I missing that's causing the first OC to occur too early like this?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Aug 2006 03:10:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/908QY4-output-compare/m-p/126172#M966</guid>
      <dc:creator>BlkStang</dc:creator>
      <dc:date>2006-08-10T03:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: 908QY4 output compare</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/908QY4-output-compare/m-p/126173#M967</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Think I found it...&lt;/P&gt;&lt;P&gt;Has to do with the setting of the mode select 0 A (MS0A) bit in TSC0. In the datasheet, if ELS0B:A == 00, &amp;nbsp;it's described as "pin under port control; initial output level high" if MS0A is '0' and "pin under port control; initial output level low" if MS0A is high. I was initializing this register to 0x00 and so, I presume, when I turned on the OC by writing 0x5C to the TSC0 register, it attained a "high"&amp;nbsp;initial level.&lt;/P&gt;&lt;P&gt;Ensuring that MS0A is '1' seems to have fixed my problem.&lt;/P&gt;&lt;P&gt;&lt;FONT face="Helvetica" size="1"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Aug 2006 20:30:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/908QY4-output-compare/m-p/126173#M967</guid>
      <dc:creator>BlkStang</dc:creator>
      <dc:date>2006-08-10T20:30:37Z</dc:date>
    </item>
  </channel>
</rss>

