Temporary stepper motor control

I have a question regarding stepper motor control when using the Microchip TCP / IP stack.

In the past, I used a timer to control a stepper motor. I set the timer period to the required time between pulses, and then change the motor phase outputs as necessary in the ISR tick timer. In cases where I did this, my pedometer moved at a maximum speed of about 400 pulses per second, which means that the interrupt occurred every 2.5 milliseconds. And I used USB to communicate with the host.

Now I am working on a new product that will use the TCP / IP stack to communicate with a PC via Ethernet. It will also communicate with other devices through SPI and UART modules. This new device should be able to work with a pedometer up to 2000 pulses per second, which means that the interrupt can be triggered every 0.5 ms if I use the same timer / ISR approach to control the step amplifier. The pedometer turns on and off based on the commands received from the host, so communication with the host and engine operation should occur harmoniously and simultaneously. If the step speed changes somewhat, that will not be a problem, but this is not ideal. In addition, if the pedometer was supposed to stop, say, 30 ms in the middle of its movement, which MUST NOT be acceptable.

I am considering using a 16 MHz PIC24F (32 MHz / 2 using internal FRC + PLL) for this project. Do you think interrupts for a stepper device interrupt Ethernet communications, or vice versa? Is there a better way to do this?

I considered using a separate PIC for step-by-step control, and then I could send pic target position commands or stop commands to start and stop moving, but this would add another firmware to the mix and complicate everything around.

+4
source share
3 answers

It depends on the hardware, and the best answer is to give it a chance and try it.

Your other options are to either use a separate PIC to control the stepping mechanism, as you mentioned, use pseudo-threading (a custom thread, but usually not available in most compilers for the PIC platform).

But perhaps what works best for you is that the main loop of your software controls the stepper motor (for ... moving, sleeping, continuing), and then use interrupts to process the TCP / IP requests that come in which You will change the status registers / variables.

Using interrupts is a good idea, but when you have something so high priority, polls and loops are the best options. In order for everything to go smoothly, you must be able to ensure that your TCP / IP interrupts do not exceed xxx cycles (or milliseconds, the same on the PIC, really), or add step control code to the TCP / IP interrupt.

Now none of this is required if your PIC has interrupt priorities. In this case, just place the stepper device interrupt with a higher priority than the TCP interrupt, and you will be good to go. However, I do not think PIC has user functions, but I could be wrong. It might also be a good idea to switch to another platform that supports priority interrupts because it will make much cleaner code and simplify your life in general.

+1
source

I had the same problem as controlling the time of a microcontroller processor between controlling stepper motors and receiving data from a PC and sensors, but I decided to divide the control program (pulses) into parts for every 1 Kbyte and send them to the microcontroller’s memory, then I was able to free up processor time.

+1
source

Is a host required to start and stop a step at the .5 ms border? I don’t have any numbers to support this, but I feel that the variable latency of the Ethernet line may dominate your response to commands, especially if there are other devices on the same network.

0
source

Source: https://habr.com/ru/post/1334668/


All Articles