Search code examples
microcontrollerpicdevice-driver

Writing device driver for rotary encoder on PIC16F


Building on top of this question Writing Device Drivers for a Microcontroller(any) I am just starting to learn deep inside microcontrollers, more specifically PIC16F690. I already know a whole lot of Arduino and am good with logic.

I want to start writing a device driver for these rotary encoders (the ones that look like a potentiometer), to use it like a human interface device. Where should I start from, what should I consider?

I know how to use such rotary encoders with Arduino, using libraries. Understanding how it works is not a problem.

Questions like these (with these answers) I need information about writing a device driver for microcontroller doesn't help.


Solution

  • You should start from interfacing and getting it working with PIC16F690. As you know (you stated that you understand how encoder works), It will emit a pair of signals that generally named A and B signals. You must track their polarity to define the movement direction. You can do this by using interrupt on change (IOC) feature of that PIC micro.

    Once you got it working enough to comply your needs or requirements, then you start to restructure and encapsulate your code so that it can be used as a library. You can see the rotary encoder library of Arduino to make your code similar to it in terms of encapsulation. Your encapsulated code should have enough functions to read all possibly needed data like current position, whether the encoder is moving or not, moving direction etc.

    When you finish the encapsulation process, then you should do unit tests first. When your code passes all unit tests then you should do integration tests by using the new library you created in an independent test project. If it passes the integration tests then it would be ready to use in real projects.