CANNY 7, Discrete IO Driver

General Description

CANNY 7 gives you access to eleven discrete general purpose IO channels. Each channel is physically accessed through a corresponding pin of X2(Channels 0..7) and X3(Channels 8..10) connectors. By writing and reading data of the respective driver registers, the functional diagram can manage the electric potential in each of these contacts, as well as get information about the current potential of each of them.

The physical characteristics of these channels allow them to be connected to a variety of external devices. Channels 0..7 can be used to work with any type of load, for example: electromagnetic relays, small electric motors, LEDs, low current systems. Channels 0..8 can only be used to work with resistive and capacitive loads. You can use a variety of input signal sources, such as: mechanical, electromechanical, and electronic buttons and switches, pulse generators, voltage source 0-12V, transistor outputs of various equipment, etc.

Channel operation mode and parameters are set via function diagram. At any given moment in time, the channels can only work in one of the possible modes, but it is possible to dynamically override the channel configuration from the function diagram.

A number of CANNY 7 controller drivers, specifically High Resolution PWM, UART / RS232 / Modbus, LIN, I²C, Dallas® 1-Wire® and Infrared Remote Control Driver, use input-output channels resources while operating and have a higher priority than the Discrete IO driver. This means that when you use these drivers on a certain controller channel, IO driver will not be able to access that channel.

IO Registers

The parameters that define operation mode and current state of the channel are set for each channel independently. Below is a description of expected IO register values.

Configuration and IO value registers.
Register Expected values
DIO Mode Setup Channel 0
DIO Mode Setup Channel 1
DIO Mode Setup Channel 2
1…65535 = set controller channel configuration, which determines current mode and valid parameters (defined by a special constant from the constants directory)
0 = transfer the channel to a neutral state, disable the ability to change the state of the channel through the function diagram
DIO Period Setup Channel 0
DIO Period Setup Channel 1
DIO Period Setup Channel 2

DIO Period Setup Channel 10
In Input Counter mode:
1…65535 = period in milliseconds, used for counting the number of pulses on the corresponding pin of the controller and updating the obtained value in the corresponding output value register 0 = enable the channel in counter accumulation mode

In PWM output mode:
1…65535 = period in milliseconds of generated pulses at the appropriate controller pin. 0 = stop generating pulses and set the potential at the appropriate controller pin equal to “OFF” potential of the current channel configuration.

In Digital Input mode:
0…65535 = the value is ignored

In Digital Output mode
0…65535 = the value is ignored
DIO Output Value Register 0
DIO Output Value Register 1
DIO Output Value Register 2

DIO Output Value Register 10
In Input Counter mode:
0…65535 = the value is ignored

In PWM output mode:
0…65535 = filling (duty cycle), in milliseconds, of generated pulses at the corresponding controller pin.

In Digital Input mode:
0…65535 = the value is ignored;

In Digital Output mode:
1…65535 = set an electric potential specified by the channel configuration for status “ON” at the appropriate controller pin
0 = set an electric potential specified by the channel configuration for status “OFF” at the appropriate controller pin

Control registers of the IO channels driver are divided into:

  • registers containing information of the IO driver altogether;
  • registers containing information about the state of each channel individually.

Below is a description of IO driver return value control registers in all major operation modes.

IO driver return value control registers.
Register Return values
DIO Input Activity 1 = during the last diagram execution loop:registered a change in electric potential on any controller pin corresponding to a channel configured as an active input or pulse counter
OR
register values of output channels or input-counters were changed by the diagram
0 = during the last diagram execution loop: no changes on active controller inputs were registered, no changes in active outputs were made by the diagram
DIO Output Overload Register 1 = on one or more controller channels configured as a power output: found a short-circuit and the channel was switched into protection mode
0 = none of controller channels detected a short-circuit
DIO Input Value Register #0
DIO Input Value Register #1
DIO Input Value Register #2

DIO Input Value Register #10
In Digital Input mode:
1 = at the appropriate controller pin: established electric potential corresponding to this channel’s input polarity;
0 = at the appropriate controller pin: established electric potential not corresponding to this channel’s input polarity.
In Input Counter mode:
0…65535 = the number of pulses registered on the appropriate controller pin during the last counting period
In Digital or PWM Output mode:
1 = at the appropriate controller pin: detected electric potential corresponding to the output polarity of the channel in “ON” mode
0 = at the appropriate controller pin detected electric potential not corresponding to output polarity of the channel in “ON” mode

