<?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: Stepper motor Speed Ramp in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208490#M17737</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Kef,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your approach to compensate for the DDS output jitter is very interesting, although I would be concerned about the extra bus cycles for the additional processing, and the ability to use higher DDS clock rates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I happened to look at the details of the Slo-syn products, named in the OP.&amp;nbsp; I note that the typical lower power models have the torque specified up to 10,000 steps per second, and the basic model has 200 steps per revolution (1.8 deg/step).&amp;nbsp; To achieve the maximum speed, it would seem that there would be problems with either control method.&amp;nbsp; I think that the DDS method is out of the picture for the&amp;nbsp;HCS08.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the lookup method, the&amp;nbsp;minimum interrupt period would be 50us or 400 bus cycles,&amp;nbsp;requiring an output compare&amp;nbsp;interrupt twice per cycle.&amp;nbsp; Without allowing for multiple timer overflows, and the extra code to do this, the minimum allowable frequency would be about 62 Hz.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If we assume each frequency step&amp;nbsp;2 Hz, there would be nearly 5000 steps over the full frequency range, therefore requiring a linear interpolation process&amp;nbsp;to reduce the 10 kbyte&amp;nbsp;table size.&amp;nbsp; For the HCS08 there is no hardware assistance for doing this, compared with the HCS12.&amp;nbsp; I am guessing that the ISR code will require significantly more than 200 bus cycles, (allowing&amp;nbsp;50 percent processor usage).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, a different strategy might be feasible - one that does not require interrupts at twice the output rate, and is an adaption of the lookup method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;frequency only needs to change at each speed&amp;nbsp;ramp step, and remains constant between steps.&amp;nbsp; If I were to assume a ramping rate of 1kHz per second (I don't know whether this is realistic), and with a 2 Hz speed step, would represent 500 output compare interrupts per second for the timer controlling the ramp.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, the proposal would be to utilise 50 percent&amp;nbsp;PWM output for the drive, and to simultaneously change the modulo and PWM channel settings&amp;nbsp;as a consequence of&amp;nbsp;each ramp interrupt.&amp;nbsp; I have not examined the synchronising process required to prevent any gliches or discontinuities, so might require an additional interrupt on the PWM channel, at the ramp interrupt rate.&amp;nbsp; Of course, the new settings must be calculated during the ramp ISR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 May 2011 23:47:48 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2011-05-27T23:47:48Z</dc:date>
    <item>
      <title>Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208473#M17720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello, as the title says i´m trying to do a speed ramp for a slo-syn stepper motor.&lt;/P&gt;&lt;P&gt;I´m using DEMO9s08LL16 board, an example of my code (not speed ramp):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PTCD_PTCD4 = 0;&lt;/P&gt;&lt;P&gt;delay(10)&amp;nbsp;&amp;nbsp; //cpu cycles 10 multiplies 100 cycles&lt;/P&gt;&lt;P&gt;PTCD_PTCD4 = 1;&lt;/P&gt;&lt;P&gt;delay(10); //cpu cycles&lt;/P&gt;&lt;P&gt;PTCD_PTCD4 = 0;&lt;/P&gt;&lt;P&gt;delay(10)&amp;nbsp;&amp;nbsp; //cpu cycles&lt;/P&gt;&lt;P&gt;PTCD_PTCD4 = 1;&lt;/P&gt;&lt;P&gt;delay(10)&amp;nbsp;&amp;nbsp; //cpu cycles&lt;/P&gt;&lt;P&gt;PTCD_PTCD4 = 0;&lt;/P&gt;&lt;P&gt;delay(10)&amp;nbsp;&amp;nbsp; //cpu cycles&lt;/P&gt;&lt;P&gt;PTCD_PTCD4 = 1;&lt;/P&gt;&lt;P&gt;delay(10)&amp;nbsp;&amp;nbsp; //cpu cycles&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I decrement the delay time the motor will go faster, but in order to speed it, i need to have a speed ramp.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know speed ramps change the starting delay and decrement it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;greetings,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Skaptor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 May 2011 04:04:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208473#M17720</guid>
      <dc:creator>Skaptor</dc:creator>
      <dc:date>2011-05-22T04:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208474#M17721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Skaptor, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For ramping a stepper motor, you will need to achieve a linear output frequency control.&amp;nbsp; Varying&amp;nbsp;the delay value will give non-linear frequency control.&amp;nbsp; A method of achieving&amp;nbsp;linear control can be found &lt;A href="https://community.freescale.com/message/73208#73208" title="https://community.freescale.com/message/73208#73208"&gt;https://community.freescale.com/message/73208#73208&lt;/A&gt;.&amp;nbsp; The thread provided an ADC controlled stepper speed, however linearly ramping the speed should also be simple to achieve.&amp;nbsp; What ramp slope&amp;nbsp;(Hz per second) do you require?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 May 2011 03:00:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208474#M17721</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-23T03:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208475#M17722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply bigmac.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe I achieved linear&amp;nbsp; output frequency (I saw that within an oscilloscope).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The slope I need should be arround 10 Hz per sec, I need that to speed the motor to its maximmum speed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 May 2011 05:58:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208475#M17722</guid>
      <dc:creator>Skaptor</dc:creator>
      <dc:date>2011-05-23T05:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208476#M17723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Skaptor,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mac is right in that the frequency is non-linear. To be specific, the frequency will be the reciprocal of the delay time. At lower frequencies, it will look pretty linear, but the curvature will increase as the speed increases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did the same thing as what you are doing&amp;nbsp; back in the 80's, (using an MC68701) and I simply indexed through a table of delay values. I built the delay table using MathCad, and imported it into my firmware. I indexed forward through the table﻿ to ramp-up to speed, and backward through the table﻿ to ramp-﻿down. I used the output-compare function to generate the step pulses (similar to what you have now with the S08 timers)﻿.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 May 2011 06:54:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208476#M17723</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2011-05-23T06:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208477#M17724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please bear with me i´m just 16 and don´t know lots of things yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ok i´m trying to use the TPM module to make the acceleration, I want to do it in 2000 mS but I can´t get the timer working here´s an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Timer1 overflow about every 1ms&lt;BR /&gt;&amp;nbsp; TPM1MOD = 8000;&lt;BR /&gt;&amp;nbsp; TPM1SC = 0x54;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The timer ISR wont execute. any ideas? I appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the ISR:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;interrupt VectorNumber_Vtpm1ch0 void timer1_CH0(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear CH0F flag&lt;BR /&gt;&amp;nbsp; TPM1C0SC &amp;amp;=0x7F;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Clear the 16-bit timer1 counter&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; TPM1CNT = 0x00;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;}﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 May 2011 07:12:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208477#M17724</guid>
      <dc:creator>Skaptor</dc:creator>
      <dc:date>2011-05-24T07:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208478#M17725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp; If your MCU has the&amp;nbsp;S08RTCV1 rtc in it you could do this. If you still want to use the TPM, tell me what the oscillator frequency is and I will show you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void InitRTCInternalClock(void){ // Set RTIE to enable interrupts, select the 1KHz internal oscillator // set the divider to 1 for a 1ms interrupt. RTCSC = 0x18; RTCMOD = 0;}interrupt  VectorNumber_Vrtc void  RTC_InterruptHandler(void){       // Do your 1ms stuff here RTCSC |= 0x80;   // Ack the interrupt}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;BTW You also need to ack the TPM interrupt as well. And did you enable processor&amp;nbsp;&amp;nbsp;interrupts? Use the&amp;nbsp;EnableInterrupts macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 May 2011 07:40:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208478#M17725</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2011-05-24T07:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208479#M17726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Skaptor,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are two different methods of achieving a linear frequency control.&amp;nbsp; The method that Rocco has used might be described as a "table lookup" method.&amp;nbsp; The method that I previously referenced is a direct digital synthesis (DDS) method, with square wave output.&amp;nbsp; Either method would require the use of two timers, one for generating the output frequency, and a second one for the slow ramp output control.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My personal preference is the DDS method, for which the timer interrupt period remains constant.&amp;nbsp; This represents the DDS clock.&amp;nbsp; The method would utilize a 16-bit accumulating register, with a value N added to the accumulator during each interrupt.&amp;nbsp; Each overflow of the accumulator represents one cycle of the output frequency.&amp;nbsp; Therefore, the higher the value of N, the more quickly will the accumulator overflow, and the higher will be&amp;nbsp;the output frequency.&amp;nbsp; The output frequency will be given by the formula:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fout = Fclk * N / 65536&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The incremental frequency step will be:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;delta_F = Fclk / 65526&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's assume&amp;nbsp;delta_F&amp;nbsp;= 0.1 Hz.&amp;nbsp; The will result in Fclk = 6553.6 Hz (or Tclk = 152.6 us).&amp;nbsp; Assume that the TPM1 module is used, with software output compare on channel 0, for this purpose. Your current interpretation of TPM operation seems to be incorrect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the frequency ramp control, I have assumed that TPM2 module is used, again with software output compare on channel 0.&amp;nbsp; In this case, an interrupt would occur each 10ms, where the current N value would be incremented, decremented, or remain unchanged, depending on the current speed setting for the stepper.&amp;nbsp; This will result in a frequency ramp of 0.1 Hz per 10ms, or 10 Hz per second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following snippet shows the ISR code for each interrupt.&amp;nbsp; I have not shown the initialisation required for each TPM module, nor the code required to set the speed value.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;// For following output compare intervals, 8 MHz bus frequency is assumed&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;#define INCR_VAL&amp;nbsp; 1220&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // TPM1C0 Output compare period 152.6us with prescale 1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;#define RAMPTIME&amp;nbsp; 19999&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // TPM2C0 Output compare period 10ms with prescale 4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;#define STEP_CLK&amp;nbsp; PTAD_PTAD0&amp;nbsp; // GPIO pin&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;word ramp, speed;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Global variables&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;interrupt void ISR_TPM1C0( void)&amp;nbsp; // 152.6us intervals&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; static word accum = 0;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; TPM1C0SC_CHOF = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear flag&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; TPM1C0V += INCR_VAL;&amp;nbsp; // Set next compare value&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; accum += ramp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// Update accumulation count&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; if (accum &amp;amp; 0x8000)&amp;nbsp;&amp;nbsp; // Test MSB&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STEP_CLK = 1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; else&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; STEP_CLK = 0;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;interrupt void ISR_TPM2C0( void)&amp;nbsp; // 10ms intervals&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; TPM2C0SC_CHOF = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear flag&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; TPM2C0V += RAMPTIME;&amp;nbsp; // Set next compare value&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; if (ramp &amp;lt; speed)&amp;nbsp; ramp++;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; if (ramp &amp;gt; speed)&amp;nbsp; ramp--;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;BR /&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In practice, the maximum value within the global variable &lt;FONT face="courier new,courier"&gt;speed&lt;/FONT&gt;&amp;nbsp;would be limited to about 2000, giving an upper frequency limit of 200 Hz.&amp;nbsp; This will minimize short term frequency jitter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 May 2011 12:40:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208479#M17726</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-24T12:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208480#M17727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is of course interesting to use DDS, but I'm not sure if it's a good idea to use DDS for step motor velocity profiles. For slow speeds yes, it should be ok. But let's consider the case of 200Hz step rate, which is not high, and 6.5kHz DDS clock, please correct my if I'm wrong.&lt;/P&gt;&lt;P&gt;DDS output clock of 200Hz means that you should see 200*2 toggles per second or 200Hz of average frequency. But instant frequency&amp;nbsp;in fact may change from&amp;nbsp;period to period (of Fout). Outputing the same 200Hz signal, period will&amp;nbsp;sometimes&amp;nbsp;change by +1/Fdds or -1/Fdds, which is +-152us in our case. This is because Fdds/Fout ratio is not integer, it's between 32 and 33. So the instant output freqency will vary from Fdds/32=204.8Hz to Fdds/33=198.6Hz to produce average Fout of 200Hz. 5Hz difference&amp;nbsp;may be too big step for some motors and loads.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It&amp;nbsp;is&amp;nbsp;more difficult to calculate output compare delays on the fly, from step to step. But&amp;nbsp;200Hz interrupt rate is &amp;gt;30 times lower than in the case of 6.5kHz DDS. As another&amp;nbsp;bonus you should be able&amp;nbsp;to accelerate your motor to higher speeds.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 May 2011 18:11:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208480#M17727</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-05-24T18:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208481#M17728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree that DDS is a great algorithm for generating rates, but as Kef mentioned, a firmware implementation could be either too slow or too inaccurate. When I need DDS, I do it in an FPGA, with a minimum add-rate of 1 MHz.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The approach I took only needs a single timer (that's all I had in 68701). I simply loaded a table value into the output-compare register, and on each OCR interrupt, I would load the next value from the table. It was just a couple of instructions per step, and I could get step-rates up to 40kHz twenty years ago.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A big disadvantage over DDS is the lack of flexibility. With DDS, you could generate any ramp you need on the fly, whereas the table uses a "canned" ramp. If a canned ramp is all you need, the table approach is quick, easy﻿ and extremely smooth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Building the table is the challenge. The output-compare circuit generates delays, which is the reciprocal of rate. On top of that, the velocity update rate is based on that same variable delay, so that is a second level of non-linearity. Also, I did not use a linear ramp, built built a ramp derived from the motor's torque-curve, for a third level on non-linearity.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I used the three equations in MathCad to generate the table, and programmed that into the microcontroller's EEPROM separately (allowing me to program different tables for different motors).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 May 2011 03:34:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208481#M17728</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2011-05-25T03:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208482#M17729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have done it. thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is my initialization:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;////////////////////////////////////////////////////////////////////////////&amp;nbsp;&lt;BR /&gt;// Init TPM&lt;BR /&gt;////////////////////////////////////////////////////////////////////////&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;// Timer1 overflow about every 1ms&lt;BR /&gt;&amp;nbsp; TPM1MOD = mod;&lt;BR /&gt;&amp;nbsp; // Stops timer2 and select 1 as prescaler divisor&lt;BR /&gt;&amp;nbsp; TPM1SC = 0x0C;&amp;nbsp; //4C&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; TPM1C0SC =0x54;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; TPM1C1SC =0x10;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; // Timer2 overflow about every 1ms&lt;BR /&gt;&amp;nbsp; TPM2MOD = 0;&lt;BR /&gt;&amp;nbsp; // Stops timer2 and select 1 as prescaler divisor&lt;BR /&gt;&amp;nbsp; TPM2SC = 0x00;&lt;BR /&gt;&amp;nbsp; TPM2C0SC =0x10;&amp;nbsp; //with these i have enabled the isr&lt;BR /&gt;&amp;nbsp; TPM2C1SC =0x10;&amp;nbsp; ﻿&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;interrupt VectorNumber_Vtpm1ch0 void timer1_CH0(void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp; msec++;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; if(msec &amp;gt; 5)&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; msec = 0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(mod &amp;gt; 100)&amp;nbsp; //this is the ramp&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mod -= 20;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; TPM1MOD = mod;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear CH0F flag&lt;BR /&gt;&amp;nbsp; TPM1C0SC &amp;amp;=0x7F;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Clear the 16-bit timer1 counter&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //TPM1CNT = 0x00;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;}﻿&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 May 2011 06:25:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208482#M17729</guid>
      <dc:creator>Skaptor</dc:creator>
      <dc:date>2011-05-25T06:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208483#M17730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Kef,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I agree with your observations about the limitations of the DDS method for higher speed applications, including the amount of jitter that you calculate for the frequency waveform.&amp;nbsp; However, my assumption was that the motor and load would provide&amp;nbsp;inertia for "low pass filtering"&amp;nbsp;the jitter component, resulting in a&amp;nbsp;significantly lower modulation of the motor speed.&amp;nbsp; Otherwise, there would not be the&amp;nbsp;requirement for the speed ramping of a low inertia system.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the example that I posted, I purposely chose rather conservative speed requirements with a frequency resolution of 0.1Hz for the average frequency, which would be accurate.&amp;nbsp;&amp;nbsp;Still assuming the&amp;nbsp;8MHz bus, it should be feasible to quadruple the interrupt rate, because of the simplicity of the ISR code.&amp;nbsp; Without increasing the length of the accumulating register beyond 16 bits, this would also have increased the frequency increment to 0.4Hz.&amp;nbsp; But perhaps this would be OK for&amp;nbsp;many 800Hz stepper applications, thus retaining the code simplicity, and not having to revert to assembly coding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A major advantage of the DDS method is the ability to control down to zero frequency, for applications where this is important.&amp;nbsp; This would appear to be a major weakness of the lookup table method with frequency to period conversion.&amp;nbsp; In fact, there would always be a minimum frequency, below which the timer would overflow.&amp;nbsp; Of course, you can fiddle with prescale rates on the fly, or handle multiple overflows, but I will&amp;nbsp;assume this would greatly increase code complexity within the timer ISR and elsewhere, and maybe ramping would be virtually impossible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There&amp;nbsp;is also likely to be the situation where the minimum speed requirement will dictate&amp;nbsp;a given&amp;nbsp;period interval, so that the speed resolution at high speeds&amp;nbsp;could be considerably degraded.&amp;nbsp; Using the previous example, a 200Hz stepper with at most 0.1Hz resolution, would require a period resolution of 2.5 us (1/199.9 - 1/200) and a TPM interval of 2000, with appropriate prescale factor.&amp;nbsp; Therefore TPM overflow will occur for frequencies less than about 6.1 Hz, or a speed control ratio of approximately 32:1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Neither method is ideal for all applications - the best method will likely depend of the finer detail of each application.&amp;nbsp; I&amp;nbsp;posted the DDS snippet as a basis for experiment, because of the simplicity of the code, and to also provide an example of TPM output compare operation, which seemed to be needed.&amp;nbsp; Maybe you could similarly post a&amp;nbsp;snippet for the alternative method, as a means of comparison.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 May 2011 19:29:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208483#M17730</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-25T19:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208484#M17731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Skaptor,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps I am missing something, but your code&amp;nbsp;snippet appears to commence with a hard-coded frequency of 500 Hz at TPM1C0&amp;nbsp;pin output, and then increases the frequency until a frequency of 40,000 Hz (200 bus cycle period)&amp;nbsp;is reached - the frequency will be one half the interrupt rate.&amp;nbsp;&amp;nbsp;A frequency&amp;nbsp;step occurs&amp;nbsp;starting&amp;nbsp;with&amp;nbsp;5 ms interval, and the final step interval is reduced to about 100 us.&amp;nbsp; If my calculations are correct, the first frequency step would be 2.5 Hz, and the final frequency step would be 13.3 kHz, i.e. the ramp starts with a slope of 0.5 Hz/ms, and concludes with a slope of 133 kHz/ms.&amp;nbsp; Deceleration of the motor is not covered by the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firstly, the output frequency range seems rather high for a motor device.&amp;nbsp; Secondly, the frequency ramp is non-linear to an extreme.&amp;nbsp; There could also be a further problem because the execution of the ISR code may not be completed within 100 bus cycles, so some interrupts would likely be missed, giving erratic operation.&amp;nbsp; There is always an upper limit to the rate at which interrupts may occur, dependent on many factors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a general comment, since you are changing the TPM modulo value, there may be a case for using the TPM overflow interrupt, rather than the channel interrupt.&amp;nbsp; The channel output toggle on compare feature will still work, even when the channel interrupt is disabled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 May 2011 20:34:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208484#M17731</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-25T20:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208485#M17732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mac,&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;bigmac wrote:&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;A major advantage of the DDS method is the ability to control down to zero frequency, for applications where this is important.&amp;nbsp; This would appear to be a major weakness of the lookup table method with frequency to period conversion.&amp;nbsp; In fact, there would always be a minimum frequency, below which the timer would overflow.&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;Perhaps I am missing something, but your code&amp;nbsp;snippet appears to commence with a hard-coded frequency of 500 Hz at TPM1C0&amp;nbsp;pin output, and then increases the frequency until a frequency of 40,000 Hz ﻿. . .&lt;BR /&gt;&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;What hasn't been mentioned is a stepper-motor's "base" speed: the step-rate that the motor needs to start ramping from. This rate is never zero, and 500 Hz seems like a reasonable value. Any step-rate slower than the base-rate causes the motor to "lurch" from step to step, causing vibration and noise. The frequency is below that mechanical low-pass filter that you mentioned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And speaking of that mechanical low-pass filter, you are correct in that it should compensate for the jitter in the step-rate. However, a motor-driver circuit that contain anti-resonant circuitry (compensating for the mid-band resonance problem) typically cannot handle the jitter. The jitter appears as repeating changes in acceleration, causing the driver circuit to not know what to do.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2011 03:03:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208485#M17732</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2011-05-26T03:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208486#M17733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Max,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;no doubt, your code is great and made me wondering if I could use DDS for my SM(step motor) application, where I'm acceleratting it to 20kHz. It would simplify calculations a lot. But high ISR rate, high jitter and output clock makes DDS impractical. I doubt it is possible to accelerate SM to high speeds with 3% jitter/T(period). Jitter causes extra vibration(acceleration) and SM loose their torque on higher speeds. But I may try.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the past on HC11 I was using 2&amp;nbsp;or 3 lines interpolation of output compare delay vs step# curve for linear velocity profile like in attached xls file. ISR code is quite simple.&amp;nbsp;When accelerating I was decrementing T by smaller or higher dT, depending on current T.&lt;/P&gt;&lt;P&gt;On&amp;nbsp;S12 I'm calculating T and deceleration/acceleration paths on the fly. This allows to accept new position, acceleration or target speed commands at any time, motor smoothly accelerates/decelerates and changes direction without extra momevents or idling.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Long T is no problem at all. Yes, I'm counting timer overlows. Bad cases like T%65536 &amp;lt; interrupt latency are divided into two parts 0x8000 ticks and 0x8000+T%65536. Here's my code for S12, I didn't use the same approach on S08 yet:&lt;/P&gt;&lt;PRE&gt;#pragma TRAP_PROCvoid smisr(void){static unsigned long period;static char half; // extra +0x8000 interrupt   // is overflow counter &amp;gt; 0   if( (period &amp;gt;&amp;gt; 16)!= 0)   {      if(half)      {         // timer compare value += 0x8000         TCh(STEPPINNO) += 0x8000;         half = 0;      }      else      {         // decrement overflow counter         period -= 0x10000;               if( (period &amp;gt;&amp;gt; 16) == 0 )         {            // set compare mode to SET            SETCOMPMODE(STEPPINNO, COMPSET);         }      }   }   else   {      // set compare mode to CLEAR      SETCOMPFROMSETTOCLEAR(STEPPINNO);      // force compare output      CFORC |= (1&amp;lt;&amp;lt;STEPPINNO);      // calculate new period here      period = ???;      if( (unsigned short)period &amp;lt; latency )      {         half = 1;         TCh(STEPPINNO) = 0x8000 + TCh(STEPPINNO) + (unsigned short)period;      }      else         TCh(STEPPINNO) = TCh(STEPPINNO) + (unsigned short)period;            // should we set OC pin on next ISR?            if( (period &amp;gt;&amp;gt; 16)!= 0)      {         SETCOMPMODE(STEPPINNO, COMPSET);      }   }   // clear flag   TFLG1 &amp;amp;= (1&amp;lt;&amp;lt;STEPPINNO);}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 May 2011 15:22:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208486#M17733</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-05-26T15:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208487#M17734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know it will be useful,&amp;nbsp;but it is possible to improve jitter of your DDS pulse generator a lot in the case one has spare output compare channel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your code, accum variable is in fact&amp;nbsp;the phase&amp;nbsp;of the signal. When it's a time in Fdds ISR to generate pulse or toggle the pin level, phase error is known and we can calculate delay needed to generate pulse more precisely. We can either check if on the next Fdds ISR phase will overflow and calculate positive phase correction Ph_togo in timer ticks units and generate pulse on +Ph_togo. Or, we can wait while phase overflows and calculate negative phase correction Ph_late, and generate output compare pulse on&amp;nbsp;+Tdds-Ph_late.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;interrupt void ISR_TPM1C0( void)&amp;nbsp; // 152.6us intervals&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; word accum;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; static word old_accum;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;﻿&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; TPM1C0SC_CHOF = 0;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clear flag&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; TPM1C0V += INCR_VAL;&amp;nbsp; // Set next compare value&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;﻿&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; accum = old_accum + ramp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Update accumulation count&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; if( (old_accum ^ accum) &amp;amp; 0x8000) // was there an phase oveflow?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; {&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; generate_toggle_on(TPM1C0V&amp;nbsp;- (unsigned long)INCR_VAL * (accum &amp;amp; ~0x8000)&amp;nbsp;﻿/ ramp);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; }﻿&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; old_accum = accum;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Yes, division in 6.5kHz interrupt is not nice thing. But we can eliminate division precalculating INCR_VAL / ramp * 65536 multiplier on change of ramp and eliminate division in Fdds interrupt.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;word mramp; // precalculated mramp&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; mramp = (unsigned long)INCR_VAL&amp;nbsp;* 65536 / ramp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Then expression in ISR should be this&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; generate_toggle_on(TPM1C0V -&amp;nbsp;((unsigned long)(accum &amp;amp; ~0x8000) ﻿* mramp) &amp;gt;&amp;gt; 16);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;I tried it on S12, so my apologies for no code for generate_toggle_on().&amp;nbsp;Using the same Fdds=6.5kHz and Fout=200Hz, jitter dropped from ~150us down to 60ns.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;﻿&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;﻿&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2011 14:02:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208487#M17734</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-05-27T14:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208488#M17735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;[For some reason edit message succeeds, but I see old contents. ]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jitter dropped to one timer tick.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2011 14:16:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208488#M17735</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-05-27T14:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208489#M17736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Rocco,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;rocco wrote:&lt;BR /&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;What hasn't been mentioned is a stepper-motor's "base" speed: the step-rate that the motor needs to start ramping from. This rate is never zero, and 500 Hz seems like a reasonable value. Any step-rate slower than the base-rate causes the motor to "lurch" from step to step, causing vibration and noise. The frequency is below that mechanical low-pass filter that you mentioned.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I&amp;nbsp;had assumed that zero minimum velocity would be a requirement for those applications requiring open-loop position control.&amp;nbsp; The provision of speed ramping might still be important to prevent missed steps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding was&amp;nbsp;that "lurching from step to step" was fundamental to the operation of a &lt;U&gt;stepper&lt;/U&gt; motor.&amp;nbsp; This should obviously not be a problem for the stepper motor itself.&amp;nbsp; If this is problematic for the load, at low operational speeds, perhaps a motor type with more steps per revolution&amp;nbsp;is needed, or a more complex microstepping drive could be employed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2011 22:19:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208489#M17736</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-27T22:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208490#M17737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Kef,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your approach to compensate for the DDS output jitter is very interesting, although I would be concerned about the extra bus cycles for the additional processing, and the ability to use higher DDS clock rates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I happened to look at the details of the Slo-syn products, named in the OP.&amp;nbsp; I note that the typical lower power models have the torque specified up to 10,000 steps per second, and the basic model has 200 steps per revolution (1.8 deg/step).&amp;nbsp; To achieve the maximum speed, it would seem that there would be problems with either control method.&amp;nbsp; I think that the DDS method is out of the picture for the&amp;nbsp;HCS08.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the lookup method, the&amp;nbsp;minimum interrupt period would be 50us or 400 bus cycles,&amp;nbsp;requiring an output compare&amp;nbsp;interrupt twice per cycle.&amp;nbsp; Without allowing for multiple timer overflows, and the extra code to do this, the minimum allowable frequency would be about 62 Hz.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If we assume each frequency step&amp;nbsp;2 Hz, there would be nearly 5000 steps over the full frequency range, therefore requiring a linear interpolation process&amp;nbsp;to reduce the 10 kbyte&amp;nbsp;table size.&amp;nbsp; For the HCS08 there is no hardware assistance for doing this, compared with the HCS12.&amp;nbsp; I am guessing that the ISR code will require significantly more than 200 bus cycles, (allowing&amp;nbsp;50 percent processor usage).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, a different strategy might be feasible - one that does not require interrupts at twice the output rate, and is an adaption of the lookup method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;frequency only needs to change at each speed&amp;nbsp;ramp step, and remains constant between steps.&amp;nbsp; If I were to assume a ramping rate of 1kHz per second (I don't know whether this is realistic), and with a 2 Hz speed step, would represent 500 output compare interrupts per second for the timer controlling the ramp.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Therefore, the proposal would be to utilise 50 percent&amp;nbsp;PWM output for the drive, and to simultaneously change the modulo and PWM channel settings&amp;nbsp;as a consequence of&amp;nbsp;each ramp interrupt.&amp;nbsp; I have not examined the synchronising process required to prevent any gliches or discontinuities, so might require an additional interrupt on the PWM channel, at the ramp interrupt rate.&amp;nbsp; Of course, the new settings must be calculated during the ramp ISR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2011 23:47:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208490#M17737</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-05-27T23:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208491#M17738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;bigmac wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;I&amp;nbsp;had assumed that zero minimum velocity would be a requirement for those applications requiring open-loop position control.&amp;nbsp; The provision of speed ramping might still be important to prevent missed steps.&lt;/BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It is a reasonable assumption, and one I also made at first. But very quickly you learn that 1) the beginning chunk of your ramp can be tossed away and you can get up to speed quicker, and 2) you can avoid a lot noise and vibration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The physics is that, regardless of how fast you issue step pulses, the motor can make a single step rather quickly. Any step-rate below the base-rate will allow the motor to step and then come to a full stop before the next step pulse. Hence noise and vibration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And you are right, the load can affect the base rate, if it is tightly coupled to the motor. But most stepper applications use soft-coupling to the load to protect it against vibration. The driver circuit can also effect the base-rate.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 May 2011 01:49:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208491#M17738</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2011-05-28T01:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Stepper motor Speed Ramp</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208492#M17739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yes,&amp;nbsp;DDS with jitter compensation doesn't seem practical, it is more like academic excercise.&amp;nbsp;But if&amp;nbsp;calculated phase adjustment almost removes jitter, then what about calculating&amp;nbsp;approximate adjustment? Higher, but still acceptable jitter could be OK and could allow to use lower Fdds for the same output frequency.&amp;nbsp;Hope it is possible to estimate fractional multiplier on change of speed with just one DIV instruction call, and maybe calculate phase adjustment on phase overflow with just 1-2 MULs.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 May 2011 23:56:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Stepper-motor-Speed-Ramp/m-p/208492#M17739</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-05-28T23:56:31Z</dc:date>
    </item>
  </channel>
</rss>

