<?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: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151950#M4358</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi Yj,&lt;BR /&gt;&lt;BR /&gt;Normally you don't use PWM on a stepper motor. You use pulses, and how often you pulse the windings determines speed, but usually the pulse are all of the same duration, and the phasing of the pulses determines the motion of the motor.&lt;BR /&gt;&lt;BR /&gt;Does the board you are using already have a stepper motor drive circuit on it ?&lt;BR /&gt;Do you know if it is a bipolar or unipolar motor (4 wires or 6 wires)?&lt;BR /&gt;&lt;BR /&gt;As for an encoder, there is no specific support for this, but it all can be done in software. It would be nice if you connect it to inputs that can provide interrupts, or you can poll the encoder. But you don't need any external decoders or counters.&lt;BR /&gt;&lt;BR /&gt;Is it a mechanical encoder or an optical encoder? Mechanical encoders require debouncing and are only good up to a certain RPM&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Oct 2007 03:34:54 GMT</pubDate>
    <dc:creator>JimDon</dc:creator>
    <dc:date>2007-10-05T03:34:54Z</dc:date>
    <item>
      <title>Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151949#M4357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a student doing my project where I'm going to use this microcontroller (MC9S12DP256B) to control a hybrid stepper motor in a closed-loop system. I'm still new in learning this microcontroller. Therefore, I have few questions stated below :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Can anyone provide me an example of C program to control a hybrid stepper motor in closed-loop&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; system using PWM?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Incremental encoder will be used to feedback the position of the motor. As I know, decoder and&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; counter will be needed to change the quadrature signal to digital position of the motor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Is MC9S12DP256B provides such capabilities? So that external decoder and counter can be&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; eliminated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. To use it in motor control system, what else should I read from its datasheet?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would be grateful for any reply. Thanks you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;best regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;yj&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by yj on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2007-10-01&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;04:27 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Message Edited by yj on &lt;/SPAN&gt;&lt;SPAN class="date_text"&gt;2007-10-01&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;04:28 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Oct 2007 22:05:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151949#M4357</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2007-10-01T22:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151950#M4358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi Yj,&lt;BR /&gt;&lt;BR /&gt;Normally you don't use PWM on a stepper motor. You use pulses, and how often you pulse the windings determines speed, but usually the pulse are all of the same duration, and the phasing of the pulses determines the motion of the motor.&lt;BR /&gt;&lt;BR /&gt;Does the board you are using already have a stepper motor drive circuit on it ?&lt;BR /&gt;Do you know if it is a bipolar or unipolar motor (4 wires or 6 wires)?&lt;BR /&gt;&lt;BR /&gt;As for an encoder, there is no specific support for this, but it all can be done in software. It would be nice if you connect it to inputs that can provide interrupts, or you can poll the encoder. But you don't need any external decoders or counters.&lt;BR /&gt;&lt;BR /&gt;Is it a mechanical encoder or an optical encoder? Mechanical encoders require debouncing and are only good up to a certain RPM&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Oct 2007 03:34:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151950#M4358</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2007-10-05T03:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151951#M4359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Thanks for your reply.&lt;BR /&gt;&lt;BR /&gt;But I was requested to use the PWM module inside this microcontroller (MC9S12DP256B) to control the stepper motor. Is it possible to use PWM? Because it also generates pulses and its duty cycle and period are programmable.&lt;BR /&gt;&lt;BR /&gt;I have been provided a step motor drive. So I will have to communicate the microcontroller with this driver. The stepper motor is a bipolar stepper motor and it has 8 leads.&lt;BR /&gt;&lt;BR /&gt;I'm using incremental encoder (optical). The output is two signal A and B where they are 90 degree out of phase from each other.&lt;BR /&gt;&lt;BR /&gt;So, what are the basic steps I can have as my reference to program this microcontroller?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;best regards,&lt;BR /&gt;yj&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by yj on &lt;SPAN class="date_text"&gt;2007-10-05&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:20 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Oct 2007 08:18:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151951#M4359</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2007-10-05T08:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151952#M4360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello yj,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The control of the stepper motor will be dependent on the requirements of the driver device or circuit.&amp;nbsp; You do not say what device is used.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;For a &lt;U&gt;bipolar&lt;/U&gt; stepper motor, eight leads seems an unusually large number, presumably four windings rather than the expected two windings.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Closed loop control of a stepper motor would seem very unusual, particularly for a compound type stepper motor where the angular incremental steps are likely to be small.&amp;nbsp; Usually, stepper motors are chosen because they provide open loop control.&amp;nbsp; What is hoped to be achieved using closed loop control?&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Do you require control of &lt;U&gt;absolute&lt;/U&gt; position?&amp;nbsp; If so,&amp;nbsp;an incremental encoder does not provide this.&amp;nbsp; Some optical encoders do provide an index pulse once per revolution, in addition to the quadrature output, which may be used to provide an absolute position reference.&amp;nbsp; This might be used to initialise the motor shaft to a known position on power-up.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;The following lengthy thread discusses the possible methods of decoding quadrature signals -&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&amp;amp;message.id=398" target="_blank"&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;A href="http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&amp;amp;message.id=398" target="test_blank"&gt;http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&amp;amp;message.id=398&lt;/A&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Oct 2007 09:18:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151952#M4360</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2007-10-05T09:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151953#M4361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Thanks Mac.&lt;BR /&gt;He is correct about the encoders. In fact, normally not having to use and encoder is a stated advantage of a stepper motor, but there is no reason it can not be done.&lt;BR /&gt;&lt;BR /&gt;Well usually an 8 wire for use with unipolar drive is connected with 4 of the wires to +V, and 4 of the wires driven to ground, so you have A,-A,B and -B.&lt;BR /&gt;&lt;A href="http://www.wimb.net/index.php?s=motion&amp;amp;page=52" rel="nofollow" target="_blank"&gt;Like this.&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Let me ask you this - did he say that you must micro-step the motor using PWM?&lt;BR /&gt;&lt;BR /&gt;The way I have done it is using a timer,&amp;nbsp; a state table and counters, but PWM channels could be used for micro-stepping. Table 1 in this &lt;A href="http://www.solarbotics.net/library/pdflib/pdf/motorbas.pdf" rel="nofollow" target="_blank"&gt;document&lt;/A&gt; shows how the data in the table would be. This document also discusses micro-stepping.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Oct 2007 09:48:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151953#M4361</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2007-10-05T09:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151954#M4362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Ok, now some reference material for the hcs12.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Here is a list of &lt;A href="http://www.freescale.com/webapp/sps/site/overview.jsp?code=S12S12X&amp;amp;fsrch=1" rel="nofollow" target="_blank"&gt;reference&lt;/A&gt; material for the HCS12&lt;BR /&gt;&lt;BR /&gt;I strongly recommend you read S12PWM8B6CV1 and also AN2250 and the the software files.&lt;BR /&gt;This example uses the PWM channels to play music, which means that you can generate any wave form with the PWM. I doubt in your case you will need the filter as the windings of the motor will act as a filter, but you might.&lt;BR /&gt;&lt;BR /&gt;Think of it this way, instead of a wav file, you could send analog samples (from a table) that would be the pulse train. Doing things this way you could vary the amplitude of the pulses as well.&lt;BR /&gt;&lt;BR /&gt;I will warn you that the code in AN2250 is very old and not really done the way things should be - like he has includes for the MCU registers which you should not do.&lt;BR /&gt;&lt;BR /&gt;I also recommend you take the time to learn Code Warrior - too often Electrical Engineering students under estimate the power an importance of good software tools and understanding how they work.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by JimDon on &lt;SPAN class="date_text"&gt;2007-10-05&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:58 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Oct 2007 00:49:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151954#M4362</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2007-10-06T00:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151955#M4363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;Most industrial duty stepper drives do in fact employ PWM.&lt;/DIV&gt;&lt;DIV&gt;Not to produce the steps, but to control the winding current.&lt;/DIV&gt;&lt;DIV&gt;For a very basic description:&lt;/DIV&gt;&lt;DIV&gt;You turn on and off the windings like you normally do but when they are "on" you don't simply turn them on but control the current through the winding by PWM switching. This allows a current profile to be applied to allow a faster magnetic field etc etc... Another simple/major benefit is when the stepper is simply holding position the current can be reduced to reduce the heat.&lt;/DIV&gt;&lt;DIV&gt;This current control is usually closed loop, in that the actual winding current is fed back into the controller.&lt;/DIV&gt;&lt;DIV&gt;Maybe this is what was meant???&lt;/DIV&gt;&lt;DIV&gt;This PWM can be thought of quite seperately from actually getting the motor to turn. Once you have the motor actually turning then you can do the PWM current control on top in order to maximise performance.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Oct 2007 06:38:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151955#M4363</guid>
      <dc:creator>peg</dc:creator>
      <dc:date>2007-10-06T06:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151956#M4364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;Thanks for your replies.&lt;BR /&gt;&lt;BR /&gt;Basically, my system is like this:&lt;BR /&gt;1.&amp;nbsp;&amp;nbsp;&amp;nbsp; Firstly, there will be a Graphical User Interface (GUI) for the user to input their desired position, speed and direction. This GUI will communicate with MC9S12DP256B through RS232.&lt;BR /&gt;&lt;BR /&gt;2.&amp;nbsp;&amp;nbsp;&amp;nbsp; MCU will drive the stepper motor according to the input via a driver. The driver needs three input namely STEP, DIRECTION and ENABLE. Motor will step on rising edge of STEP input.&lt;BR /&gt;&lt;BR /&gt;3.&amp;nbsp;&amp;nbsp;&amp;nbsp; Next, incremental encoder will feedback its position to MCU. There will be also a home sensor for&amp;nbsp; homing routine once power is on.&lt;BR /&gt;&lt;BR /&gt;4.&amp;nbsp;&amp;nbsp;&amp;nbsp; When the motor is in desired position, user will purposely turn the motor to cause position error. Then user will press a 'correct button' in GUI to drive the motor back to its actual position.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;So, what are the basic steps to program this microcontroller? What block/module I should study in this MCU? PWM module is requested in driving this motor. Microstep function is already available in the motor driver. That means PWM will be used to control the speed only. Any information about the communication between GUI and MCU?&lt;BR /&gt;&lt;BR /&gt;I cant download the pdf file entitled &lt;SPAN&gt;'Quick Start for Beginners to Drive a Stepper Motor (AN2974)'. Anyone know where to find it?&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Please correct me if I'm wrong because I'm quite new in this application.&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance. Your help is highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;yj&lt;BR /&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Oct 2007 01:31:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151956#M4364</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2007-10-13T01:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151957#M4365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;1. Sorry, but this is the wrong place to ask about a PC based GUI program. Are you sure that this program is not to be provided? If you are not familiar with PC GUI application programing, this task &lt;I&gt;could&lt;/I&gt; be more complex than the mcu part. You need to ask more questions of the instructor concerning this.&lt;BR /&gt;&lt;BR /&gt;2.&amp;nbsp; When you say "driver", do you mean that you have a driver board for the stepper motor that is provided? Thats how it sounds to me. If so, I don't understand why you are also asking about the PWM for the stepper, as this driver board should handle all of that. From what you said about the STEP, DIRECTION and ENABLE inputs, these would be connected to digital outputs.&lt;BR /&gt;&lt;BR /&gt;3. The connection of the encoder was explained - do you have further questions? If so, what did you not understand?&lt;BR /&gt;&lt;BR /&gt;4. Your code will be tracking the encoder, so&amp;nbsp; when the motor is turned the code will "know" how many steps and in what direction to step the motor to put it back in it's correct position. BTW I don't know about the driver board you are using, but be aware that as long as the driver board is enabled, it will attempt to hold the motor in it's current position.&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="-1"&gt;&lt;SPAN class="a"&gt;&lt;FONT size="3"&gt;Here is a link to&lt;/FONT&gt; &lt;A href="http://www.freescale.com/files/microcontrollers/doc/app_note/AN2974.pdf" rel="nofollow" target="_blank"&gt;AN2974.pdf&amp;nbsp;&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&amp;nbsp; However, as you will see it uses a table and no PWM. Also, if you do have a driver board, you will&amp;nbsp; not need to do any of this. Still, it is worth reading..&lt;BR /&gt;&lt;BR /&gt;Do you know the model number of the MC9S12DP256B board you are using?&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by JimDon on &lt;SPAN class="date_text"&gt;2007-10-12&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;11:45 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Oct 2007 10:40:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151957#M4365</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2007-10-13T10:40:53Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151958#M4366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Thanks for your reply.&lt;BR /&gt;&lt;BR /&gt;1.&amp;nbsp;&amp;nbsp;&amp;nbsp; The GUI program will not be provided. I have to develop it myself. The GUI will be developed using C# language. This GUI will be used to control the motor via RS232. Any reference for this part?&lt;BR /&gt;&lt;BR /&gt;2.&amp;nbsp;&amp;nbsp; At the moment, the driver board has been provided. It is 3540M from Applied Motion Products.&lt;BR /&gt;But the driver will be changed due to the changes on the hardware module design.&lt;BR /&gt;&lt;BR /&gt;3.&amp;nbsp;&amp;nbsp; How to drive the motor and keep track with the GUI input while receiving the feedback quadrature encoder signal?&lt;BR /&gt;If the encoder is connected to the interrupt, when the motor is turning, interrupt will keep on occuring. So, the main program will be neglected. (if i am wrong on this, someone please correct me)&lt;BR /&gt;&lt;BR /&gt;4.&amp;nbsp;&amp;nbsp; There will be a button to enable and disable the driver board on the GUI.&lt;BR /&gt;&lt;BR /&gt;The model number of the board is AD9S12DP256M. Is this what you mean, JimDon?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;yj&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by yj on &lt;SPAN class="date_text"&gt;2007-11-03&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:22 AM&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by yj on &lt;SPAN class="date_text"&gt;2007-11-03&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:28 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Nov 2007 16:20:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151958#M4366</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2007-11-03T16:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151959#M4367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;1. RS232 means the serial port on your computer. You will have to write a GUI in C# that open the serial port and send receives data. I recommend you go to code project and look for C# programs that use the serial port. I am a c++ program, so I can't help with c#, but you should be able to find something close at &lt;A href="http://www.codeproject.com/index.asp" rel="nofollow" target="_blank"&gt;code project&lt;/A&gt;.&lt;BR /&gt;&lt;BR /&gt;2. Ok, so you will connect&amp;nbsp; digital outputs to the controller. If it is to be changed, when do they plan to tell what the final unit will be?&lt;BR /&gt;&lt;BR /&gt;3. You are not correct. The interrupts will happen, but will only consume a small amount of time, so the "main" program will keep running.&lt;BR /&gt;&lt;BR /&gt;4. Ok, so the GUI needs at least a button. You will need to create a set of commands for the board and the GUI to communicate. These will be ASCII strings. The board will monitor the serial port as well as the encoder, and will look for commands sent from the PC. As an example, you could decide that when send the string "C1&amp;lt;lf&amp;gt;" (for Command 1) it means enable and when you send "C2&amp;lt;lf&amp;gt;"&amp;nbsp; (&amp;lt;lf&amp;gt; mean "line feed" and is used here to indicated the end of a command lf = 10d ).&lt;BR /&gt;&lt;BR /&gt;Do you Visual Studio Installed ? You should sit down a write up exactly how the gui should look and what functions it need, even if you don't yet know how to do it.. Same for the controller software, write down a list of all the things it needs to do. Make sure you search code project for some samples.&lt;BR /&gt;&lt;BR /&gt;We already know that you will need to use the serial port on the controller, so look here &lt;A href="http://www.mecheng.adelaide.edu.au/robotics/wpage.php?wpage_id=56" rel="nofollow" target="_blank"&gt;Sample Programs&lt;/A&gt;.&lt;BR /&gt;Scroll down for a list of sample programs.&lt;BR /&gt;&lt;BR /&gt;AD9S12DP256M - Made by &lt;FONT size="-1"&gt;&lt;SPAN class="a"&gt;technologicalarts ? If you have not yet done so go to their web site and download all the manuals and read them through.&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;A little up front thought and planning wil go a long way.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by JimDon on &lt;SPAN class="date_text"&gt;2007-11-04&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;08:27 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Nov 2007 21:24:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151959#M4367</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2007-11-04T21:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151960#M4368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;In my system, the board will have to monitor the serial port and keep track the feedback encoder and at the same time produce step pulses to drive the motor driver. So program plan is as follows:&lt;BR /&gt;1.&amp;nbsp; Main program will keep track on the serial port and calculation will be conducted to calculate the number of step to drive the driver and the frequency as well. The number of step and frequency will be used in ECT module.&lt;BR /&gt;2.&amp;nbsp; At the same time, output compare and input capture will be used to drive the driver and count the feedback encoder respectively.&lt;BR /&gt;&lt;BR /&gt;So, is it possible to use PWM module to produce the step pulses rather than Output Compare module in my case?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Below is the simple code to on and off LED on the board (PTP7) and external LED using PTT7/IOC7 every 0.5second. Just want to know whether my understanding on programming the interrupt module correct or not. I haven try this code because I think I left something else. Is my code complete?&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#include &amp;lt;mc9s12dp256.h&amp;gt;

