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!!