Driving three steppers

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Driving three steppers

1,249 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ycroosh on Sat Nov 12 22:31:16 MST 2011
Hello,
I need some help with my new hobby project.
I am trying to make a CNC machine controller using LPC1769 (LpcXpresso). The PC will send g-code commands (one at a time) and the MCU will covert the code into stepper motor pulses. Well, my problem is that this would be myg first ARM project (I've been using MSP430 and .NETMF untill now)...
Basically, on a conceptual level I need to have three different pulse outputs (at different frequencies). I also need to count the pulses (i.e. to have exactly [I]n [/I]pulses).
The motors will have ~64000 steps per inch (three axes), so the frequency will need to be in 100+ KHz range...
Since the MCU will be driving a cutter, the timing is the most important thing, so I'd like the pulses to be generated and counted by the hardware, not inside an interrupt, if possible.
I would really apprecite if someone could point me into the right directions (and some examle code)

Thank you
Yuriy
0 项奖励
回复
8 回复数

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Nov 16 16:36:52 MST 2011

Quote: Zero
I'm pretty sure I can do it :rolleyes: And even worse, I've done it :eek:

See: http://knowledgebase.nxp.com/showthread.php?t=787



What I was thinking about when I answered this post was a way of achieving that goal without using either polling or interrupts. Some 8 bits microcontrollers have that ability.

If the frecuency is to high, and the LPC microcontroller has other things to do, or it's running a RTOS, it may loose some interrupts, or it can miss others sources of interrupt, or it will schedule (or preempt) too fast. None of them are good :p
0 项奖励
回复

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Nov 16 16:24:16 MST 2011

Quote: ycroosh
fjrg76,
This is exactly what I was looking for. Thank you

Yuriy



You're welcome !!
0 项奖励
回复

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ycroosh on Wed Nov 16 16:18:51 MST 2011
fjrg76,
This is exactly what I was looking for. Thank you

Yuriy
0 项奖励
回复

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Tue Nov 15 23:40:50 MST 2011

Quote: ycroosh

In my case I will be receiving commands over UART, adding them to the queue and the motion controller will execute one at a time, so there will be one UART interrupt, three timer interrupts for the motors and one interrupt for the scheduler...

Thank you
Yuriy



Look at this AN:

AN10915

You may also find this article interesting enough (although for Cortex-M0):

http://www.eetimes.com/design/embedded/4230085/The-basics-of-low-power-programming-on-the-Cortex-M0
0 项奖励
回复

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ycroosh on Tue Nov 15 23:05:29 MST 2011
First of all, thank you for the help.

So, I ended up setting timers 1,2, and 3 for axes X,  Y and Z.
I count the pulses inside the interrupt routine for each timer (reset and interrupt on match...) Timer 0 will be used for the main "scheduler" (if there is one)

Now I have a bit different question:

I have a variable "x_ready" that is set to 0 in the "start" functoin and to 1 in the "stop" function. The only minor problem is that stop is called fom the ISR, so it can fire outside of the main's context, so I'm wondering if there is a way to implement some sort of "mutex" that would make it "thread safe"

And, actually, one more question... In the examples I've seen online most people run an infinite loop in the "main". On MSP430 I would normally set up the interrupts and go to "sleep" so the MCU is in low power mode and is awaken on interrupts. Is that an acceptable practice with LPC1769, or is there a better way? If yes, could you point me to some resources.

In my case I will be receiving commands over UART, adding them to the queue and the motion controller will execute one at a time, so there will be one UART interrupt, three timer interrupts for the motors and one interrupt for the scheduler...

Thank you
Yuriy
0 项奖励
回复

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Nov 14 18:38:18 MST 2011

Quote:
I'm pretty shure you cannot generate PWM pulses and count them at the  same time using the same Timer, but if I'm wrong please let me know it.

I'm pretty sure I can do it :rolleyes: And even worse, I've done it :eek:

See: http://knowledgebase.nxp.com/showthread.php?t=787
0 项奖励
回复

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Mon Nov 14 18:08:53 MST 2011

Quote: ycroosh
Hello,
I need some help with my new hobby project.
I am trying to make a CNC machine controller using LPC1769 (LpcXpresso). The PC will send g-code commands (one at a time) and the MCU will covert the code into stepper motor pulses. Well, my problem is that this would be myg first ARM project (I've been using MSP430 and .NETMF untill now)...
Basically, on a conceptual level I need to have three different pulse outputs (at different frequencies). I also need to count the pulses (i.e. to have exactly [I]n [/I]pulses).
The motors will have ~64000 steps per inch (three axes), so the frequency will need to be in 100+ KHz range...
Since the MCU will be driving a cutter, the timing is the most important thing, so I'd like the pulses to be generated and counted by the hardware, not inside an interrupt, if possible.
I would really apprecite if someone could point me into the right directions (and some examle code)

Thank you
Yuriy




Hello

You can easily implement PWM for pulses using the timers. For PWM generation you have two choices:

1) Reset on match and toggle the output pin, or
2) Native PWM timer function (this is intended mainly for a motor controller purposes).

I think you won't have problems with the frecuency. The main concern is about counting pulses. You may follow this approach:

Take the Timer0 for PWM generation (output), and take the Timer1 (input) for counting. For this, you should configure Timer1 for counting external events (this mode is called CAP, and you can eventually generate an interrupt every time the CAP pin reaches its maximum count), and then externally wire PWM outputs with CAP inputs. Be aware that the timer can also measure the elapsed time between events, but that is not what you want. It's worth to mention that Timers have more than seven modes of operation!!

I'm pretty shure you cannot generate PWM pulses and count them at the same time using the same Timer, but if I'm wrong please let me know it.

Good lock!!
0 项奖励
回复

1,117 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Sun Nov 13 11:46:27 MST 2011
Hello,
I've an hobby project that is quite the same as yours. I'm building a  laser cutter (almost done) and I've decided to take the LPCXpresso  (1769) to drive it. I've only two stepping motors to drive but I want  the 1769 to be able to drive 3 steppers for future extension.
In fact, for driving a stepper, it's simple: one directional bit (DIR)  and one pulse bit (PULSE). You need the LPC17XX user manual and the  LPC1769 datasheet. Then you need to learn how the timers are working and  how to program them (that's just what I'm doing now). Since the 1769  has 4 timers with a lot of capabilities, you can drive 4 steppers. The  challenge is the timing. Concerning the resolution, since the CPU can  run @ 100MHz and the timer can have the same clock frequency than the  CPU, I think that there is no problem. For my project, a maximum speed  of 10khz is enought. To generate 10khz pulses, one has to program the timer accordingly.
That's what I'm doing now.
Olivier
0 项奖励
回复