<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Pulse width + counting</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/16721/pulse-width-counting</link><description> While trying to understand some device connection protocol I&amp;#39;v faced a problem: at first simply I need to continosle monitor what happens on CLK pin of device. In sample: 
 
ET0 = 1; 
EA = 1; 
 
TMOD = (TMOD &amp;amp; 0xF0) | 0x09; 
 
while (1) 
 { 
 T0_ISR_count</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Pulse width + counting</title><link>https://community.arm.com/thread/72467?ContentTypeID=1</link><pubDate>Wed, 05 May 2004 02:23:03 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:91b8a0ae-7865-4a69-a13f-6376d9cfe12e</guid><dc:creator>Aleksandras Sharpilo</dc:creator><description>&lt;p&gt;Thanks Andrew...&lt;br /&gt;
I&amp;#39;m using:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;void serinit(void)&lt;br /&gt;
{&lt;br /&gt;
	TMOD=0x20;&lt;br /&gt;
	TH1=0xFD;&lt;br /&gt;
	SCON=0x50;&lt;br /&gt;
	TR1=1;&lt;br /&gt;
}&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Any ideas ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulse width + counting</title><link>https://community.arm.com/thread/72466?ContentTypeID=1</link><pubDate>Wed, 05 May 2004 02:20:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8f497fa4-0e27-4582-b823-3a469dbabd6a</guid><dc:creator>Aleksandras Sharpilo</dc:creator><description>&lt;p&gt;Thanks Jon!&lt;br /&gt;
&lt;br /&gt;
It helped a little bit, but... those huge numbers I&amp;#39;v got... After all I made some modifications:&lt;br /&gt;
1. Entered a keypress wait before start of calculation&lt;br /&gt;
2. Changed to printf (TH0,TL0,T0_ISR_count)&lt;br /&gt;
&lt;br /&gt;
After all of this I got TH0 = 253 (not always stable, but it it seems to be true), TL0, T0_ISR_count = 0...&lt;br /&gt;
&lt;br /&gt;
Any ideas why TH0 counts first ?&lt;br /&gt;
&lt;br /&gt;
If i try to remove a keypress wait, i lost any stability and TH0 values begins to jump in vary wide range. Why I lost stability if I do the same thing, but continiously without waiting for kaypress or something?&lt;br /&gt;
&lt;br /&gt;
Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulse width + counting</title><link>https://community.arm.com/thread/42151?ContentTypeID=1</link><pubDate>Tue, 04 May 2004 15:16:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4cbb1900-bbc4-41b6-9976-d445e282450e</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;Maybe printf function takes a lot of time to output calculated data&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Think about what baud rate are you using, and do the sums from there!&lt;br /&gt;
&lt;br /&gt;
Are you using polled or interrupt-driven serial output?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pulse width + counting</title><link>https://community.arm.com/thread/42150?ContentTypeID=1</link><pubDate>Tue, 04 May 2004 08:38:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5238c02c-cbbb-42e3-908a-04cc0f661e20</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;I&amp;#39;d probably change the code to something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
while (1)
  {
  T0_ISR_count = 0;
  TH0 = 0;
  TL0 = 0;

  while (INT0);    // wait for falling edge
  TR0 = 1;         // Start Timer
  while (!INT0);   // wait for rising edge
  while (INT0);    // wait for falling edge
  TR0 = 0;         // Stop Timer

  printf (&amp;quot;The period is: %ld uSec\n&amp;quot;,
          (unsigned long)((TH0 &amp;lt;&amp;lt; 8) | TL0 |
          ((unsigned long)T0_ISR_count &amp;lt;&amp;lt; 16)));
  }&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>