void TOC7_Init(void)
{  asm sei

    TIOS=0x80;    // IOS7 = 1, channel 7 is output compare
    TCTL1=0x40;   // OM7 = 0, OL7 = 1, Toggle output on PTT7/IOC7
    TSCR2=0x0F;   // TCRE = 1, counter reset enable
    // Prescaler = 128 (Timer clock freq = 25MHz/128 = 195.31kHz)

    TC7=48828;    // LED on/off duration = 48828/195.31kHz = 0.25s
    TIE=0x80;     // Timer interrupt enable, C7I=1
    TSCR1=0x80;   // Timer enable, TEN=1
   
    asm cli;
}

void main()
{
    TOC7_Init();

    DDRP=0xFF;    // Port P as output
    PTP=0x00;     // Initialize LED off
}

// definition
#pragma interrupt_handler TOC7_ISR(); 
void TOC7_ISR(void)
{
    PTP ^= 0x80;  // Toggle output bit (PTP7)
    TFLG1=0x80;   // Clear C7F
}

// interrupt vector declaration
extern void TOC7_ISR();
#pragma abs_address:0xffee;
void (* TOC7_handler[])() = { TOC7_ISR };
#pragma end_abs_address
&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;I need your help on this:&lt;BR /&gt;1.&amp;nbsp; Is the definition and vector declaration of the TOC7_ISR correct ?&amp;nbsp; Should I include vectors.c file?&lt;BR /&gt;2.&amp;nbsp; "#pragma abs_address:0xffee"&amp;nbsp; Where is the 'ffee' address based on? As I know, the vector address for ECT channel 7 in the datasheet is ffe0.&lt;BR /&gt;3.&amp;nbsp; How to set the bus clock to the ECT module ? In this example, I assume it to be 25MHz.&lt;BR /&gt;4.&amp;nbsp; What is 'asm sei' and 'asm cli' ?&lt;BR /&gt;5.&amp;nbsp; Will the PTT7/IOC7 output toggle automatically when interrupt occur?&lt;BR /&gt;&lt;BR /&gt;Your help is highly appreciated.&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;best regards,&lt;BR /&gt;yj&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN class="time_text"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151960#M4368</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2020-10-29T08:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151961#M4369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BR /&gt;I set bit 4 of the TSCR1 register to allow fast clearing.&lt;BR /&gt;In the interrupt handler you should:&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;
In the initcode:
 TSCR1 = 0x90;               // Enable TCNT and fast clear

