<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _setSpeed(self, speed, motor, device):
 """ Set motor speed. This method takes into consideration the PWM frequency that the hardware is currently running at and limits the values passed to the hardware accordingly. :Parameters: speed : `int` Motor speed as an integer. Negative numbers indicate reverse speeds. motor : `str` A string value indicating the motor to set the speed on. device : `int` The device is the integer number of the hardware devices ID and is only used with the Pololu Protocol. """

        reverse = False

        if speed < 0:
            speed = -speed
            reverse = True

        # 0 and 2 for Qik 2s9v1, 0, 2, and 4 for 2s12v10
        if self._deviceConfig[device]['pwm'] in (0, 2, 4,) and speed > 127:
            speed = 127

        if speed > 127:
            if speed > 255:
                speed = 255

            if reverse:
                cmd = self._COMMAND.get('{}-reverse-8bit'.format(motor))
            else:
                cmd = self._COMMAND.get('{}-forward-8bit'.format(motor))

            speed -= 128
        else:
            if reverse:
                cmd = self._COMMAND.get('{}-reverse-7bit'.format(motor))
            else:
                cmd = self._COMMAND.get('{}-forward-7bit'.format(motor))

        if not cmd:
            msg = "Invalid motor specified: {}".format(motor)
            self._log and self._log.error(msg)
            raise ValueError(msg)

        self._writeData(cmd, device, params=(speed,))