<?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>driving a stepper motor</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/29049/driving-a-stepper-motor</link><description> 
Hi guys, 

 
I wrote a function that generates a set of constants to be used in
assigning a delay value for each pulse for driving a stepper motor.
My code just stop at the first iteration of the code, please have a
look below and tell me what you think</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: driving a stepper motor</title><link>https://community.arm.com/thread/116988?ContentTypeID=1</link><pubDate>Fri, 14 Sep 2012 18:01:43 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:85a69279-d06d-46a9-ac22-e02cfb6f8ba2</guid><dc:creator>Andre Marcus</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank you all for your reply; my issue is fixed; all I had to do
is change my data type to float, and a bit of adjustment of my
code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: driving a stepper motor</title><link>https://community.arm.com/thread/106374?ContentTypeID=1</link><pubDate>Thu, 13 Sep 2012 20:00:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6d76f136-089b-454f-aaff-a14735e33df0</guid><dc:creator>Andre Marcus</dc:creator><description>&lt;p&gt;&lt;p&gt;
Can some one says what exactly is causing my loop not run? What do
I need to change?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: driving a stepper motor</title><link>https://community.arm.com/thread/91705?ContentTypeID=1</link><pubDate>Thu, 13 Sep 2012 10:56:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7371f4c0-dd3d-404b-a07d-446b28f366d3</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
It&amp;#39;s nothing specifically to do with &lt;b&gt;embedded&lt;/b&gt; &amp;#39;C&amp;#39; - it is
the standard language operation in &lt;i&gt;&lt;b&gt;any&lt;/b&gt;&lt;/i&gt; context.&lt;/p&gt;

&lt;p&gt;
For some &amp;#39;C&amp;#39; learning &amp;amp; reference materials, see: &lt;a href="http://blog.antronics.co.uk/2010/12/12/"&gt;blog.antronics.co.uk/.../&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: driving a stepper motor</title><link>https://community.arm.com/thread/61139?ContentTypeID=1</link><pubDate>Thu, 13 Sep 2012 10:47:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:00f8e5c6-04a8-4d71-ba00-a29064b33a82</guid><dc:creator>Andre Marcus</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank you all for your reply. How to avoid truncation of my
numeric results, what data type I should be using. I&amp;#39;m new to write
code in embedded C, hope you guys won&amp;#39;t mind my question; does
anybody have a sample code that deals with math operations(
multiplication and division).&lt;br /&gt;
Thank you so much!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: driving a stepper motor</title><link>https://community.arm.com/thread/61137?ContentTypeID=1</link><pubDate>Wed, 12 Sep 2012 23:56:46 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7931014c-cfc7-48a8-b5d9-60ab0fee5a1c</guid><dc:creator>Martin Unger</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Andre,&lt;/p&gt;

&lt;p&gt;
better formatting will help to spot problems (and posting it in
this format, of cause).&lt;/p&gt;

&lt;pre&gt;
void stepper_loop()
{
  unsigned long constants_array[1772];
  unsigned long Cn_vals;
  unsigned int j;

  unsigned long *Px; // decalre the pointer first
  Px= constants_array; //make the pointer points to the address of first element in the array

  for(j=0; j&amp;lt;1772; j++)
  {

    Cn_vals=calc();

    constants_array[j]=Cn_vals;
    Px++; // increment the pointer to point to the next element in the array
  }
}
&lt;/pre&gt;

&lt;p&gt;
On the first glance I see that:&lt;br /&gt;
1) &amp;quot;long constants_array&amp;quot; is a local variable and placed on the
stack, which typically is very limited in the embedded world. Make it
static, for example.&lt;br /&gt;
2)It is only written as well as Px, so optimizer may remove some of
the code, which makes debugging difficult.&lt;/p&gt;

&lt;p&gt;
Hope that helps&lt;br /&gt;
Martin&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: driving a stepper motor</title><link>https://community.arm.com/thread/61135?ContentTypeID=1</link><pubDate>Wed, 12 Sep 2012 23:54:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1ed772af-9aa6-4c93-8248-34dd04a5c4ca</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
You should wrap your code in the &amp;#39;pre&amp;#39; tag.&lt;br /&gt;
But before you do that, please make sure that your code uses
consistent indentation, placement of braces and so on. This code
makes my eyes sore.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: driving a stepper motor</title><link>https://community.arm.com/thread/61136?ContentTypeID=1</link><pubDate>Wed, 12 Sep 2012 23:54:02 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8e1b905e-d566-4b22-b40d-839a28c97880</guid><dc:creator>Alexan Eramian</dc:creator><description>&lt;p&gt;&lt;p&gt;
Are you sure about the variable types you are using?&lt;/p&gt;

&lt;pre&gt;
value_sqrd=2*Alpha/angular_accel;
&lt;/pre&gt;

&lt;p&gt;
results to 0.000451611847161 which is truncated to 0 since the
result is stored in an unsigned long.&lt;/p&gt;

&lt;p&gt;
The line following this is useless , it calculates the square root
of 0&lt;/p&gt;

&lt;pre&gt;
C0_constant=sqrt(value_sqrd/period);
&lt;/pre&gt;

&lt;p&gt;
Alex&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>