Classes | |
struct | CpuPortAndPin |
struct | PWMInSubchannelConfig |
PWM input subchannel configuration. More... | |
struct | PWMOutSubchannelConfig |
PWM output subchannel configuration. More... | |
struct | PWMOutSubchannelConfig2 |
PWM output subchannel configuration 2. More... | |
Public Types | |
enum | Port { P1 = 0, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20, P21, P22, P23, P24, P25, P26, P27, P28, P29, P30, P31, P32, P33, P34, P35, P36, P37, P38, P39, P40, NumOfItems, First = P1, Last = P40, Inv = NumOfItems } |
Physical ports on the MIO board. More... | |
enum | PortMode { DigIn = 0, DigInOut, Vref, AnaIn, NumOfItems, First = DigIn, Last = NumOfItems - 1 } |
Port mode for physical ports on the MIO board. More... | |
enum | PortDigInOut { In = 0, Out0, Out1 } |
Additional parameter for Mio.PortMode.DigInOut. More... | |
enum | TaskType { DS18x20 = 0, NumOfItems, First = DS18x20, Last = NumOfItems - 1, Inv = NumOfItems } |
MIO (background) task types. More... | |
enum | DS18x20Type { Auto = 0, S, B } |
DS18x20 sensor type. More... | |
enum | DS18x20Error { None = 0, NotPresent, Error, StartFail, BadCrc } |
DS18x20 error codes. More... | |
enum | PWMMode { None = 0, Out, In } |
PWM mode. More... | |
enum | PWMClockSpeed { f20MHz = 0, f10MHz = 1, f5MHz = 2, f2500kHz = 3, f625kHz = 4 } |
PWM clock speed. More... | |
enum | PWMInMode { Idle = 0, Active, ActivateIfIdle } |
PWM input measurement mode. More... | |
enum | Rc { OK = 0, OS_DeviceNotOpen, OS_DeviceBusy, OS_DeviceWriteError, OS_DeviceReadError, OS_DeviceReadTimeout, API_BadInputParam, API_NullInputParam, API_BadPort, API_BadMode, API_MessageCorrupt, API_MessageCrc, API_MessageSyntax, API_WrongMessage, MIO_UartOvr, MIO_UartOer, MIO_UartFer, MIO_UartPer, MIO_MessageTimeout, MIO_MessageCorrupt, MIO_MessageCrc, MIO_MessageSyntax, MIO_BadPort, MIO_BadPortOrMode, MIO_WrongMode, MIO_BadTaskId, MIO_BadTaskType, MIO_WrongTaskType, MIO_BadTaskConfig, MIO_TaskNotActive, NumOfItems, First = OK, Last = NumOfItems - 1 } |
Result & error codes. More... | |
enum | HostMsgId { Reset = 0, Loopback, SetMioPortsModes, GetMioPortsModes, GetDigPortValue, SetDigPortValue, SetDigPortsValues, GetDigPortsValues, GetAnaPortsValues, StartTask, StopTask, GetDS18x20TaskTemp, StartPWMOut, AdjustPWMOut, StartPWMIn, SetPWMInMode, GetPWMInResult, StopPWM, NumOfItems, First = Loopback, Last = NumOfItems - 1 } |
enum | MioMsgId { ResetResp = 0, LoopbackResp, SetMioPortsModesResp, GetMioPortsModesResp, SetDigPortValueResp, GetDigPortValueResp, SetDigPortsValuesResp, GetDigPortsValuesResp, GetAnaPortsValuesResp, ErrorResp, StartTask, StopTask, GetDS18x20TaskTemp, StartPWMOut, AdjustPWMOut, StartPWMIn, SetPWMInMode, GetPWMInResult, StopPWM, NumOfItems, First = LoopbackResp, Last = NumOfItems - 1 } |
enum | CpuPort { P0 = 0, P1, P2, P3, P4, P6, NumOfItems, First = P0, Last = P6 } |
Public Member Functions | |
void | SetReceiveTimeout (uint timeout_ms) |
Set receive timeout in ms (milli-seconds). | |
uint | GetReceiveTimeout () |
Get receive timeout in ms (milli-seconds). | |
void | SetDrainTime (uint drain_time_ms) |
Set drain time in ms (milli-seconds). | |
uint | GetDrainTime () |
Get drain time in ms (milli-seconds). | |
virtual string | ResultCodeToText (Rc rc) |
Convert MIO API result code to text string. | |
Rc | Reset () |
Reset MIO board. | |
Rc | Loopback (byte[] out_data, out int out_data_len, byte[] in_data, int in_data_len) |
Loopback test. | |
Rc | SetMioPortsModes (PortMode[] modes, byte[] prms, Port[] ports, int num_ports) |
Set Mio.PortMode for 1...40 Mio.Port's. | |
Rc | SetMioPortMode (PortMode mode, byte prm, Port port) |
Set Mio.PortMode for a single Mio.Port. | |
Rc | GetMioPortsModes (PortMode[] modes, byte[] prms, Port[] ports, int num_ports) |
Get Mio.PortModes and params for 1...40 Mio.Ports at a time. | |
Rc | GetMioPortMode (out PortMode mode, out byte prm, Port port) |
Get Mio.PortMode and param for a single Mio.Port. | |
Rc | SetDigitalOutputValue (byte value, Port port) |
Set digital output value (0 or 1) for a Mio.Port. | |
Rc | GetDigitalInputValue (out byte value, Port port) |
Get digital input value (0 or 1) from a single Mio.Port. | |
Rc | SetDigitalOutputsValues (byte[] values, Port[] ports, int num_ports) |
Set digital output value (0 or 1) for 1...39 Mio.Ports. | |
Rc | GetDigitalInputsValues (byte[] values, Port[] ports, int num_ports) |
Get digital input value (0 or 1) for 1...40 Mio.Ports. | |
Rc | GetAnalogInputsValues (int[] values, Port[] ports, int num_ports) |
Get analog input value from 1...8 Mio.Ports. | |
Rc | GetAnalogInputValue (out int value, Port port) |
Get analog input value from a single Mio.Port. | |
Rc | StartDS18x20Task (int task_id, Port mio_port, DS18x20Type sensor_type, uint conversion_time_x100ms) |
Start a DS18x20 temperature sensor measurement task. | |
Rc | GetDS18x20TaskTemperature (out int temperature, out byte sn, out DS18x20Error error, int task_id) |
Get DS18x20 temperature. | |
Rc | StopTask (int task_id) |
Stop a task. | |
Rc | StartPWMOut (int pwm_clock_channel, PWMClockSpeed pwm_clock_speed, int pwm_period, PWMOutSubchannelConfig[] subchannels) |
Start PWM output (generation) on 1...3 PWM subchannels. | |
Rc | StartPWMOut (int pwm_clock_channel, float pwm_frequency, PWMOutSubchannelConfig2[] subchannels) |
Start PWM output (generation) on 1...3 PWM subchannels. | |
Rc | AdjustPWMOut (int pwm_clock_channel, PWMClockSpeed pwm_clock_speed, int pwm_period, PWMOutSubchannelConfig[] subchannels) |
Adjust ongoing PWM output (genration) on 1...3 PWM subchannels. | |
Rc | AdjustPWMOut (int pwm_clock_channel, float pwm_frequency, PWMOutSubchannelConfig2[] subchannels) |
Adjust ongoing PWM output (genration) on 1...3 PWM subchannels. | |
Rc | StartPWMIn (int pwm_clock_channel, PWMInSubchannelConfig[] subchannels) |
Start PWM input (measurement) on 1...4 PWM subchannels. | |
Rc | SetPWMInMode (int pwm_clock_channel, int pwm_subchannel, PWMInMode mode) |
Set mode for a PWM input subchannel. | |
Rc | GetPWMInResult (out uint total_halfperiod_time, out uint total_period_time, out int edges_captured, int pwm_clock_channel, int pwm_subchannel) |
Get measurement result from a PWM input subchannel. | |
Rc | StopPWM (int pwm_clock_channel) |
Stop all PWM input/output on the selected PWM clock channel. | |
bool | OpenComPort (string port) |
Open communication port to MIO board. | |
void | CloseComPort () |
Close communication port to MIO board. | |
bool | IsOpen () |
Check if the communication port is open. | |
Static Public Member Functions | |
static bool | PortIsValid (uint mio_port) |
Check if Port is valid. | |
static bool | PortIsInvalid (uint mio_port) |
Check if Port is invalid. | |
static bool | PortModeIsValid (uint mio_port_mode) |
Check if PortMode is valid. | |
static bool | PortModeIsInvalid (uint mio_port_mode) |
Check if MioPortMode is invalid. | |
static bool | TaskTypeIsValid (uint mio_task_type) |
Check if TaskType is valid. | |
static bool | MioTaskTypeIsInvalid (uint mio_task_type) |
Check if MioTaskType is invalid. | |
static bool | TaskIdIsValid (uint mio_task_id) |
Check if MIO task id is valid. | |
static bool | TaskIdIsInvalid (uint mio_task_id) |
Check if MIO task id is invalid. | |
static bool | RcIsValid (uint code) |
Check if Rc is valid. | |
static bool | RcIsInvalid (uint code) |
Check if Rc is invalid. | |
static bool | HostMsgIdIsValid (uint msg_id) |
static bool | HostMsgIdIsInvalid (uint msg_id) |
static bool | MioMsgIdIsValid (uint msg_id) |
static bool | MioMsgIdIsInvalid (uint msg_id) |
static bool | CpuPortIsValid (uint mio_cpu_port) |
static bool | CpuPortIsInvalid (uint mio_cpu_port) |
static Rc | ConvertPWMOutValues (out PWMClockSpeed pwm_clock_speed, out int pwm_period, PWMOutSubchannelConfig[] dst_subchannels, float pwm_frequency, PWMOutSubchannelConfig2[] src_subchannels) |
Convert from frequency/duty cycle PWM values to PWM clock tick values. | |
Public Attributes | |
const uint | TaskMaxTaskId = 8 |
Max number of simultaneous MIO tasks. | |
const int | PWM_DISABLE = 0 |
Disable PWM subchannel. The corresponding Mio.Port can be used for other things. | |
const int | PWM_ENABLE = 0x01 |
Enable PWM subchannel. | |
const int | PWM_POL_0 = 0 |
Polatiry 0. First halfperiod of PWM signal is 0. | |
const int | PWM_POL_1 = 0x02 |
Polarity 1. First halfperiod of PWM signal is 1. | |
const int | PWM_IDLE = 0 |
PWM input measurement is idle (not measuring). | |
const int | PWM_ACTIVE = 0x04 |
PWM input measurement is active. | |
const uint | MessageMaxPayloadSize = 28 |
Max message payload size in bytes. | |
const uint | CommunicationSpeed = 125000 |
Protected Member Functions | |
virtual void | DispatchOutOfBandMessage (MioMsgId msg_id, int payload_len, byte[] payload) |
"Call-back" for out-of-band messages received from MIO. |
The functionality in the MIO board is exposed through an API which is implemented in this class.
The Mio class translates the API function calls into messages that are sent/received to/from the MIO board.
The Mio class requires .NET framework version 2.0
enum Mio::Port |
Physical ports on the MIO board.
enum Mio::PortMode |
Port mode for physical ports on the MIO board.
enum Mio::PortDigInOut |
enum Mio::TaskType |
enum Mio::DS18x20Type |
enum Mio::DS18x20Error |
enum Mio::PWMMode |
enum Mio::PWMClockSpeed |
enum Mio::PWMInMode |
enum Mio::Rc |
Result & error codes.
enum Mio::HostMsgId |
For internal use only.
Message Id's for messages from Host to MIO board
enum Mio::MioMsgId |
For internal use only.
Message Id's for messages from MIO board to Host
enum Mio::CpuPort |
static bool Mio::HostMsgIdIsValid | ( | uint | msg_id | ) | [inline, static] |
For internal use only.
Check if HostMsgId is valid
static bool Mio::HostMsgIdIsInvalid | ( | uint | msg_id | ) | [inline, static] |
For internal use only.
Check if HostMsgId is invalid
static bool Mio::MioMsgIdIsValid | ( | uint | msg_id | ) | [inline, static] |
For internal use only.
Check if MioMsgId is valid
static bool Mio::MioMsgIdIsInvalid | ( | uint | msg_id | ) | [inline, static] |
For internal use only.
Check if MioMsgId is invalid
static bool Mio::CpuPortIsValid | ( | uint | mio_cpu_port | ) | [inline, static] |
For internal use only.
Check if CpuPort is valid
static bool Mio::CpuPortIsInvalid | ( | uint | mio_cpu_port | ) | [inline, static] |
For internal use only.
Check if CpuPort is invalid
void Mio::SetReceiveTimeout | ( | uint | timeout_ms | ) | [inline] |
Set receive timeout in ms (milli-seconds).
The receive timeout specifies how long the API will wait for a response message from MIO, after a request message has been sent to it. If no response message is received within the specified timeout, the correspodning API function will return with the the error code Mio.Rc.OS_DeviceReadTimeout.
The default value (of about 1000 ms) should be good in most cases. Increase the timeout if the host OS is VERY busy with other tasks.
timeout_ms | IN: Timeout in ms |
uint Mio::GetReceiveTimeout | ( | ) | [inline] |
Get receive timeout in ms (milli-seconds).
See documentation for SetReceiveTimeout().
void Mio::SetDrainTime | ( | uint | drain_time_ms | ) | [inline] |
Set drain time in ms (milli-seconds).
The drain time specifies how long the communication channel should be cleared from possibly bad data after a communication error has been detected.
The default value (of about 200 ms) should be good in most cases.
drain_time_ms | IN: Drain time in ms |
uint Mio::GetDrainTime | ( | ) | [inline] |
Get drain time in ms (milli-seconds).
See documentation for SetDrainTime().
virtual string Mio::ResultCodeToText | ( | Rc | rc | ) | [inline, virtual] |
Convert MIO API result code to text string.
rc | Error code to convert to string |
Rc Mio::Reset | ( | ) | [inline] |
Reset MIO board.
The function resets MIO to the same state as when power was switched on to the board.
Rc Mio::Loopback | ( | byte[] | out_data, | |
out int | out_data_len, | |||
byte[] | in_data, | |||
int | in_data_len | |||
) | [inline] |
Loopback test.
Loop the given data through the MIO board and back to the host. This function can be used as a basic communication test.
out_data | OUT: Output buffer (must be at least MessageMaxPayloadSize bytes long) | |
out_data_len | OUT: Length of output data is stored here | |
in_data | IN: Input data (max MessageMaxPayloadSize bytes long) | |
in_data_len | IN: Length of input data (max MessageMaxPayloadSize bytes long) |
Set Mio.PortMode for 1...40 Mio.Port's.
The operating mode (Mio.PortMode) for a port (Mio.Port) must be set before the port can be used. The following modes can be set:
Mio.PortMode.DigIn // Digital input (default at MIO startup) Mio.PortMode.DigInOut // Digital input and output Mio.PortMode.Vref // Vref input for ADC Mio.PortMode.AnaIn // Analog input
See definition of Mio.PortMode for more info.
modes | IN: 1...40 Mio.PortModes | |
prms | IN: 1...40 extra paramerers for the Mio.PortModes. Set to null to apply default (0) for all ports | |
ports | IN: 1...40 Mio.Ports | |
num_ports | IN: Number of ports to configure |
Set Mio.PortMode for a single Mio.Port.
Same as SetMioPortsModes() but for a single Mio.Port.
mode | IN: Mio.PortMode | |
prm | IN: Extra parameter for the Mio.PortMode. Set to 0 if not applicable | |
port | IN: Mio.Port |
Get Mio.PortModes and params for 1...40 Mio.Ports at a time.
modes | OUT: Buffer where 1...40 Mio.PortModes are stored | |
prms | OUT: Buffer where 1...40 extra params for the Mio.PortModes are stored | |
ports | IN: 1...40 Mio.Ports | |
num_ports | IN: Number of ports |
Get Mio.PortMode and param for a single Mio.Port.
Same as GetMioPortsModes() but for a single Mio.Port.
mode | OUT: Mio.PortMode | |
prm | OUT: Extra param related to Mio.PortMode | |
port | IN: Mio.Port |
Set digital output value (0 or 1) for a Mio.Port.
The Mio.Port must be configured as Mio.PortMode.DigInOut. If the port currently is in input mode, it is automatically switched to output mode.
value | OUT: Output value (0 or 1) to be set | |
port | OUT: Mio.Port |
Get digital input value (0 or 1) from a single Mio.Port.
The Mio.Port must be configured as Mio.PortMode.DigInOut or Mio.PortMode.DigIn. If the port is Mio.PortMode.DigInOut and currently in output mode, it is automatically switched to input mode.
value | OUT: Input value (0 or 1) is stored here | |
port | IN: Mio.Port |
Set digital output value (0 or 1) for 1...39 Mio.Ports.
The ports must be configured as Mio.PortMode.DigInOut. This is an optimized version that sets the output values with minimum latency between the CPU I/O register writes. All Mio.Ports residing on the same 8 bit CPU I/O register are guaranteed to be updated simultaneously. The maximum update latency between any two Mio.Ports residing on different CPU I/O registers is ~5 us. Please check the MIO specifications for the exact latency.
values | IN: 1...39 output values (0 or 1) corresponding to the Mio.Ports | |
ports | IN: 1...39 Mio.Ports | |
num_ports | IN: Number of ports |
Get digital input value (0 or 1) for 1...40 Mio.Ports.
The ports must be configured as Mio.PortMode_DigIn or Mio.PortMode_DigInOut. This is an optimized version that gets the input values with minimum latency between the CPU input register reads. All Mio.Ports residing on the same 8 bit CPU input register are guaranteed to be read simultaneously. The maximum read latency between any two Mio.Ports residing on different CPU input registers is ~3 us. Please check the MIO specifications for the exact latency.
values | IN: 1...40 input values (0 or 1) corresponding to the Mio.Ports | |
ports | IN: 1...40 Mio.Ports | |
num_ports | IN: Number of ports |
Get analog input value from 1...8 Mio.Ports.
The ports must be configured as Mio.PortMode.AnaIn (only Mio.Port.P11 ... Mio.Port.P18 can be configured in this mode). The ports are sampled sequentially in the same order as specified in the 'ports' array. One sample takes ~6 us. When sampling more than one port, the samples are taken ~15 us apart giving a total of ~120 us for sampling all 8 analog input ports.
values | OUT: Array where analog input values are stored; 1...8 items | |
ports | IN: Analog input ports; 1...8 ports (Mio.Port.P11 ... Mio.Port.P18) | |
num_ports | IN: Number of ports in array; 1...8 |
Get analog input value from a single Mio.Port.
Same as GetAnalogInputsValues() but for a single Mio.Port.
value | OUT: Analog input values is stored here | |
port | IN: Analog input port (Mio.Port.P11 ... Mio.Port.P18) |
Rc Mio::StartDS18x20Task | ( | int | task_id, | |
Port | mio_port, | |||
DS18x20Type | sensor_type, | |||
uint | conversion_time_x100ms | |||
) | [inline] |
Start a DS18x20 temperature sensor measurement task.
The function will internally configure the selected Mio.Port for temperature measurement. The temperature is measured periodically by a task. The measurement interval time is specified with 'conversion_time_x100ms' which can be from 0,1 - 25,5 seconds.
The DS18x20 sensor needs an external 4k7 pull-up resistor on the 1-wire data line. When only using the weak internal pull-ups of the MIO board, MIO will detect the sensor, but reading the temperature will give wrong results.
task_id | IN: Task id: 0 ... Mio.TaskMaxTaskId | |
mio_port | IN: Mio.Port to be used as 1-wire data interface to the sensor | |
sensor_type | IN: DS18x20 sensor type | |
conversion_time_x100ms | IN: Temperature conversion interval [1...255] in multiples of 100 ms |
Rc Mio::GetDS18x20TaskTemperature | ( | out int | temperature, | |
out byte | sn, | |||
out DS18x20Error | error, | |||
int | task_id | |||
) | [inline] |
Get DS18x20 temperature.
Get the latest temperature measurement result from the DS18x20 task that was started with StartDS18x20Task().
temperature | OUT: Temperature in deci-Celsius | |
sn | OUT: Measurement sequence number. 0 = no measurement ready yet, after that sn is 1...255,1...255,1... | |
error | OUT: Sensor error | |
task_id | IN: Id of DS18x20 task |
Rc Mio::StopTask | ( | int | task_id | ) | [inline] |
Stop a task.
The function stops the specified task that has been started with any of the StartXXXTask() functions.
task_id | IN: Task id: 0 ... Mio.TaskMaxTaskId |
static Rc Mio::ConvertPWMOutValues | ( | out PWMClockSpeed | pwm_clock_speed, | |
out int | pwm_period, | |||
PWMOutSubchannelConfig[] | dst_subchannels, | |||
float | pwm_frequency, | |||
PWMOutSubchannelConfig2[] | src_subchannels | |||
) | [inline, static] |
Convert from frequency/duty cycle PWM values to PWM clock tick values.
pwm_clock_speed | OUT: Calculated PWM clock speed is stored here | |
pwm_period | OUT: Calculated PWM period width (in PWM clock ticks): 1 ... 65536 is stored here | |
dst_subchannels | OUT: Calculated 3 PWM subchannel config info is stored here | |
pwm_frequency | IN: PWM frequency (in Hz): ~10.0 ... ~400000.0 | |
src_subchannels | IN: 3 PWM subchannel config info to convert |
Rc Mio::StartPWMOut | ( | int | pwm_clock_channel, | |
PWMClockSpeed | pwm_clock_speed, | |||
int | pwm_period, | |||
PWMOutSubchannelConfig[] | subchannels | |||
) | [inline] |
Start PWM output (generation) on 1...3 PWM subchannels.
Configure a PWM clock channel in PWM output mode, with one of the following clock speeds; 20MHz, 10MHz, 5MHz, 2.5MHz or 625 kHz. A PWM clock channel in output mode has 3 independent 16-bit PWM subchannels which can output PWM signals. The 3 subchannels are syncronised, i.e. their PWM periods start on the same PWM clock tick.
The subchannels are mapped onto the physical Mio.Ports as follows:
PWM clock channel 0: subchannel 0 /* not available for PWM output */ subchannel 1 Mio.Port.P29 subchannel 2 Mio.Port.P28 subchannel 3 Mio.Port.P27 PWM clock channel 1: subchannel 0 /* not available for PWM output */ subchannel 1 Mio.Port.P25 subchannel 2 Mio.Port.P24 subchannel 3 Mio.Port.P23
This function configures and starts 1..3 PWM subchannels on 1 PWM clock channel. The shape of the PWM signals are specified as number of PWM clock ticks.
pwm_clock_channel | IN: PWM clock channel: 0 or 1 | |
pwm_clock_speed | IN: PWM clock speed | |
pwm_period | IN: PWM period width (in PWM clock ticks): 1 ... 65536 | |
subchannels | IN: 3 PWM subchannel config for subchannels 1, 2, 3 |
Rc Mio::StartPWMOut | ( | int | pwm_clock_channel, | |
float | pwm_frequency, | |||
PWMOutSubchannelConfig2[] | subchannels | |||
) | [inline] |
Start PWM output (generation) on 1...3 PWM subchannels.
Configure a PWM clock channel in PWM output mode, with one of the following clock speeds; 20MHz, 10MHz, 5MHz, 2.5MHz or 625 kHz. A PWM clock channel in output mode has 3 independent 16-bit PWM subchannels which can output PWM signals. The 3 subchannels are syncronised, i.e. their PWM periods start on the same PWM clock tick.
The subchannels are mapped onto the physical Mio.Ports as follows:
PWM clock channel 0: subchannel 0 /* not available for PWM output */ subchannel 1 Mio.Port.P29 subchannel 2 Mio.Port.P28 subchannel 3 Mio.Port.P27 PWM clock channel 1: subchannel 0 /* not available for PWM output */ subchannel 1 Mio.Port.P25 subchannel 2 Mio.Port.P24 subchannel 3 Mio.Port.P23
This function configures and starts 1..3 PWM subchannels on 1 PWM clock channel. The shape of the PWM signals are specified with PWM frequency and duty cyckle.
pwm_clock_channel | IN: PWM clock channel: 0 or 1 | |
pwm_frequency | IN: PWM frequency (in Hz): ~10.0 ... ~400000.0 | |
subchannels | IN: 3 PWM subchannel config for subchannels 1, 2, 3 |
Rc Mio::AdjustPWMOut | ( | int | pwm_clock_channel, | |
PWMClockSpeed | pwm_clock_speed, | |||
int | pwm_period, | |||
PWMOutSubchannelConfig[] | subchannels | |||
) | [inline] |
Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.
Adjust ongoing PWM genration period width and shape on 1...3 PWM subchannels. The adjustment is made after the current PWM period has ended and before the next PWM period starts, to minimize glitches in the generated signals.
pwm_clock_channel | IN: PWM clock channel: 0 or 1 | |
pwm_clock_speed | IN: PWM clock speed | |
pwm_period | IN: PWM period width (in PWM clock ticks): 1 ... 65536 | |
subchannels | IN: PWM subchannel config for subchannels 1, 2, 3 |
Rc Mio::AdjustPWMOut | ( | int | pwm_clock_channel, | |
float | pwm_frequency, | |||
PWMOutSubchannelConfig2[] | subchannels | |||
) | [inline] |
Adjust ongoing PWM output (genration) on 1...3 PWM subchannels.
Adjust ongoing PWM genration frequency and duty cycle on 1...3 PWM subchannels. The adjustment is made after the current PWM period has ended and before the next PWM period starts, to minimize glitches in the generated signals.
pwm_clock_channel | IN: PWM clock channel: 0 or 1 | |
pwm_frequency | IN: PWM frequency (in Hz): ~10.0 ... ~400000.0 | |
subchannels | IN: 3 PWM subchannel config for subchannels 1, 2, 3 |
Rc Mio::StartPWMIn | ( | int | pwm_clock_channel, | |
PWMInSubchannelConfig[] | subchannels | |||
) | [inline] |
Start PWM input (measurement) on 1...4 PWM subchannels.
Configure a PWM clock channel in PWM input mode with 20MHz clock speed. A PWM clock channel in input mode has 4 independent subchannels which can measure PWM signals.
The subchannels are mapped onto the physical Mio.Ports as follows:
PWM clock channel 0: subchannel 0 Mio.Port.P30 subchannel 1 Mio.Port.P29 subchannel 2 Mio.Port.P28 subchannel 3 Mio.Port.P27 PWM clock channel 1: subchannel 0 Mio.Port.P26 subchannel 1 Mio.Port.P25 subchannel 2 Mio.Port.P24 subchannel 3 Mio.Port.P23
When a measurement on a subchannel becomes active (using the 'config' bits in this function or using SetPWMInMode()), it will start to capture the edges of the PWM signal, up to the number of edges specified in 'edges'. When the specified number of edges has been captured, the subchannel enters idle mode. The number of edges captured so far, and the total halfperiod and period times can be polled with GetPWMInResult(). A new measurement on the subchannel can be started with SetPWMInMode().
The PWM input implementation in MIO is software assisted meaning that a software interrupt is generated in the MIO board for each edge that is captured. For reliable measurements, it's important not to overflow MIO with interrupts. MIO can reliably capture signals up to 10 kHz (minimum halfperiod pulse width is 50 us) on one subchannel. If two subchannels are used simultaneously, the maximum signal is 5 kHz, tree subchannels is 2.5 kHz, etc. If several high-frequency signals needs to be measured, the measurements should be done sequentially on one subchannel at a time. I.e. only one subchannel should be active at a time, and the other in idle mode. Sequential measurement can be acheived using SetPWMInMode().
pwm_clock_channel | IN: PWM clock channel: 0 or 1 | |
subchannels | IN: 4 PWM subchannel config for subchannels 0, 1, 2, 3 |
Set mode for a PWM input subchannel.
Set the PWM input subchannel mode to one of the following:
Mio.PWMInMode.Idle // Set subchannel in idle mode Mio.PWMInMode.Active // Set subchannel in active mode (force start of a new measurement) Mio.PWMInMode.ActivateIfIdle // Set subchannel in active mode only if currently in idle mode
pwm_clock_channel | IN: PWM clock channel: 0 or 1 | |
pwm_subchannel | IN: PWM subchannel: 0, 1, 2 or 3 | |
mode | IN: PWM mode for this subchannel |
Rc Mio::GetPWMInResult | ( | out uint | total_halfperiod_time, | |
out uint | total_period_time, | |||
out int | edges_captured, | |||
int | pwm_clock_channel, | |||
int | pwm_subchannel | |||
) | [inline] |
Get measurement result from a PWM input subchannel.
GetPWMInResult() is used to check (poll) the current measurement result for a specific PWM input subchannel. The function returns the number of PWM edges captured so far, along with the total (accumulated) PWM halfperiod and period time in 50 ns ticks. The number of edges a measurement will capture was specified in StartPWMIn(). The following can be derived from the parameters received from GetPWMInResult():
Initial edge captured if: edges_captured >= 1
Measurement completed if: edges_captured >= subchannels[n].edges
Number of periods captured: (edges_captured - 1) / 2
The following can be calculated when at least 1 period (3 edges) has been captured:
Duty cycle in percent: (100.0 * total_halfperiod_time) / total_period_time
Frequency in Hz: ((edges_captured - 1) / 2) / (total_period_time * 50.0E-9)
Period time in ms: total_period_time * 50.0E-6 / ((edges_captured - 1) / 2)
First halfperiod time in ms: total_halfperiod_time * 50.0E-6 / ((edges_captured - 1) / 2)
Second halfperiod time in ms: (total_period_time - total_halfperiod_time) * 50.0E-6 / ((edges_captured - 1) / 2)
Apart from measuring PWM periods, PWM input mode can also be used to measure the width of single pulses. Number of edges should then be set to 2, and pulse polarity accordingly (Mio.PWM_POL_0 or Mio.PWM_POL_1) using StartPWMIn(). In this case, when 2 edges has been captured, total_halfperiod_time will contain the pulse width (in 50 ns ticks) and total_period_time will be zero. Please note that this is a special measurement case, as normally, when more than 2 edges are captured, total_halfperiod_time and total_period_time will only be updated at the end of each captured PWM period.
total_halfperiod_time | OUT: Total halfperiod time (in 50 ns ticks) of all halfperiods captured | |
total_period_time | OUT: Total period time (in 50 ns ticks) of all halfperiods captured | |
edges_captured | OUT: Number of edges in the PWM signal that has been captured | |
pwm_clock_channel | IN: PWM clock channel: 0 or 1 | |
pwm_subchannel | IN: PWM subchannel: 0, 1, 2 or 3 |
Rc Mio::StopPWM | ( | int | pwm_clock_channel | ) | [inline] |
Stop all PWM input/output on the selected PWM clock channel.
Stop all PWM input/output on the slected PWM clock channel and release the Mio_Ports.
pwm_clock_channel | IN: PWM clock channel: 0 or 1 |
bool Mio::OpenComPort | ( | string | port | ) | [inline] |
Open communication port to MIO board.
port | IN: COM-port name, e.g. "COM1" |
bool Mio::IsOpen | ( | ) | [inline] |
Check if the communication port is open.
virtual void Mio::DispatchOutOfBandMessage | ( | MioMsgId | msg_id, | |
int | payload_len, | |||
byte[] | payload | |||
) | [inline, protected, virtual] |
"Call-back" for out-of-band messages received from MIO.
This is a call-back for out-of-band messages received from MIO. Out-of-band messages are sent on MIO's own initiative and can be received by the host at any time. Implement this function in the derived class to handle the messages.
msg_id | IN: Message id | |
payload_len | IN: Payload length | |
payload | IN: Ptr to payload |
const uint Mio::CommunicationSpeed = 125000 |
For internal use only.
MIO <--> host communication speed in bps