Hi,
I have a problem where i don't how to write a program for my rotation counter.
My system is a rotation counter, It count decrementally. does anyone here can help me on the programming part?
If you are simply counting then you can use one of the timer modules which can count from an external pin. If you want to measure pulse rate then the capture mode may be more appropriate. Do you have a schematic? You will need to ensure you have a clean input signal to prevent miscounting.
Is your magnetic sensor a hall effect sensor or reed switch type? If the sensor gives pulse outputs then feed that pulse to RB0/INT pin and use PORTB interrupt to get the values of rotations. If one pulse is given for every rotation then interrupt occurs for every rotation, so, no. of interrupts is the no. of rotations.
If the sensor gives you a pulse, you can use the CCP module for a precise value.
Made a frequencimeter with the CCP module in this post.
Modified to give the RPM.