Need to have index zero counter and have count loop based on encoder resolution
I have two issues I'm trying to figure out.
-
I am using the encoder to read revolutions based on the encoder resolution. As an example, I have an encoder with 1000 ppr. This gives me 4000 "ticks" per revolution with my quadrature encoder with an index signal. So, I will want the encoder to count from zero to 3999 and then start back at zero so I will have a total of 4000 pulses. It would be good to have this as a variable in case I change resolution on the encoder. Ultimately I'll be mapping from zero to 359 but I need the high resolution and feedback as to the direction more accurately so it is great that on every tick I'm getting a direction value.
-
I will use the index signal to reset the counter each revolution. At a basic level I can set to zero. In fact, for my purpose, I will want to use it to know the "offset" from zero. So, for example, when the arduino powers up I can put the arm that my encoder is attached to in the exact correct zero position. At that point I want to be able to send a "reset counter to zero" command. Then I can rotate the arm a full circle and read where the index is in reference to the zero position. I can then save that difference between zero and the index signal as an "offset". I'm not exactly sure how I would save that offset value but as long as I can read/request/set that value I can go from there. Then, whenever the arduino power cycles all I have to do is pull the offset number from where it is saved (external database or SD card) and write it to the arduino program. Then I rotate the arm around once. When it hits the index the counter should then automatically be set to that offset value. As a result the zero position will always be exactly where it should be and it won't have to be calibrated on every startup.
-
In the .ino file I'll want to send out the position every time it changes via serial/ethernet along with some other data that I'm reading from other sensors so I'll need to have the header file give the .ino file the information on each tick so I can send it out. I would think this should be in the .ino file as opposed to the header file but, as I'm sure you can tell, I'm not an expert. I only know enough to get into trouble.
I have tried to add another interrupt to do this function but I'm not advanced enough to make it work within your templates, etc. I appreciate any help you could offer!!