Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

PWM usage in custom class


Best Answer Chris Walker, 28 February 2013 - 11:03 PM

Hi Jeroen, If you add the following line to your code, you should be good to go :)

PWMspeedFwd.Start();
Does that get your PWM running? Chris Go to the full post


  • Please log in to reply
3 replies to this topic

#1 JR.NET

JR.NET

    Member

  • Members
  • PipPip
  • 15 posts

Posted 28 February 2013 - 09:47 PM

Hello,

 

I have a Netduino plus 2 and I am making a motor controller with it :)

 

I have a class with the folowing constructor:

 

# region MotorControl Constructor        public MotorControl(Cpu.PWMChannel pwmpinleft ,Cpu.PWMChannel pwmpinright, Cpu.Pin releasecontroller, Cpu.AnalogChannel analogpin, Cpu.Pin rpmpin, int mvToma, string name)        {                        Debug.Print("New controller motor instance created.");            PWMspeedFwd = new PWM(pwmpinleft, PWMFrequency, CurrentPWMFwd, false);            PWMspeedRev = new PWM(pwmpinright, PWMFrequency, CurrentPWMRev, false);            ReleaseController = new OutputPort(releasecontroller,true);            Debug.Print("PWM and release ports created.");

 

 

The class is created using the following line:

 

 /// <summary>        /// Left UGV motor        /// </summary>        public static MotorControl motorleft = new MotorControl(PWMChannels.PWM_PIN_D5, PWMChannels.PWM_PIN_D6, Pins.GPIO_PIN_D0, Cpu.AnalogChannel.ANALOG_0, Cpu.Pin.GPIO_Pin15, 20, "Motorleft");

 

However, it looks like the pwm pins are not initialized? When I want to measure the signal using a scope I get no signal.

 

Do I initialize the PWM pins the correct way?

 

I set PWM values using the following code:

 

PWMspeedFwd.DutyCycle = i;

 

With i varying between 0 and 1. Is this correct or should it be between 0 and 100 %?

 

Thanks in advance and with best regards,

 

Jeroen.



#2 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 28 February 2013 - 10:53 PM

Haven't used PWM much myself but I remember reading something lately about issues with initializers of static variables - are you seeing the dubug messages?

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 February 2013 - 11:03 PM   Best Answer

Hi Jeroen, If you add the following line to your code, you should be good to go :)
PWMspeedFwd.Start();
Does that get your PWM running? Chris

#4 JR.NET

JR.NET

    Member

  • Members
  • PipPip
  • 15 posts

Posted 01 March 2013 - 08:55 PM

Thanks, that solved the problem :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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