In the interrupt handler:

// Clear the interrupt no need to write to TFLG
// This should be the only line of code in the hander.
// The channel should toggle on its own.
TC7 += 48828;&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;The way you did it may work, I just always do it this way.&lt;BR /&gt;&lt;BR /&gt;You have set to channel to toggle - so why are you toggling it in the interrupt handler?&lt;BR /&gt;It will toggle on it's own.&lt;BR /&gt;&lt;BR /&gt;There are may ways to create the vector table, no sure if yours will work but this is how I do it.&lt;BR /&gt;Note also the use the the key words rather than pragmas.&lt;BR /&gt;&lt;BR /&gt;Modify the table for you purposes. You can drop it in at the bottom of main.&lt;BR /&gt;This makes it much easier to keep track of the vector.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;__interrupt void NullHandler(void)
{
 
}
typedef void near (* near tIsrFunc)(void);
const tIsrFunc _vectab[] @0xFFE0 =
{ 
  (tIsrFunc)Timer7Interrupt,                          /* Timer 7 0xFFE0                */
  (tIsrFunc)Timer6Interrupt,                          /* Timer 6 0xFFE2                */
  (tIsrFunc)Timer5Interrupt,                          /* Timer 5 0xFFE4                */
  (tIsrFunc)Timer4Interrupt,                          /* Timer 4 0xFFE6                */
  (tIsrFunc)Timer3Interrupt,                          /* Timer 3 0xFFE8                */
  (tIsrFunc)NullHandler,                              /* Timer 2 0xFFEA                */
  (tIsrFunc)NullHandler,                              /* Timer 1 0xFFEC                */
  (tIsrFunc)NullHandler,                              /* Timer 0 0xFFEE                */
  (tIsrFunc)RealTimeInterrupt,                        /* RTI 0xFFF0                    */
};
&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;As you can see 0xFFE0 is the correct place for the Timer 7 interrupt.&lt;BR /&gt;On page 77 of 9S12DP256BDGV2.pdf you will see the vector allocations.&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151961#M4369</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2020-10-29T08:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151962#M4370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Thanks for your reply, Jim D.&lt;BR /&gt;&lt;BR /&gt;1.&amp;nbsp;&amp;nbsp;&amp;nbsp; I have enabled the counter reset, TCRE=1. So I don't have to add&amp;nbsp; "TC7 += 48828" in my ISR because the counter will reset once it match TC7=48828 and ISR will be serviced. Then it will count again to cause the next interrupt. ( Please correct me if I'm wrong )&lt;B&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/B&gt;2.&amp;nbsp;&amp;nbsp; I'm toggling Port P (PTP7) not the timer port (PTT7 / IOC7). This is because I want to try both cases on two LEDs. ( toggling Port P bit 7 in ISR and toggling IOC7 automatically )&lt;BR /&gt;&lt;BR /&gt;3.&amp;nbsp;&amp;nbsp; How to set the bus clock to the ECT module ? In this example, I assume it to be 25MHz.&lt;BR /&gt;&lt;BR /&gt;4.&amp;nbsp;&amp;nbsp; How about the 'asm sei' and 'asm cli' ? I not really understand these terms.&lt;BR /&gt;&lt;BR /&gt;5.&amp;nbsp;&amp;nbsp; Just drop the code you gave me at the bottom of the main?&lt;BR /&gt;I'm still confuse on the ways to manage the vector table. Is it depends on the compiler used in organising the vector table or I have to do it in my program?&lt;BR /&gt;&lt;BR /&gt;Thanks again. I really appreciate your help.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Best Regards,&lt;BR /&gt;yj&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 03 Dec 2007 09:49:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151962#M4370</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2007-12-03T09:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151963#M4371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Ok, what your are doing with TCRE should work, I have just never tried that way.&lt;BR /&gt;&lt;BR /&gt;asm cli&amp;nbsp; inserts the assembly language instruction that enables interrupts for the CPU, by clearing the bit (0 means enabled). sei disable interrupts.&amp;nbsp; Unless you enable the CPU interrupts, NO interrupts will occur.&lt;BR /&gt;&lt;BR /&gt;As for the vector table, delete or set to NullHandler the ones you will not be using. I find it handy to leave unused ones in so I do not have to go look them up when I need them.&lt;BR /&gt;&lt;BR /&gt;Yes, you just paste the table into your code.&lt;BR /&gt;&lt;BR /&gt;The bus clock will not be 25MHz unless you set up the PLL. The way you set the PLL depends on the oscillator that is&amp;nbsp; on the board.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void PLL_Init(byte speed){    // PLLCLK = 2 * OSCCLK * (SYNR + 1) / (REFDV + 1)  // We want OSCCLK *  (SYNR + 1) / (REFDV + 1) to be 24  if( 16 == speed )  {      SYNR  = 0x02;       // 16/(1+1) * (2+1) = 24         REFDV = 0x01;  } else if( 8 == speed )  {      SYNR  = 0x02;       // 8/(0+1) * (2+1) = 24      REFDV = 0x00;  } else if( 4 == speed )  {      SYNR  = 0x05;       // 4/(0+1) * (5+1) = 24       REFDV = 0x00;  }   else     return;   CLKSEL = 0x00;  PLLCTL = 0xD1;  // Turn on PLL Clk   while((CRGFLG&amp;amp;0x08) == 0)    // Wait for PLLCLK to stabilize.        ;          CLKSEL_PLLSEL = 1;  // Switch to PLL clock}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&amp;nbsp;This example shows to get a bus clock of 24MHz from a 4,8 or 16Mhz clock. If yours is not one of those,&lt;BR /&gt;you can figure out how to set the registers. You may have to change around the ECT counter settings to get the exact period you want.&lt;BR /&gt;If you have an oscilloscope in the lab, try a counter setting that gives a 1ms period and look at it on the scope (it is hard to see a 1 second pulse on the scope).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151963#M4371</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2020-10-29T08:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151964#M4372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Thanks for your help. I have insert the interrupt table code you gave to me but when I compile, there is error.&lt;BR /&gt;So, I have program my board according to Tutorial on MC9S12DP256 Flash Programming. I will use bus clock = 16MHz to on and off LED every 0.5 seconds. The problem now is the interrupt is not working. (LED didn't blink) I just wonder which part of my code wrong. I'm using 16MHz, so should I intialize anything on this in my code (PLL)? The board has 16MHz crystal.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#include &amp;lt;mc9s12dp256.h&amp;gt;#include "vectors_dp256.c"  void TOC7_Init(void);void TOC7_Init(void){  asm(" sei");    TIOS=0x80;    // IOS7 = 1, channel 7 is output compare    TCTL1=0x00;   // OM7 = 0, OL7 = 1, Toggle output on PTT7/IOC7    TSCR2=0x07;   // TCRE = 0, counter reset disable    // Prescaler = 128 (Timer clock freq = 16MHz/128 = 125kHz)    TC7=62500;    // LED on/off duration = 62500/125kHz = 0.5s    TIE=0x80;     // Timer interrupt enable, C7I=1    TSCR1=0x90;   // Timer enable TEN=1, fast flag clear TFFCA=1        asm(" cli");}void main(){    TOC7_Init();    DDRP=0xFF;    // Port P as output    PTP=0x00;     // Initialize LED off    while(1);}void TOC7_ISR(void){    PTP ^= 0x80;  // Toggle output bit (PTP7)    TC7 += 62500;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;yj&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by yj on &lt;SPAN class="date_text"&gt;2007-12-08&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;06:09 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151964#M4372</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2020-10-29T08:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151965#M4373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Well for on thing you need to declare the handler as:&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;__interrupt void TOC7_ISR(void){    PTP ^= 0x80;  // Toggle output bit (PTP7)    TC7 += 62500;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;Also, you should be able to test this in the simulator, at least as far as the interrupt handler is concerned - that is you should be able to break point in your interrupt handler in the simulator.&lt;BR /&gt;&lt;BR /&gt;If you ocilliator is 16Mhz, and&amp;nbsp; you want a 16 MHz bus clock you would need to x2 the clock to 32Mhz.&lt;BR /&gt;Or you could just us the PLL code I show, pass in 16 and run at 24Mhz.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151965#M4373</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2020-10-29T08:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151966#M4374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;1.&amp;nbsp;&amp;nbsp;&amp;nbsp; If the crystal freq is 16MHz and I don't use PLL code, then my default bus clock into ECT module is equal to 8Mhz.&lt;BR /&gt;Am I correct?&lt;BR /&gt;&lt;BR /&gt;2.&amp;nbsp;&amp;nbsp;&amp;nbsp; The previous code for interrupt succeeded. The LED blink according to the duration I want.&lt;BR /&gt;&lt;BR /&gt;3.&amp;nbsp;&amp;nbsp;&amp;nbsp; If I want to execute the ISR routine for a specific amount, let say I want to produce 2 step pulses (LED will blink 2 times), then the ISR routine must be executed 4 times. After 4 times the routine being serviced, I disable the timer interrupt. Below is the simple code for this case. This will be used in my system when I want to drive the stepper motor to a desired position, then I will service this routine for the desired amount. (Please correct me if I wrong)&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;int i=1;void TOC7_ISR(void){         PTP ^= 0x80;     if (i&amp;lt;4)       i++;    else    {       TIE=0x00;     // Timer interrupt disable, C7I=0       TSCR1=0x10;   // Timer disable TEN=0, fast flag clear TFFCA=1     }}    &lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;But the LED blink continuously and didn't stop. Am I miss something in disabling the interrupt?&lt;BR /&gt;Hope you can help me on this.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;yj&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by yj on &lt;SPAN class="date_text"&gt;2007-12-09&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;06:29 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151966#M4374</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2020-10-29T08:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151967#M4375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I have try many simple codes in the interrupt routine.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;BR /&gt;&lt;/DIV&gt;&lt;PRE&gt;int k;

