Netduino home hardware projects downloads community

Jump to content


Photo

Use Pins Enum in clas constructor


  • Please log in to reply
5 replies to this topic

#1 JR.NET

JR.NET

    Member

  • Members
  • PipPip
  • 15 posts

Posted 02 November 2011 - 08:24 PM

Hello,

I would like to set certain pins in my class constructor. I've tried the following but without any luck:

        PWM PWMpinENA;
        InputPort DirectionPinIN1;
        InputPort DirectionPinIN2;
        SecretLabs.NETMF.Hardware.AnalogInput ReadmAPin;
        InterruptPort RPMpin;

        public MotorControl(Pins pwmpin, Pins Direction1, Pins Direction2, Pins mapin, Pins rpmpin)
        {
            PWMpinENA = new PWM(pwmpin);
            DirectionPinIN1 = new InputPort(Direction1, true, ResistorModes.PullUp);
            DirectionPinIN2 = new InputPort(Direction2, true, ResistorModes.PullUp);
            ReadmAPin = new SecretLabs.NETMF.Hardware.AnalogInput(mapin);

            RPMpin = new InterruptPort(rpmpin, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLevelHigh);
            RPMpin.OnInterrupt += new NativeEventHandler(RPMpin_OnInterrupt);

        }

The class initiation would be:

MotorControl MotorLeft = new MotorControl(Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D5, Pins.GPIO_PIN_A1, Pins.GPIO_PIN_D10);

However this is not correct. Can anyone point me in the right direction?

Thanks in advance.

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 November 2011 - 08:38 PM

Strange, that should work. I've done the same here: http://netmftoolbox....iew/8751#134105 Which 'using' lines do you have? The Pins enumeration requires SecretLabs.NETMF.Hardware.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1561 posts
  • LocationCzech Republic

Posted 02 November 2011 - 08:43 PM

The type of Pins enumeration values is actually Cpu.Pin, so you'd need to change constructor prototype like the following:

public MotorControl(Cpu.Pin pwmpin, Cpu.Pin direction1, Cpu.Pin direction2, Cpu.Pin mapin, Cpu.Pin rpmpin)
{
  ...
}


#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 November 2011 - 08:51 PM

The type of Pins enumeration values is actually Cpu.Pin, so you'd need to change constructor prototype like the following:

public MotorControl(Cpu.Pin pwmpin, Cpu.Pin direction1, Cpu.Pin direction2, Cpu.Pin mapin, Cpu.Pin rpmpin)
{
  ...
}

Oh true, missed that! :o
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 JR.NET

JR.NET

    Member

  • Members
  • PipPip
  • 15 posts

Posted 02 November 2011 - 09:01 PM

Thanks (and to Stefan: Dank je!!) I am writing (yet another probably) a motor driver that can also maintain a certain RPM (using an encoder) instead of only PWM values. I am building a (quite big) tank (with massive DIY tracks) that use two motors to drive it. With an earlier version that only used PWM I has speed sync issues. Cheers.

#6 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 02 November 2011 - 09:13 PM

I am writing (yet another probably) a motor driver

Yep, you're correct :D I recognise your code and have written something simular once myself. But it's very educating writing code. Helps you understand the device. :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2010-2014 Secret Labs LLC  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.