This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

using the rotary encoder as an input device

i am searching for 'C' code for using the rotary encoder to input 4 digits and save them , then comapare the input code with a saved one.

i wish if any one can help

waled

  • It seems like you want to implement a quite trivial function, so exactly what do you need help with?

    Other people can probably not supply code, since code for embedded use is optimized for specific paltforms with equipment connected to specific pins.

    You need to configure a couple of processor pins as inputs. Which inputs is specific for your project.

    You need to regularly read the pins. You need to process the data depending on format - often Gray code.

    You need to figure out how your specific hardware saves the configuration. In flash, or eeprom or battery-backed RAM, ...

    You need to decide for yourself if you should store the "current" value, or if you should store a regular log every x seconds with the current position, or if you should count number of revolutions from the encoder. You need to decide if binary or ASCII format. With or without timestamp. If timestamp, you need to decide if the timestamp is number of ticks of uptime, or if your platform should have a Real Time Clock (RTC) so that you may store the time in Unix epoch (seconds since 1970-01-01 or as yyyy-mm-dd hh:mm:ss or any other format.

    How to compare a saved value with a current value depends completely on how you decide to save values.

    As you can see, all these steps are small and trival. Together, they may form a bigger program that may not be trivial. But since every single step requires a design decision - a decision that YOU must make - other people can't supply the code for your project.

    So now is a good time for you to sit down and start writing a specification for exactly what you want to solve, and exact how you want to solve it. Then it is up to you to split that specification into its multiple trivial steps and implement them one-by-one.

    A forum can help answering questions or suggest solutions if you find a problem where you get stuck. A forum can not do your job. Consultants can do your job - but only if you pay them and supply them with a comprehensive specification.

  • When posting a question, please be specific. It makes a difference whether you:

    1) create a code to handle raw input digital lines directly in your f/w. In literature, they typically referred to as lines #A, #B

    or

    2) you use a quadrature detector chip, like LS7084 which takes those #A, #B as an input and produces cleaned-up clock & direction signals which also must be handled as digital lines but in a different way ;-). The hint is: on C167 family you can map CLK/UP signals to the timer's TxIN & TxEUD inputs. BTW, there is solution based on using PCF8574, bus expander - see ref. b) below

    or

    3) you are going to use processed output from a specialized controller

    Good start for you would be:
    a) google & learn
    b) www.circellar.com/.../2303017.pdf

    -- Nikolay.