void main()
{
  k=1;
  .... initialize the interrupt
  while(1)
  {
    }
}

void TOC7_ISR(void){         k=k+1;       if (k==4)        { PTP ^= 0x80;          PTS ^= 0x80;          blink_delay();          PTS ^= 0x80;          TFLG1 = 0x80;        }       else       {           TFLG1 = 0x80;            }}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;The &lt;B&gt;if&lt;/B&gt; part not evaluated as true. It seems like any variable not increasing in the routine. This happens in previous code as well. I really don't understand what happen. I need your help.&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;yj&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151967#M4375</guid>
      <dc:creator>admin</dc:creator>
      <dc:date>2020-10-29T08:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Freescale MC9S12DP256B - Closed-loop Stepper Motor Control System Using MC9S12DP256B</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151968#M4376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Questions:&lt;BR /&gt;&lt;BR /&gt;How do you declare TOC7_ISR as being an interrupt handler? You should really use the __interrupt keyword on the function, otherwise it is hard for someone reading your code to know that.&lt;BR /&gt;&lt;BR /&gt;&lt;B&gt;How are you debugging this ? Do you have a BDM? What make you think that the variable is not working?&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt;Because variables in a proper interrupt handler work fine. Your code does not look wrong as far as the variable is concerned.&lt;BR /&gt;&lt;DIV&gt;&lt;BR /&gt;Please post the init code too. At one point you seemed to follow my advice using the fast clear mode and TC7 += 62500; but now you stopped using that so I can't say if the interrupt is running correctly or not.&lt;BR /&gt;(BTW TFLG1 = 0x80 should work, I just have never done it that way)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;
&lt;/PRE&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;PRE&gt;
&lt;/PRE&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by JimDon on &lt;SPAN class="date_text"&gt;2007-12-10&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;01:32 PM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 08:55:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Freescale-MC9S12DP256B-Closed-loop-Stepper-Motor-Control-System/m-p/151968#M4376</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2020-10-29T08:55:39Z</dc:date>
    </item>
  </channel>
</rss>

