Dear Forum, I am trying to mimic an optical rotary encoder with two digital outputs from an Arduino Uno. The mechanical encoder has two outputs (ChA and ChB) which produce 5V pulses (50% duty cycle) at a frequency related to the speed of the encoder. I haven't measured the output frequency accurately but the two channels can operate at over 1KHz, probably much higher. The direction of the encoder appears to be coded by which channel (A or B) goes high first. So, to mimic this behaviour, I need to stagger the two digital outputs by roughly 500 us or even less.
I can get this working to some degree by simply setting a pair of output pins on an arduino high for a period and then low with a delay to stagger the two outputs. This is fine for relatively slow speeds but to get the motor running at a fast speed, I need to send pulses faster than the arduino can manage with millisecond delays. If I reduce the stagger delay between the pulses too low, then the motor stops turning smoothly; presumably this is because of interrupts interrupting the output.
I have tried using PWM outputs instead since I believe these will remain at a given frequency regardless of interrupts. I have managed to change the frequency of the output to get it running at more than 1KHz. However, to get this to work, I need a delay between the PWM signals. So far I have just tried outputs from the same timer (timer 0; pins 5 and 6); A quick look with an oscilloscope (while at work a couple of days ago) made me think that the two PWM signals were precisely in phase even though there was a delay before starting them.
Is this expected? I guess it could be because the PWM signals are from the same timer. Do you think it is possible to get PWM signals out of phase from the same timer, or from outputs controlled by different timers? I don't have access to an oscilloscope to test it out so I hoped someone out there would be able to tell me if I am flogging a dead horse!
I also wonder if there is another approach to this problem.