I am just starting on a small project. It is not to be a product or anything like that, but just something to test an idea. I will only build one, and will only use it for a few days.
What I have is a motor that currently turns at 120revolutions per second. It it pretty tight and there is less than 2uS in deviation from turn to turn. If I set timer1 on my mega16 to count on the clock (3.711MHZ) the count is always between 30848 and 30864. The extreme ends seldom happen and it is usually around 30857.
What I need to do is to drive a stepper motor so that it is exactly the same speed as this precise motor. Sounds easy enough, however there is one more thing. I need to be able to select in software the angular difference between them. So, if the encoder pulse that I get from the one is at 0 time, then I need to be able to have the encoder pulse from the other at programmable time N. For example, if they were both rotation a shaft, then the shaft could be programmed to be rotating at exactly the same speed, but (for example) 90 degrees ahead of the other. (Or any other number of degrees.)
The way I was thinking of doing it does not seem very good and so I am asking for suggestions on how to do it.
I had intended to use INTO for the pulse for the first motor, and then use ICR1 for the input of my stepper motors encoder pulse. I could then control the apparent angular difference between the two motors. I could step every 30857/steps_per_revolution.
The problem is that my approach has me resetting the timer at 30857 and I don't think that is a very good way of doing things. Also, it gets kind of complicated if I miss a step during some other interrupt occurance.
Any suggestions on a general approach would be appreciated.