Channel neutral state

The channels are automatically transferred to a neutral state in the following cases:

  • when controller is operating in software download mode;
  • when the controller is in standalone mode if the channel configuration is not set at all or set by the constant “Neutral state” or “0”;
  • at the time of controller software reset or power-on reset, before switching to a stand-alone mode and starting function diagram execution;
  • in the event of controller malfunction or system software failure.

Electrically, channel neutral position - “air” - is equivalent to a high resistance input, internally connected to the the GND terminal with a ~200k Ohm resistor.

Digital output mode

When the channel is configured to operate as a discrete output, it sets the following electric potentials at its corresponding controller pin:

  • an electric potential corresponding to the “ON” state, when a nonzero value is written to the channel’s output value register;
  • an electric potential corresponding to the “OFF” state when a value of “0” is written to the the channel’s output value register.

Channel configuration for operating in this mode is determined by a constant that defines a combination of parameters. These parameters determine the electrical potential and current at the channel’s pin in both the “ON” and “OFF” positions.

Digital output mode configuration parameters.
Parameter Permitted values
Channel type Digital output
“ON” pulled up to: plus (1mA); PLUS (100mA); pulled up to: minus (1mA); MINUS (100mA); neutral(air)
“OFF” pulled up to: plus (1mA); PLUS (100mA); pulled up to: minus (1mA); MINUS (100mA); neutral(air)

These constants are available in the “DIO Channel Configuration” folder of the CannyLab constants directory.

To set the controller channel to digital output mode, write the constant value corresponding to the selected mode into the channel’s “Register channel configuration №**” register.

Note: For channels operating in digital output mode, you can also obtain a value that corresponds to the current electrical potential at the channel pin. This allows the use of the channel in feedback mode.

Function diagram that alternately, every second, switches electrical potentials from + 12V (100mA) to GND (1 mA) at controller pins corresponding to channels #0 & #1 every second.

PWM output mode

When the channel is configured to operate as a PWM output, it generates a pulse-width moudulated signal of a predetermined polarity, frequency, and duty cycle on the corresponding controller pin. In this mode, the channel is asynchronous to functional diagram, which allows for greater stability of the generated timing signal, compared to implementing a PWM generator using the function diagram resources.

PWM mode graph.

Channel configuration for operation in this mode is determined by:

  • a constant, representing a combination of parameters that determine the electrical potential and current to the corresponding controller pin in the active “ON” and passive “OFF” generating phase;
  • a pair of numeric values that define the frequency and filling of the generated pulses in milliseconds.
PWM output mode confguration constant paremeters.
Parameter Permitted values
Channel type PWM output
“ON” plus (1mA); PLUS (100mA); minus (1mA); MINUS (100mA); air
“OFF” plus (1mA); PLUS (100mA); minus (1mA); MINUS (100mA); air

These constants are available in the “DIO Channel Configuration” folder of the CannyLab constants directory.

To set the controller channel to PWM output mode, do the following:

  • write the constant value, corresponding to PWM Output mode into the channel’s “DIO Mode IO Channel ##” register;
  • write a digital value from 0 to 65565, that defines the period of generated pulses in ms, into the channel’s “DIO Period IO Channel ##” register;
  • write a digital value from 0 to 65565, that defines the duty cycle of generated pulses in ms, into the channel’s “DIO Output IO Channel ##” register.
Function diagram that alternately, every second, switches of electrical potentials from + 12V (100mA) to GND (1 mA) at the controller pin corresponding to channel #0, implemented using the PWM output mode.

Digital input mode

When a channel is configured to operate as a digital output, it sets the following register values:

  • returns a value of “1” in its input value register, if it detects an electrical potential corresponding to the “Input polarity” state on the appropriate controller pin;
  • returns a value of “0” in its input value register, if it detects an electrical potential not corresponding to the “Input polarity” state on the appropriate controller pin.

Channel configuration for operation in this mode is determined by a constant that represents a combination of parameters. These parameters define the electrical potential that will correspond to the state of “1” of the channel; the existence and potential of internal controller pin “pull-up”; sensitivity and channel activity in the low power mode of the controller.

