2018-09-05 12:05 PM
Hi!
I'am new to STM's so I thought I will learn them by making the project. I want to control a CNC machine. I started to control stepper motor via TB6600. The problem I cannot solve is setting very accurate frequency for the PWM. For example:
I have 16 microstepping and a ball screw (1 turn is 5mm move). That gives me the resolution about 1/640mm per step(640 pulses per mm). Without microstep it's 1/40mm per step.
With 1/16 microstepping I need to give 3200 steps to make 1 turn (5mm move). So.
When I want to set feed rate to (for example) 1217mm/min I need to set frequency at 12981.33333Hz.
frequency = (feed/5)*3200/60
How can I set that accurate frequency on stm32F429 disco?
What am I missing couse I fell that's not how I can control this? :D
Greetings
2018-09-05 02:54 PM
The F429 runs at 168MHz? or is it 180MHz?? I'm too lazy to look it up. Even if your timer runs at Clk/2 (I'll pick 84MHz for now), 84MHz / 12981.3333 = a divisor of 6470 (rounded up then subtract one). This gives you an actual frequency of 12980.992, which is an error of around 0.003% - pretty darn close if you ask me. Now at some slower step rate you will need to set the prescaler to something other than 0 (i.e. divide-by-1) to keep from overflowing the 16-bit counter registers (if you are using a 16-bit timer).
What some CNC controllers do is keep track of the hypothetical/ideal number of step pulses and the actual number of step pulses generated and periodically correct the pulse rate so it averages out over time.
If you are familiar with Mach4 (a CNC control program), it talks to a number of motion controller boards. One of which is the PMDX SmartBOB series, which use an STM32F4xx series CPU. Mach4 tells the motion devices the step pulse rates for each motor, and updates the step pulse rate typically every millisecond.
2018-09-05 05:21 PM
you would set the timer overflow interrupt,
carefully calculated to fit inside a 16bit timer. thanks @Bob S
in that interrupt you would look at the state you have
and the state you want
for M1,M2,M3,Direction Clk reset etc.
no printing in the interrupt.