Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>It's like t is never getting assigned...</p> </blockquote> <p>There is no reason for the compiler to assign a value of 0 to t in the declaration</p> <pre><code>float t = 0; </code></pre> <p>since it immediately gets assigned to MotorSteps on the next line. My guess is the optimizer is ignoring the assignment to zero in the declaration and the debugger is simply displaying the uninitialized value for the memory where t is located on the stack.</p> <p>You might want to consider getting rid of the formula altogether and using a look up table for the ramp values. It looks like there are only 51 values so the table would be relatively small. The code to look up a value would be <em>much</em> quicker than using the floating point libraries on an 8051.</p> <pre><code>#define NUM_RAMP_STEPS 51 unsigned char MotorSteps = 0; //"Global" variables unsigned char MotorSpeed = 0; const unsigned char RampTable[NUM_RAMP_STEPS] = {...appropriate values...}; bit RampUp() { if ( MotorSteps &lt; NUM_RAMP_STEPS ) { MotorSpeed = RampTable[MotorSteps]; return 0; } else return 1; } </code></pre> <p>At least you could test your integer rather than the float to avoid the floating point libraries unless you need them...</p> <pre><code>unsigned **int** MotorSteps = 0; //"Global" variables unsigned **int** MotorSpeed = 0; bit RampUp() { if ( MotorSteps &lt; 51 ) { float t = MotorSteps; t = (1-((50 - t)/50))*15; t = (t * t); MotorSpeed = 100 + t; return 0; } else return 1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload