Closed-loop stepper motor using Adapt9S12DP256

General problems? Ask here!

Moderator: cbarnes

Closed-loop stepper motor using Adapt9S12DP256

Postby yj » Wed Nov 14, 2007 11:43 am

Hi,

How to use this development board in order to develop the closed-loop stepper motor control system? What are the module/block I should use in this board? Any sample code for this case as a reference?

Basically, my system is like this:
1. 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. Any reference for
this part?

2. MCU will drive the stepper motor according to the GUI input via
a motor driver board (3540M from Applied Motion Products). The driver
needs three input namely STEP, DIRECTION and ENABLE. Motor will step
on rising edge of STEP input.

3. Next, incremental encoder will feedback its position to MCU.
There will be also a home sensor for homing routine once power is on.

4. 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. There
will be a button to enable and disable the driver board on the GUI.

Any help is highly appreciated.

Best Regards,
yj
yj
Newbie
Newbie
 
Posts: 6
Joined: Wed Nov 14, 2007 11:18 am

Postby cbarnes » Fri Nov 16, 2007 10:24 pm

for the first requirement, have a look at the demo program that comes with this board. the user interface is done via the rs232 interface on the board by using a terminal program on your PC. after you get the basics working, you can create a simple GUI with VB.NET or C# to use instead

the second part is really easy-- just pick some port lines to use as outputs to control the driver board, and write code to activate them when needed. you could use an Output Compare pin to generate a Step pulse train, if desired.

same with the third one, only for the encoder input you'll probably want to use the Input Captures to make counting easier

hope that helps get you going...
cbarnes
Admin
Admin
 
Posts: 79
Joined: Mon Jul 26, 2004 10:28 pm
Location: Toronto

Postby yj » Sat Nov 17, 2007 9:41 am

Hi,

Thanks for your reply.

Can I know where I can get the demo program for the rs232 interface?

Best Regards,
yj
yj
Newbie
Newbie
 
Posts: 6
Joined: Wed Nov 14, 2007 11:18 am

Postby yj » Sun Nov 18, 2007 6:17 am

Hi,

Can I know where I can get the detail information on the basic steps
to write program for the interrupt in C? Any sample code as a reference?

What are the specific registers that needed in this Enhanced Capture Timer module?

Any help is highly appreciated.

Best Regards,
yj
yj
Newbie
Newbie
 
Posts: 6
Joined: Wed Nov 14, 2007 11:18 am

Postby cbarnes » Sun Nov 18, 2007 11:05 pm

Start here: http://support.technologicalarts.ca/docs/Adapt9S12DP/

Also, follow the links provided on the Resources tab on this product's webpage:
http://www.technologicalarts.ca/catalog ... cts_id=123
cbarnes
Admin
Admin
 
Posts: 79
Joined: Mon Jul 26, 2004 10:28 pm
Location: Toronto

Postby cbarnes » Tue Nov 20, 2007 12:41 pm

Here's a good place to start for the stepper motor portion of your project:
http://www.freescale.com/files/microcon ... AN2974.pdf
http://www.freescale.com/files/microcon ... AN2612.pdf
cbarnes
Admin
Admin
 
Posts: 79
Joined: Mon Jul 26, 2004 10:28 pm
Location: Toronto

Postby yj » Sun Dec 02, 2007 2:50 am

Hi,

Thanks for the information.

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.

My program plan is as follows:
1. 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.
2. At the same time, output compare and input capture will be used to drive the driver and count the feedback encoder respectively.

So, is it possible to use PWM module to produce the step pulses rather than Output Compare module in my case?



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 correct?

Code: Select all
code:

#include <mc9s12dp256.h>

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
}

#pragma interrupt_handler TOC7_ISR()
void TOC7_ISR(void)
{
    PTP ^= 0x80;    // Toggle output bit (PTP7)
    TFLG1=0x80;   // Clear C7F
}



I need your help on this:
1. How to define the ISR interrupt vector ?
2. How to set the bus clock to the ECT module ? In this example, I assume it to be 25MHz.
3. What is 'asm sei' and 'asm cli' ?
4. Will the PTT7/IOC7 output toggle automatically when interrupt occur?

Your help is highly appreciated.
yj
Newbie
Newbie
 
Posts: 6
Joined: Wed Nov 14, 2007 11:18 am

Postby yj » Sun Dec 09, 2007 1:37 am

Hi,

I have succeeded to use Output Compare module. The LED blink according to the duration I want.

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)


Code: Select all
int i=1;

void TOC7_ISR(void)
{   
   PTP ^= 0x80; 

   if (i<4)

      i++;

   else
   {
      TIE=0x00;        // Timer interrupt disable, C7I=0
          TSCR1=0x10;    // Timer disable TEN=0, fast flag clear TFFCA=1
    }
}     


But the LED blink continuously and didn't stop. Am I miss something in disabling the interrupt?
Hope you can help me on this.

Thank you.

Best Regards,
yj
yj
Newbie
Newbie
 
Posts: 6
Joined: Wed Nov 14, 2007 11:18 am

Postby yj » Wed Dec 12, 2007 8:40 pm

Hi,

I just want to know whether this Adapt9S12DP256M board produce 5V TTL or CMOS logic signal at the digital I/O port? I cant get any information on this. Hope you can help.

Thanks.

Best Regards,
yj
yj
Newbie
Newbie
 
Posts: 6
Joined: Wed Nov 14, 2007 11:18 am

Postby ed taylor » Mon Dec 17, 2007 9:01 pm

hi vj:

this series of processor (assuming a 5v supply) will have logic level outputs of 5v or 0v and can sink or source about 25ma per pin. be careful not to exceed the total supply current as outlined in the electrical specifications.


ed
ed taylor
Master
Master
 
Posts: 174
Joined: Wed Jan 19, 2005 10:20 pm
Location: calgary alberta


Return to General Problems

Who is online

Users browsing this forum: No registered users and 2 guests

cron