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 Issue with Netduino 4.2 SDK


Best Answer Chris Walker, 24 February 2013 - 11:37 PM

Hi Cal, You'll need to start the PWM. Try adding this:

led1.Start();
The new NETMF PWM classes are designed for some advanced scenarios. SerialPorts have to be opened in NETMF...and PWM channels need to be started. This is in part so that you can set up a bunch of PWM channels and then start them simultaneously. Does that get you up and running? Chris Go to the full post


  • Please log in to reply
6 replies to this topic

#1 Calabraun

Calabraun

    New Member

  • Members
  • Pip
  • 7 posts

Posted 24 February 2013 - 01:05 AM

After figuring out how to restore the firmware on my Netduino Plus 2 after bricking it the first time using PWM, I am at it again.  If I read correctly, there is a newer method for using PWM under 4.2? The problem I am having is that it's saying PWM only takes in one parm for the constructor using the 4.2 libs, however I see examples on the forums of people using more than one parm. The object browser also shows that PWM only takes one parm, and that I am definately using 4.2. Completely confused!

 

Error : 'SecretLabs.NETMF.Hardware.PWM' does not contain a constructor that takes 4 arguments

 

I have attached a screenshot...

 

-Cal

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 February 2013 - 01:58 AM

Hi Cal, Try removing the SecretLabs.NETMF.Hardware.PWM.dll assembly from your project references. Use Microsoft.SPOT.Hardware.PWM.dll instead (the new integrated PWM class). Chris

#3 Calabraun

Calabraun

    New Member

  • Members
  • Pip
  • 7 posts

Posted 24 February 2013 - 04:22 PM

Okay, thanks Chris.

 

I am now trying this code that uses Microsoft's PWM instead of yours, and no results from either my LED on pin 5, or even the onboard LED. It just stays off. I tried different DutyCycles between 0 and 1. Both pin 5 and the onboard LED work when I use OutputPort. Not sure why PWM is being so elusive for me!

 

 

 

//using System;
//using System.Net;
//using System.Net.Sockets;
//using System.Threading;
//using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
 
namespace NetduinoLedApplication
{
    public class Program
    {
        public static void Main()
        {
            PWM led1 = new PWM(PWMChannels.PWM_ONBOARD_LED, 100, .5, false); 
            led1.Frequency = 900;
            led1.DutyCycle = 1;
            while (true)
            {
                led1.DutyCycle = .9;
            }
 
        }
 
    }
}


#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 24 February 2013 - 05:33 PM

it should work.

 

i have some suggestions: first: your setting the freq and duty in the constructor, so the led.Frequency and duty after that is not needed, set the values you want there. (and ofc wherever you wanna change it)

 

also, try setting tghe invert parameter to true, maybe helps (depends on the circiut wich you connected the led)

 

and try:

 

Single test = 0.0f;

while (true)

{
led1.DutyCycle = test;
test+= 0.05f;
if(test > 1.0f)
{
test = 0.0f;
}
Thread.Sleep(100);
}


#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 February 2013 - 11:37 PM   Best Answer

Hi Cal, You'll need to start the PWM. Try adding this:
led1.Start();
The new NETMF PWM classes are designed for some advanced scenarios. SerialPorts have to be opened in NETMF...and PWM channels need to be started. This is in part so that you can set up a bunch of PWM channels and then start them simultaneously. Does that get you up and running? Chris

#6 Calabraun

Calabraun

    New Member

  • Members
  • Pip
  • 7 posts

Posted 25 February 2013 - 12:46 AM

Now that was a pretty silly omission on my part! Working great now, thanks!

 

Looking forward to new tutorials that go over these types of updated changes (PWM, etc).

 

-Cal



#7 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 25 February 2013 - 09:12 AM

wow i also forgot it had to be started first, i thought it just starts when initialized -.-

but well, its some time since i used it for testing.






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.