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.
If you want to create a small repro (<20 lines of code) that changes the PWM of the onboard LED and post it...we'll be happy to replay it here and provide a solution directly.
Would that be something like the file I attached in my first post and the modified version I attached in my latest post?
So I attach a copy of the solution and would ask if someone would like to open the solution in VS2012 and run the code on a netduino plus with 4.2.0.1 firmware and tell me if it works or not.
I'm waiting for the delivery of a Plus2 before I revisit this properly again but in the meantime if the attached sample assists then great; once again thanks for your help.
The plus2 arrived and the PWM code works fine - so I'll mark this thread as solved - shame the plus2 is faulty (no Ethernet connectivity - no led on pcb or on network switch) and is about to be returned.
[font="arial, helvetica, sans-serif;"]I have a netduno plus - version 1 (Rev a pcb). I want to use VS2012 Professional to develop code so I believe I need the following[/font]
[font="arial, helvetica, sans-serif;"]Netduino 4.2 Firmware (because the 4.3 firmware for the netduino plus is not yet available)[/font]
[font="arial, helvetica, sans-serif;"]I followed the instructions at http://www.geekality...irmware-update/ to update the firmware which involves[/font]
[font="arial, helvetica, sans-serif;"]Short 3v3 to small pad near Digital I/O 0[/font]
[font="arial, helvetica, sans-serif;"]When I execute the following code from VS2012 all is well and the blue led flashes - I can edit the time delay and redeploy the code successfully.[/font]
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
namespace _1000_HelloWorld
{
public class Program
{
public static void Main()
{
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
lcd myLcd = new lcd();
{
bool ledState = false;
while (true)
{
ledState = !ledState;
led.Write(ledState);
Thread.Sleep(500);
}
}
}
}
public class lcd
{
public lcd()
{
//PWM backlightPwm0 = new PWM(Cpu.PWMChannel.PWM_5, 10, 100, false);
}
}
}
[font="arial, helvetica, sans-serif;"]However when I un-comment the PWM line the code deploys successfully but does not run and not only does VS2012 become un-responsive when stopping the “execution” but I need to repeat 1) through 6) in order to try again![/font]
[font="arial, helvetica, sans-serif;"]I've attached the project files as a zip archive.[/font]
[font="arial, helvetica, sans-serif;"]I'm very probably doing something wrong or have incompatible hardware/software/firmware and would be grateful for a pointer because I can now flash new firmware without need to consult the documentation having repeated the process several times on both my Windows 8 desktop and Wndows 7 laptop machines.[/font]
HI dbradshaw,
Cpu.PWMChannel.PWM_5 won't work on Netduino Plus 1. The new gen2 Netduinos have 6 PWM channels (0-5), but the gen1 gear only have 4 PWM channels (0-3).
I'd also recommend using PwmChannels.PWM_PIN_D# to choose the PWM channel. That way you'll get an exception if you try to use one of the new gen2 channels...and it's easy to tell which pin is used.
Welcome to the Netduino community,
Chris
Thanks for the advice - I was wondering how to sensibly map the actual pins to the PWM channels.
PWM backlightPwm0 = new PWM(PWMChannels.PWM_PIN_D3, 10, 100, false);
The above is much more sensible - however it still doesn't run and still corrupts the board. I'm beginning to think the best way forward is to get a Plus 2 which would use 4.3 firmware.
Has anyone used PWM successfully on 4.2 firmware with 4.3 SDK?
Hi dbradshaw,
In your PWM constructor, your period is 10us and your duration is 100us.
Period needs to be at least as long as the duration. Duration is the amount of time that the PWM is held high.
If you were looking for 100% dutycycle instead, use the constructor with doubles and specify the dutyCycle parameter as 1.0.
Does that help?
Chris
Sorry but any one of the following lines cause the board to be trashed. I'm beginning to remember why I put the netduino plus back in an anti-static bag two years ago just after I first purchased them - so much promise but soooooooooooo frustrating.
//PWM backlightPwm0 = new PWM(PWMChannels.PWM_PIN_D3, 10, 100, false);
//PWM backlightPwm0 = new PWM(PWMChannels.PWM_PIN_D3, 100, 10, false);
//PWM backlightPwm1 = new PWM(PWMChannels.PWM_ONBOARD_LED, 100, 10, PWM.ScaleFactor.Milliseconds, false);
Okay, none of those three lines of code will work. Let me help tweak each of them with you...
PWM sample #1
PWM backlightPwm0 = new PWM(PWMChannels.PWM_PIN_D3, 10, 100, false);
This dutyCycle is being set to 10,000% (value of 100, range is 0.0-1.0). If you change the constructor as follows, it should work for you:
PWM backlightPwm0 = new PWM(PWMChannels.PWM_PIN_D3, 10, 1.0, false);
PWM sample #2
PWM backlightPwm0 = new PWM(PWMChannels.PWM_PIN_D3, 100, 10, false);
Sorry, I glanced at the constructor earlier and didn't realize you were using the frequency and dutyCycle constructor. So my advice wasn't terribly helpful. Please ignore For the solution, see the code sample above this one.
PWM sample #3
PWM backlightPwm1 = new PWM(PWMChannels.PWM_ONBOARD_LED, 100, 10, PWM.ScaleFactor.Milliseconds, false);
100 milliseconds is too long of a period for 16-bit PWM. 65ms is about the longest period you can get. If you change the ScaleFactor to MicroSeconds (1/1000th of a millisecond) it should work for you.
We're going to take a long look at how the new PWM classes handle invalid parameters and see if we can throw some exceptions. Exceptions would be a much happier way to handle this rather than having NETMF get grumpy and asserting.
I apreciate your efforts to help me and either we will resolve this and I'll become a convert to Netduino or I'll put the Netduino back in its nice warm anti-static bag and go back to AVR Studio and GCC - where at least I know what I'm doing.
Every time I try this as a solution and it fails I have to wipe the board, install the bootloader and then install the micro framework (so I've done this three times this morning - each line un-commented seperately and the second one with the onboard led flash disabled to check it didn't interfere with using PWM on the led).
If this is a coding error on my part (e.g. invalid values) then the code not working or working in an unexpected way fine - but having to reflash the board is a pretty hefty price to pay for a typo.
Dave
//PWM backlightPwm0 = new PWM(PWMChannels.PWM_PIN_D3, 10, 0.60, false);//PWM backlightPwm1 = new PWM(PWMChannels.PWM_ONBOARD_LED, 100, 10, PWM.ScaleFactor.Microseconds, false);
(On the plus side I've found the code tags in the forum editor)
you cant use too low frequenzy (iam not sure whats the smallest value is you can use, theres a thread about it, gutworks explained it there)
first value is the pin, second is the freuqenzy in hz, thrid is the duty cycle in percent, 4th is the inverting setting (like 0.1f duty gets to 0.9f than -
thats just that you can use the same code for different external circiuts, cos it makes a difference wich transistor and such you choose, npn, pnp)
That also doesn't make any difference - I would expect the compiler to warn if it explicitly needs a float; trying 1000 for the frequency also made no difference.
I'm still concerned that it trashes the bootloader and/or framework - at the end of the day all the PWM code needs to do is set a few bits in some counter timer registers and put a couple of 8 bit values in some more registers - even if the values were rubbish why does the whole board become unresponsive?
Either I have
Wrong/incompatible versions of libraries or
I have missed something in the answers above or
It doesn't work or
Something else (suggestions on a postcard)
So I attach a copy of the solution and would ask if someone would like to open the solution in VS2012 and run the code on a netduino plus with 4.2.0.1 firmware and tell me if it works or not.
If it works for someone else then it eliminates 2.
If it works and someone else has different versions of firmware or libraries then I might be able to find out what I need to change - particularly if they can post the output from MFDeploy - Target capabilities for me to compare with mine - or similar info from their dev environment.
If it doesn't work for someone else it might be 3 and I can take comfort in the knowledge that at I am not alone.
Fortunately this is not mission critical for me - I only added an LCD to have a status display and the PWM was only a test to control the backlight as the first stage after HelloWorld/BlinkLed test program :-)
Hi dbradshaw,
If you want to create a small repro (<20 lines of code) that changes the PWM of the onboard LED and post it...we'll be happy to replay it here and provide a solution directly.
And yes, you do need to call PWM.Start() to start the PWM objects that are created.
Also...what is probably happening with the out-of-range arguments is that the native code side of NETMF is not properly throwing an ArgumentException. We're currently looking into that with the 4.2.2.3 release. Unfortunately when the native side asserts, the thread scheduler is suspended so the board appears to be unresponsive. You can usually work around this by pressing the ERASE button in MFDeploy immediately after plugging in your board...to erase the current app...but the nuclear option of erase-and-reflash-the-board always works as a backup backup too.
BTW...the minimum PWM frequency is around 32Hz. Maximum PWM frequency is 1MHz.
Does that help at all?
Chris
If you want to create a small repro (<20 lines of code) that changes the PWM of the onboard LED and post it...we'll be happy to replay it here and provide a solution directly.
Would that be something like the file I attached in my first post and the modified version I attached in my latest post?
So I attach a copy of the solution and would ask if someone would like to open the solution in VS2012 and run the code on a netduino plus with 4.2.0.1 firmware and tell me if it works or not.
I'm waiting for the delivery of a Plus2 before I revisit this properly again but in the meantime if the attached sample assists then great; once again thanks for your help.
The plus2 arrived and the PWM code works fine - so I'll mark this thread as solved - shame the plus2 is faulty (no Ethernet connectivity - no led on pcb or on network switch) and is about to be returned.
Hi Dave,
We'd love to get the Netduino Plus 2 back into engineering at some point. We test the network feature on every board before it ships...so it would be very helpful to determine how that feature stopped working in-field. First instinct is that it could be a flaky pin in the Ethernet jack or shipping-related damage.
Chris
I've ordered a second board (which I'll test before upgrading the firmware to 4.3 beta) - if the second board works and I think the first one is really faulty (I never checked the Ethernet LEDs before upgrading the firmware) I'll be happy to post it direct to you rather than return it to Amazon.
I did waggle the Ethernet plug and press on the connector - but not even a flicker of a led on pcb or network switch.