Exemple #1
0
    def enablePWM(self, initialDutyCycle):
        """Enable a PWM Output on this line.

        Allocate one of the 6 DO PWM generator resources.

        Supply the initial duty-cycle to output so as to avoid a glitch when
        first starting.

        The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
        less) but is reduced the higher the frequency of the PWM signal is.

        :param initialDutyCycle: The duty-cycle to start generating. [0..1]
        :type  initialDutyCycle: float
        """
        if self.pwmGenerator is not None:
            return
        self._pwmGenerator = hal.allocatePWM()
        hal.setPWMDutyCycle(self._pwmGenerator, initialDutyCycle)
        hal.setPWMOutputChannel(self._pwmGenerator, self.channel)
        self._pwmGenerator_finalizer = \
                weakref.finalize(self, _freePWMGenerator, self._pwmGenerator)
    def enablePWM(self, initialDutyCycle):
        """Enable a PWM Output on this line.

        Allocate one of the 6 DO PWM generator resources.

        Supply the initial duty-cycle to output so as to avoid a glitch when
        first starting.

        The resolution of the duty cycle is 8-bit for low frequencies (1kHz or
        less) but is reduced the higher the frequency of the PWM signal is.

        :param initialDutyCycle: The duty-cycle to start generating. [0..1]
        :type  initialDutyCycle: float
        """
        if self.pwmGenerator is not None:
            return
        self._pwmGenerator = hal.allocatePWM()
        hal.setPWMDutyCycle(self._pwmGenerator, initialDutyCycle)
        hal.setPWMOutputChannel(self._pwmGenerator, self.channel)
        self._pwmGenerator_finalizer = \
                weakref.finalize(self, _freePWMGenerator, self._pwmGenerator)
Exemple #3
0
def _freePWMGenerator(pwmGenerator):
    # Disable the output by routing to a dead bit.
    hal.setPWMOutputChannel(pwmGenerator, SensorBase.kDigitalChannels)
    hal.freePWM(pwmGenerator)
def _freePWMGenerator(pwmGenerator):
    # Disable the output by routing to a dead bit.
    hal.setPWMOutputChannel(pwmGenerator, SensorBase.kDigitalChannels)
    hal.freePWM(pwmGenerator)