5.c. 0x83 & 0x84: Get & Set Configuration Parameter
The qik has four configuration parameters that are saved in non-volatile memory, and uses commands 0x83 and 0x84 to read and write these parameter values, respectively. The parameters are numbered as follows:
- 0: Device ID
This parameter determines which device ID the unit will respond to when the Pololu protocol is used. It has a default value of 9 (0x09 in hex) and can be set to any value from 0 – 127. When setting this parameter, you should only have one qik on your serial line at a time.
- 1: PWM Parameter
This parameter determines frequency and resolution of the pulse width modulation (PWM) signal used to control motor speed. Note that setting this parameter while the motors are running causes them to stop.
The least significant bit (bit 0) selects for 7-bit resolution when cleared (i.e. full motor speed is 127) and 8-bit resolution when set (i.e. full motor speed is 255). A PWM with 7-bit resolution has twice the frequency of one with 8-bit resolution.
Bit 1 of this parameter selects for high-frequency mode when cleared and low-frequency mode when set. Using high-frequency mode puts the PWM frequency outside the range of human hearing if you are also in 7-bit mode (or very close to it if you are in 8-bit mode), which can help you decrease motor noise. Using low frequency mode has the benefit of decreasing power losses due to switching.
The default value for this parameter is 0 (high-frequency 7-bit mode, resulting in a PWM frequency of 31.5 kHz).
Valid values for this parameter are:
- 0 = high-frequency, 7-bit mode (PWM frequency of 31.5 kHz, which is ultrasonic)
- 1 = high-frequency, 8-bit mode (PWM frequency of 15.7 kHz)
- 2 = low-frequency, 7-bit mode (PWM frequency of 7.8 kHz)
- 3 = low-frequency, 8-bit mode (PWM frequency of 3.9 kHz)
- 2: Shutdown Motors on Error
When this parameter has a value of 1, both motors M0 and M1 are stopped as a safety precaution whenever an error occurs; otherwise, if this parameter has a value of 0, errors will not affect the motors. For more information on the various types of errors that can occur, see Section 5.b. This parameter has a default value of 1 (shut down the motors on any error) and valid values for this parameter are 0 or 1.
- 3: Serial Timeout
When this parameter has a value of 0, the serial timeout feature is inactive. Otherwise, the value of this parameter controls how much time can elapse between receptions of valid command packets before a serial timeout error is generated. This can be used as a general safety feature to allow the qik to identify when communication with the controlling device is lost and shut down the motors as a result (assuming the shutdown motors on error parameter set to a value of 1).
The timeout duration is specified in increments of 262 ms (approximately a quarter of a second) and is calculated as the lower four bits (which are interpreted as a number from 0 – 15) times two to the upper three bits (which are interpreted as a number from 0 – 7). If the lower four bits are called x and the upper three bits are called y, the equation for the length of the timeout duration would be:
timeout = 0.262 seconds * x * 2y
For example, if the timeout parameter is set as 0x5E (01011110 in binary), we have that x = 1110 (binary) = 14 (decimal) and y = 101 (binary) = 5 (decimal), which results in a timeout duration of
0.262s * 14 * 25 = 117 seconds.
The maximum timeout duration (arising from a parameter value of 0x7F, or 127 in decimal) is 8.32 minutes and the minimum timeout duration (arising from a parameter value of 1) is 262 ms.
This parameter has a default value of 0 (serial timeout disabled) and can be set to any value from 0 – 127.
Command 0x83: Get Configuration Parameter
Compact protocol: 0x83, parameter number
Pololu protocol: 0xAA, device ID, 0x03, parameter number
This command lets you request the current value of any of the four configuration parameters detailed above. This command will cause the qik to transmit a single byte that represents the requested parameter value. If you request an invalid parameter (i.e. if parameter number ≥ 4), the value transmitted by the qik should be 0xFF (255 in decimal) and a format error will be generated.
Command 0x84: Set Configuration Parameter
Compact protocol: 0x84, parameter number, parameter value, 0x55, 0x2A
Pololu protocol: 0xAA, device ID, 0x04, parameter number, parameter value, 0x55, 0x2A
This command lets you set the value of any of the four configuration parameters detailed above. The final two bytes of the command packets are format bytes that make it more difficult for this command to be unintentionally or accidentally sent, as might result from a noisy serial connection or buggy code. If either of the format bytes differs from the expected value, the command is ignored and a format error is generated.
It takes the qik approximately 4 ms to finish processing this command, at which point the qik will transmit a single return byte that contains information about whether the process was successful. You should not send commands to the qik until you have received this return byte, or until at least 4 ms have elapsed. The return byte can have the following values:
- 0: Command OK (success)
- 1: Bad Parameter (failure due to invalid parameter number)
- 2: Bad value (failure due to invalid parameter value for the specified parameter number)
Failure will result in a format error.
Once you have set the value of a configuration parameter, that value will be saved even if the unit is unplugged or reset.