Digital input mode parameter values table.
Parameter Permitted values
Channel type Digital Input
Input polarity PLUS; MINUS
Pull-up plus; minus; air
Standby mode active; passive
Sensitivity max (0 ms); high (20 ms); norm (200 ms); low (700 ms)

Change of potential on the channel pin is in the active standby mode will result in the controller exiting the hibernation state immediately. Change of potential on the channel pin is in the passive standby mode won’t result in the controller changing its power consumption state.

Channel sensitivity determines its “bounce protection”, ie the time interval during which the electrical potential on the corresponding channel pin should remain unchanged, in order to be considered set and change the channel input value register.

These constants are available in the “DIO Channel Configuration” folder of the CannyLab constants directory.

To set the controller channel to Digital Input mode, write the constant value for the desired mode into the “DIO Mode IO Channel ##” register of the appropriate channel.

Function diagram that turns on the built-in green LED when the “GND” potential is detected at the channel #0 pin and held for at least 200ms.

Counter mode

The channel, configured to operate in counter mode, increments the value of its output value register, based on the number times the electric potential is switched on the corresponding controller pin, from the state opposite to the parameter “Input Polarity” into the state of the parameter “Input Polarity”, during the last period of the specified duration. Thus, the channel in this mode functions as a counter of the signal’s rising edges or as a frequency meter.

In this mode, the channel is asynchronous to the function diagram, which allows for greater accuracy in determining the time parameters of the signal, as well as measuring a higher frequency signal compared to implementing the counter using function diagram resources.

Channel configuration for operation in this mode is determined by a constant that defines a combination of parameters. These parameters determine the electrical potential, the appearance of which at teh corresponding channel pin registers the rising edge of a signal; presence and potential of the internal “pull-up”.

Counter mode parameter values table.
Parameter Permitted values
Channel type Input-Counter
Input polarity PLUS; MINUS
Pull-up plus; minus; air

In the counter mode, the channel is always in active standby with maximum sensitivity. Counting the number of state changes of this channel is carried out asynchronously.

These constants are available in the “DIO Channel Configuration” folder of the CannyLab constants directory.

To transfer the controller channel into Counter mode, do the following:

  • write a constant, corresponding to the selected mode, into the appropriate channel’s “DIO Mode IO Channel ##” register;
  • write a numeric value from 0 to 65565, which determines the pulse counting period in ms, into the appropriate channel’s “DIO Period IO Channel ##” register.

With a non-zero value in the period register, the value in the input value register of the channel is updated once per period and contains the number of pulses registered by the counter in the last pulse-counting period.

Counting of pulses by the counter is conducted with overflow. This means that when the value of 65565 is reached and subsequently increases by one, the counter value is set to zero. Each subsequent pulse increments the counter by one as per usual.

Function diagram of a tachometer with a resolution of 100 RPM, counting the number of pulses on the controller pin corresponding to channel №0.

Note: If the period is set to zero, the counter continuously counts pulses, with the total being accumulated in the hannel output value register. In this mode, the value of this register is reset only by a register overflow.

Equivalent circuit diagrams

Equivalent circuit diagrams for each possible state of the input-output channel shown in the table below:

Equivalent circuit diagrams value table
Channel state Diagram
“air”
Channel diagram in “air” mode
“plus (1mA)”
Channel diagram in “plus (1mA)” mode
“PLUS (100mA)”
Channel diagram in “PLUS (100mA)” mode
“minus (1mA)”
Channel diagram in “minus (1mA)” mode
“MINUS (100mA)”
Channel diagram in “MINUS (100mA)” mode
“pull up air”
Channel diagram in “pull up air” mode
“pull up plus”
Channel diagram in “pull up plus” mode
“pull up minus”
Channel diagram in “ull up minus” mode

Electrical protection

Controller system software performs automatic short circuit protection for channels that operate in digital output and PWM output modes, whose current in the “ON” or “OFF” states significantly exceeds 100 mA. Protection works in the following way:

  • the shorted channel is switched into the neutral mode;
  • the channel is periodically pulsed as test;
  • the channel is returned to the user-defined configuration when the short-circuit is no longer detected.

This protection is fully automatic and requires no user configuration.

SEE ALSO