Controlling two square wave frequencies over serial connection

All,
I have a question regarding the arduino a ability to manipulate it's clocks.

My project is a joystick controlled pan/tilt head for a live video setup. I currently have one arduino in a control booth that reads a Hall effect joystick, and transmits the values over about 100ft of Cat5e to a second arduino. This arduino is connected to two big easy stepper drivers, and controls the speed and direction of two nema17 steppers based in the received value from the joystick arduino. My current program uses the millis() function to toggle the step/direction pins high and low when needed to move each of the steppers. Specifically, it changes the delay between pin toggles for the steps to control speed.

Since I am using the steppers open ended (I don't care about positional accuracy) I am considering moving to a 256 micro step driver to smooth out the steppers motion. The problem is that the maximum speed I can achieve is limited by the program and the arduino a ability to toggle the step pin. The 256 micro step driver will accept up to a 300khz step signal.

My plan is to use low level code to toggle the step pins using the compare option on the clocks in the back ground, and use the joystick to modulate the frequency, which frees up my program to only control the steps and the driver and not generate the steps themselves.

My questions are as follows

  1. the timer 1 clock pre-scaler can be changed on the fly, and there are two pins available to use this clock. I cannot have two different frequencies on those pins correct, so I would need to use two different clocks in the option compare mode to generate my step signals right?

  2. clock 1 is 16bit while 2 and 3 are 8, would it be better to use clocks 2 and 3, or take advantage of the increased resolution on one of the steppers? Is there that much difference?

  3. using this method, will there be a large delay or gap in "toggles" of the step pin when the arduino changes the registry settings for the pre-scalers etc?

Sorry if this is confusing. This is my firs need to delve into the low level code of the arduino, and I am beginning to question whether this project exceeds the capabilities of the arduino (or the knucklehead programming it)

I will gladly clear up any confusion if anyone has questions about the set up. I will post a schematic and code if it is needed.

Thanks - Wes

Since I am using the steppers open ended (I don't care about positional accuracy) I am considering moving to a 256 micro step driver to smooth out the steppers motion. The problem is that the maximum speed I can achieve is limited by the program and the arduino a ability to toggle the step pin. The 256 micro step driver will accept up to a 300khz step signal.

If positional accuracy is not important then might it be better to use a geared DC motor like this instead so the movement is smooth at varying speeds.

Your not limited to using just the two OCx pins with timer 1 as you could use the compare and/or overflow interrupt hooks to change several pins at a time. You could also set the timer base frequency higher than you need and then divide it down for the various stepper speeds you need. Eg: run the timer at 2MHz but only trigger a clock edge every 10 ticks of timer 1 for one pin and every 20 ticks for another pin and so on.

I originally used DC motors for the purpose you describe. The problem I ran into was getting very fine control at very very low speed, but also being able to move quickly when needed. The typical zoom range on the camera that is mounted is a full frame upper body shot of a person from 45 feet, so a 1 degree rotation of the pan mount is a considerable distance frame wise, and so considerable gearing etc is needed to provide movement fine enough to achieve this. (Think 1/10th of 1 rpm) Gearing proved to be a nightmare as absolutely any backlash was painfully obvious on a sudden direction change. On the opposite end of the spectrum I need to move the camera quite quickly to change focus to a different subject at a different focal point.

Steppers allow me to achieve both the high speed readjust, and have the low speed fidelity required, but are inherently more difficult to control.

On the OCx, what kind of counter would you use? A coded i++ variable? Most of the high speed square wave threads I have read seem to suggest toggling at overflow or the compare point and modulating the clock speed was the preferred method. Again - don't know a whole lot about the low level programming so I am totally open to suggestions.

If using a counter in the program, what is the maximum variable size? At 2mhz it could get pretty big pretty quick...

I think for this to be successful you need to become familiar with the Timer features in the Atmel datasheet.

What Arduino are you using ?

IIRC there is one counter speed for all of Timer1 but you can set different thresholds for the two different outputs.

If you need a wide range of timing you may need to change the counter speed and that may limit the independence of the two motors. For that reason it may be better to use 2 separate 8-bit timers.

I suspect there will be a negligible delay when a new value is applied to the Timer - it only involves writing a value to a register. However you may be at risk of getting one interval of an odd duration - either shorter or longer. I don't know whether that would be noticeable in practice - you may need to experiment to find out.

Have you access to an oscilloscope to help with debugging ?

...R

Honel:
If using a counter in the program, what is the maximum variable size? At 2mhz it could get pretty big pretty quick...

Thinking about it, probably 2MHz is a bit extreme but the next pre-scaler down is /64 so your then down to 250KHz.
As for counter size, the uint32_t variable size allows a value between 0 and 4,294,967,296 and the Arduino can also handle the uint64_t and that should last you a lifetime :wink: