<?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>Best way to control a servo?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/15282/best-way-to-control-a-servo</link><description> Hi, 
 
This might be a little OT but I&amp;#39;ve been exploring a few new ways of controling a servo. 
 
I&amp;#39;m using a 8051 board of my own design, a Hitec HS300BB servo and the control line of the servo is connected to a digital out line. 
 
Up untill now I</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Best way to control a servo?</title><link>https://community.arm.com/thread/95281?ContentTypeID=1</link><pubDate>Sun, 22 Dec 2002 15:30:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ad137363-ae98-48aa-b213-222e02a64558</guid><dc:creator>Richard Collett</dc:creator><description>&lt;p&gt;Borrow a Digital Storage Oscilloscope (DSO), then you can check exactly what sort of pulse your chip is outputting.&lt;br /&gt;
This avoids the awkward &amp;quot;two unknowns&amp;quot; problem. (&amp;quot;Is it my software, or is it the hardware?&amp;quot;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best way to control a servo?</title><link>https://community.arm.com/thread/54892?ContentTypeID=1</link><pubDate>Sun, 22 Dec 2002 05:34:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cd730975-3f59-4a15-8806-a89e6cd36d90</guid><dc:creator>Mike Akkerman</dc:creator><description>&lt;p&gt;Here&amp;#39;s what I figured out using a Timer 2 example I found on the Keil site:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;void init_timer2 (void) {
	/*--------------------------------------
	Set the reload values to be 20000 clocks.
	--------------------------------------*/
	CRCL = (65535UL-0000UL);
	CRCH = (65535UL-20000UL) &amp;gt;&amp;gt; 8;

	CCEN = 0x08;

	CCL1 = (65535UL-1700UL);
	CCH1 = (65535UL-1700UL) &amp;gt;&amp;gt; 8;

	TL2 = CRCL;
	TH2 = CRCH;

	/*--------------------------------------
	Set Timer2 for 16-bit auto-reload.
	The timer counts to 0xFFFF, overflows,
	is reloaded, and generates an interrupt.
	--------------------------------------*/
	T2CON = 0x11;                /* 0XX10001 */


	/*--------------------------------------
	--------------------------------------*/
	ET2 = 1;                      /* Enable Timer 2 Interrupts */
	EAL = 1;                      /* Global Interrupt Enable */

	P5 = 0x18;
}

void timer1_ISR (void) interrupt 5 {
	TF2 = 0;
}&lt;/pre&gt;
&lt;br /&gt;
I&amp;#39;ve set it to reload every 20000 systemticks (1MHz / 20Khz = 50Hz) which should generate a interupt every 20 ms.&lt;br /&gt;
&lt;br /&gt;
So far everything okay... But I have to generate a pulse of 1.7 ms to center the servo, 8.5 ms to go absolute left and 2.5 ms to go absolute right.&lt;br /&gt;
&lt;br /&gt;
Am I doing something wrong or is this a defective servo?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Best way to control a servo?</title><link>https://community.arm.com/thread/39530?ContentTypeID=1</link><pubDate>Tue, 17 Dec 2002 18:25:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:51db3554-4310-4357-89c6-5b327ea70ab0</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;&lt;br /&gt;
A more general solution you might like would be to program one of the timers to correspond to your &amp;quot;wait&amp;quot; interval, and toggle the output bit when the interrupt occurs.  Keil&amp;#39;s app note #105 talks about a general timer tick interrupt.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.keil.com/appnotes/files/apnt_105.pdf"&gt;http://www.keil.com/appnotes/files/apnt_105.pdf&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
If the delays you need are really short (a few instruction cycle times), then you might need a instruction-loop delay.  See, for example, the recent thread:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.keil.com/forum/docs/thread2150.asp"&gt;http://www.keil.com/forum/docs/thread2150.asp&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Your particular part might include some PWM hardware to make your life even easier by driving an output pin for you according to some timer parameters.&lt;br /&gt;
&lt;br /&gt;
If you&amp;#39;re relying on timing with an instruction loop to be precise, then you might want to keep interrupts masked during the loop, so that you don&amp;#39;t lose any extra time to the interrupt handler.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>