Tuesday, August 24, 2010

I need to write a PIC micro-control program in C language to watch for belt movement.?

I have a shaft encoder on the belt. I want PIC chip to turn off certain output when shaft encoder is not moving and turn on that output when shaft encoder is moving. It was easy to turn on output when shaft encoder starts moving but I am having trouble to tell the chip when shaft encoder is stopped. I don't want to use WDT(watch dog timer) Any ideas and code examples will be appreciated.I need to write a PIC micro-control program in C language to watch for belt movement.?
You can solve that by polling the encoder in a fixed sample rate (say 100Hz I don't know). Keep checking the last sample with the current one, if it hasn't changed, increment a counting variable. Whenever the last sample is different from the current one, reset that counter.





Keep watching that variable, if it's bigger than a certain amount (if you pick 100, it means that after 1s without movement, the system is taken as stopped), set the output off, otherwise on. If you need some draft of the C code let me know.

No comments:

Post a Comment