Universal DRO based on Arduino Nano - shDRO. Part 2

    Hello again!

    I continue to describe my development of shDRO. In this part, I will describe the device polling algorithm and the format of the console commands.

    First part.

    Firmware

    Since the number of channels / ports to which readers can be connected is 12, and each channel can theoretically be configured for interrupt, two PCINT interrupt handlers are used (for ports D and C). This implies one limitation on the connection: all the outputs of the device that are configured for input must be connected to the channels of one group. If the channel is configured for output, then for the current device, it does not matter which group it belongs to. Groups: group1 (channels 0-5), group2 (channels 6-11).

    Two ring buffers, 256 bytes each, are used for interrupt handlers.

    The interrupt handler code is:

    buf[pos] = DATA_N;
    pos++;

    Where DATA_N is one of the ports: PIND, PINC.

    Data processing is as follows:

    • an interruption occurs, a new port value is written to the buffer;
    • the buffer is periodically polled, and the data that appeared after the last poll is read from it (the position of the buffer of the last poll is stored in the device structure);
    • in the process of reading new data, the interrupt levels set for the channels are compared with the current port data. If the interrupt level does not match, then the data is ignored.
    • it checks that all data for processing has been accepted (for example, 24 bits must be received for the BIN6 protocol);
    • the data is processed in a “readable” form and the processed data is displayed on the screen;
    • then the process is repeated;

    To implement the above logic, the following logic modules are implemented in the firmware:

    • Device: the module contains all the information about one connected device. For each connected device, such a module is created;
    • Protocol: the module contains information about the protocol and how to process the signals arriving at the ports in accordance with this exchange protocol;
    • Function: the module contains information on how to convert data received from the Protocol module. For example, there is a Protocol module that supports a quadrature signal, but the devices that issue a quadrature signal may be different: it can be an optical ruler, or a speed sensor. Those. in one case, the data needs to be converted to mm or inches, and in the other rpm. This module does just that;
    • Led: a module that displays information on indicators. shDRO contains 4 indicators, and for each device the desired display indicator is set;

    As a result, to connect the device, in the console you need:

    • configure the desired channels;
    • add device;
    • for device set protocol, function and led;
    • add / bind the necessary channels to the device;

    Console

    At the moment, I checked the operation of the console in the ArduinoIDE port monitor and in Terminal v.1.9b. For terminals of the Putty type, you need to implement the echo mode (not implemented).

    Command format:

    <команда> </аргумент1> <значение_аргумента1> </аргументN> <значение_аргументаN>

    The maximum number of arguments in one line is 5. Case

    does not matter, command parsing occurs after the string is converted to lower case (exception: argument value in quotation marks).

    All commands are executed only after the Setup command is issued (an exception is the Help command, which displays a list of all available commands).

    All commands are described in the attached archive, as well as the first version of the firmware in hex format.

    shDRO.zip (.hex + description of commands)

    shDRO sources

    Continued.

    Thank!

    PS
    Commands related to the configuration of devices and channels can be sent to the bare arduino without strapping.

    PS1
    Request to those who live in Kazan.
    If you have:
    • digital calipers working according to the protocols: 24BIT, BCD7;
    • iGaging digital rulers (21BIT protocol);

    then could you give them to me for a couple of days to write and debug the protocols for them?
    I promise to keep them safe and sound!
    But this is in PM. Thank you in advance.

    PS2 I
    forgot to add two commands to the command description file:
    - save: saves the settings of channels and devices in EEPROM;
    - load: unloads the settings of channels and devices from the EEPROM (load is performed automatically during initialization);
    I will not re-upload the file, just keep in mind. But "help" displays these commands.

    Also popular now: