Exemplo n.º 1
0
        //--//

        /// <summary>
        /// Build an instance of the PWM type
        /// </summary>
        /// <param name="channel">The channel to use</param>
        /// <param name="frequency_Hz">The frequency of the pulse in Hz</param>
        /// <param name="dutyCycle">The duty cycle of the pulse as a fraction of unity.  Value should be between 0.0 and 1.0</param>
        /// <param name="invert">Whether the output should be inverted or not</param>
        public PWM(Cpu.PWMChannel channel, double frequency_Hz, double dutyCycle, bool invert)
        {
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            if(hwProvider == null) throw new InvalidOperationException();

            m_pin = hwProvider.GetPwmPinForChannel(channel);
            m_channel = channel;
            //--//
            m_period = PeriodFromFrequency(frequency_Hz, out m_scale);
            m_duration = DurationFromDutyCycleAndPeriod(dutyCycle, m_period);
            m_invert = invert;
            //--//
            try
            {
                Init();
                
                Commit();
                
                Port.ReservePin(m_pin, true);
            }
            catch
            {
                Dispose(false);
            }
        }
Exemplo n.º 2
0
 public Fan(Cpu.PWMChannel pin)
 {
     this.pwmChannel = pin;
     this.speed = Speed.None;
     this.frequency = (double)100;
     Start();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initialise the Servo motor
        /// </summary>
        /// <param name="pin">PWM Pin</param>
        /// <param name="minPulse">minimum pulse durat  ion for servo in microseconds</param>
        /// <param name="maxPulseDuration">maximum pulse duration for servo in microseconds</param>
        /// <param name="maxDegrees">maximum degrees the servo can sweep</param>
        public ServoPwm(Cpu.PWMChannel pin, uint period, uint minPulseDuration, uint maxPulseDuration, uint maxDegrees, string name)
            : base(name, "servopwm")
        {
            _pin = pin;
            _period = period;
            _minPosition = minPulseDuration;
            _maxPosition = maxPulseDuration;
            _maxDegrees = maxDegrees;

            Initialise();
        }
Exemplo n.º 4
0
        public NativePwmOutput(Socket socket, Socket.Pin pin, bool invert, Module module, Cpu.PWMChannel channel)
        {
            if (channel == Cpu.PWMChannel.PWM_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Seven, Socket.Pin.Nine, "PWM", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "PWM");
            }

            _channel = channel;
            _socket = socket;
            _invert = invert;
        }
Exemplo n.º 5
0
        public static IStepSequencer GetSimulatedStepperMotor(Cpu.Pin direction1, Cpu.PWMChannel power1, Cpu.Pin direction2, Cpu.PWMChannel power2)
        {
            var direction1Port = new OutputPort(direction1, false);
            var direction2Port = new OutputPort(direction2, false);
            var bridge1        = new HBridgeLedSimulator(direction1Port, power1);
            var bridge2        = new HBridgeLedSimulator(direction2Port, power2);

            return(GetMicrosteppingStepperMotor(256, bridge1, bridge2));
        }
Exemplo n.º 6
0
 /// <summary>
 ///     Attach the servo to a specific PWM pin and set the minimum and maximum pulse
 ///     widths for the 0 and 180 degree angles.
 /// </summary>
 /// <param name="pin">PWM pin to use for this servo.</param>
 /// <param name="minimum">Minimum pulse width for the servo.  The minimum width define the value used for 0 degrees.</param>
 /// <param name="maximum">Maximum pulse width for the servo.  The maximum value determines the value used for 180 degrees.</param>
 private void Attach(Cpu.PWMChannel pin, int minimum = 544, int maximum = 2400)
 {
     Pin = pin;
     MinimumPulseWidth = minimum;
     MaximumPulseWidth = maximum;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Piezo speaker driver and notes and playback manager
 /// </summary>
 /// <param name="pin">From the SecretLabs.NETMF.Hardware.NetduinoPlus.PWMChannels namespace</param>
 /// <param name="name">Unique identifying name for command and control</param>
 public Piezo(Cpu.PWMChannel pin, string name)
     : base(name, "piezo")
 {
     _piezo = new PWM(pin, 0, 0, PWM.ScaleFactor.Microseconds, false);
     _piezo.Start();
 }
Exemplo n.º 8
0
 /// <summary>
 ///     Create a new instance of the Servo class.  This call is equivalent to creating a new instance and
 ///     then calling the <i>Attach</i> method.
 /// </summary>
 /// <param name="pin">PWM pin to which the servo is attached.</param>
 /// <param name="minimum">Minimum value for the pulse width, the default is 544.</param>
 /// <param name="maximum">Maximum value for the pulse width, the default value is 2400.</param>
 public Servo(Cpu.PWMChannel pin, int minimum = 544, int maximum = 2400)
 {
     Attach(pin, minimum, maximum);
 }
Exemplo n.º 9
0
        PWM GetPwm(Cpu.PWMChannel pwmChannel)
        {
            var pwm = new PWM(pwmChannel, 64000.0, 0.0, false);

            return(pwm);
        }
Exemplo n.º 10
0
 public PWM(Cpu.Pin pin)
 {
     Cpu.PWMChannel channel = GetChannelFromPin(pin);
     _pwm = new Microsoft.SPOT.Hardware.PWM(channel, 100, 0, Microsoft.SPOT.Hardware.PWM.ScaleFactor.Microseconds, false);
 }
 public HBridgeLedSimulator(OutputPort directionIndicator, Cpu.PWMChannel powerPwmChannel)
 {
     this.directionIndicator = directionIndicator;
     powerLevelIndicator     = new PWM(powerPwmChannel, 100.0, dutyCycle: 0.5, invert: true);
     powerLevelIndicator.Start();
 }
 override public Cpu.Pin GetPwmPinForChannel(Cpu.PWMChannel channel)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
 /// <summary>
 /// Initialise the Servo motor with default Jaycar Hobby Tech YM-2763, //timings set for the Jaycar Hobby Tech YM-2763, Pulse Width: 800 - 2200µs, Rotation Angle: 120
 /// </summary>
 /// <param name="pin">PWM Pin</param>
 public ServoPwm(Cpu.PWMChannel pin, string name)
     : base(name, "servopwm")
 {
     _pin = pin;
     Initialise();
 }
Exemplo n.º 14
0
 public virtual Cpu.Pin GetPwmPinForChannel(Cpu.PWMChannel channel)
 {
     return(NativeGetPWMPinForChannel(channel));
 }
Exemplo n.º 15
0
 public NoiseMaker(Cpu.PWMChannel channel)
 {
     _channel = channel;
 }
Exemplo n.º 16
0
 public NativePwmOutput(Socket socket, Socket.Pin pin, bool invert, Module module, Cpu.PWMChannel channel)
 {
     if (channel == Cpu.PWMChannel.PWM_NONE)
     {
         Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Seven, Socket.Pin.Nine, "PWM", module);
         throw Socket.InvalidSocketException.FunctionalityException(socket, "PWM");
     }
     this._channel = channel;
     this._socket  = socket;
     this._invert  = invert;
 }
        public NativePwmOutput(Socket socket, Socket.Pin pin, bool invert, Module module, Cpu.PWMChannel channel)
        {
            if (channel == Cpu.PWMChannel.PWM_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Seven, Socket.Pin.Nine, "PWM", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "PWM");
            }

            _channel = channel;
            _socket  = socket;
            _invert  = invert;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initialise the Servo motor with default Jaycar Hobby Tech YM-2763, //timings set for the Jaycar Hobby Tech YM-2763, Pulse Width: 800 - 2200µs, Rotation Angle: 120
 /// </summary>
 /// <param name="pin">PWM Pin</param>
 public ServoPwm(Cpu.PWMChannel pin, string name)
     : base(name, "servopwm")
 {
     _pin = pin;
     Initialise();
 }
Exemplo n.º 19
0
 extern private Cpu.Pin NativeGetPWMPinForChannel(Cpu.PWMChannel channel);
Exemplo n.º 20
0
        /// <summary>
        /// Build an instance of the PWM type
        /// </summary>
        /// <param name="channel">The channel</param>
        /// <param name="period">The period of the pulse</param>
        /// <param name="duration">The duration of the pulse.  The value should be a fraction of the period</param>
        /// <param name="scale">The scale factor for the period/duration (nS, uS, mS)</param>
        /// <param name="invert">Whether the output should be inverted or not</param>
        public PWM(Cpu.PWMChannel channel, uint period, uint duration, ScaleFactor scale, bool invert)
        {
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            if (hwProvider == null) throw new InvalidOperationException();

            m_pin      = hwProvider.GetPwmPinForChannel(channel);
            m_channel  = channel;
            //--//
            m_period   = period;
            m_duration = duration;
            m_scale    = scale;
            m_invert   = invert;
            //--//
            try
            {
                Init();
                
                Commit();
                
                Port.ReservePin(m_pin, true);
            }
            catch
            {
                Dispose(false);
            }
        }
Exemplo n.º 21
0
 public ContServo(Cpu.PWMChannel servo_pin)
 {
     servo = new PWM(servo_pin, 20, 0, false);
     servo.Start();
 }