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.
I have just downloaded the latest toolbox and have 4.2 installed on my netduino (standard). This is the first time I have used the new firmware for PWM and the first thing I noticed was that the constructor had more variables, such as period and duration.
I then took the code sample from codeplex for IPWM class from the toolbox, but I just get a list of errors on the code:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using Toolbox.NETMF;
using Toolbox.NETMF.NET;
using Toolbox.NETMF.Hardware;
namespace Fan_PWM
{
public class Program
{
IPWMPort Led1 = new Netduino.PWM(Pins.GPIO_PIN_D5);
Led1.StartPulse();
while (true)
{
for (uint Brightness = 0; Brightness < 100; ++Brightness)
{
Led1.SetDutyCycle(Brightness);
Thread.Sleep(100);
}
for (uint Brightness = 100; Brightness > 0; --Brightness)
{
Led1.SetDutyCycle(Brightness);
Thread.Sleep(100);
}
}
}
}
Am I missing something?
These are the errors:
Error 1 Invalid token '(' in class, struct, or interface member declaration c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 16 24 Fan PWM
Error 2 Invalid token '100' in class, struct, or interface member declaration c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 20 52 Fan PWM
Error 3 Type expected c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 20 52 Fan PWM
Error 4 Invalid token ')' in class, struct, or interface member declaration c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 20 69 Fan PWM
Error 5 Invalid token '(' in class, struct, or interface member declaration c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 22 34 Fan PWM
Error 6 Invalid token ')' in class, struct, or interface member declaration c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 22 45 Fan PWM
Error 7 Invalid token '(' in class, struct, or interface member declaration c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 23 29 Fan PWM
Error 8 A namespace cannot directly contain members such as fields or methods c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 25 13 Fan PWM
Error 9 Type or namespace definition, or end-of-file expected c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 31 5 Fan PWM
Error 10 Type or namespace definition, or end-of-file expected c:\users\andy\documents\visual studio 2010\Projects\Fan PWM\Fan PWM\Program.cs 32 1 Fan PWM
Your code isn't in a method, it's in the class itself. Try this:
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using Toolbox.NETMF;
using Toolbox.NETMF.NET;
using Toolbox.NETMF.Hardware;
namespace Fan_PWM
{
public class Program
{
public static void Main()
{
IPWMPort Led1 = new Netduino.PWM(Pins.GPIO_PIN_D5);
Led1.StartPulse();
while (true)
{
for (uint Brightness = 0; Brightness < 100; ++Brightness)
{
Led1.SetDutyCycle(Brightness);
Thread.Sleep(100);
}
for (uint Brightness = 100; Brightness > 0; --Brightness)
{
Led1.SetDutyCycle(Brightness);
Thread.Sleep(100);
}
}
}
}
}
You always need a main method, which contains your main app.
Thanks that was a silly mistake , I've been over my head in pcb design for the last few months and thought I'd have a little play with a few functions whilst I wait for my pcb's to come from china.
I amended the main, but I get an error on Netduino,PWM of the namespace doesn't exist, the resolve wants to add SecretLabs.NETMF.Hardware.Netduino.PWM, but then I get the error PWM does not exist in SecretLabs.NETMF.Hardware.Netduino?
Any clues?
PS I'm on 4.2.
Thanks again,
Andy
Edit:
Does this look right, it seems to deploy ok, although the fan I am controlling doesn't seem to show much variation in speed and definitely does not stop?
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using Toolbox.NETMF;
using Toolbox.NETMF.NET;
using Toolbox.NETMF.Hardware;
namespace Fan_PWM
{
public class Program
{
public static void Main()
{
IPWMPort Led1 = new Toolbox.NETMF.Hardware.IntegratedPWM(PWMChannels.PWM_PIN_D5); //(Pins.GPIO_PIN_D5);
Led1.StartPulse();
while (true)
{
for (uint Brightness = 0; Brightness < 100; ++Brightness)
{
Led1.SetDutyCycle(Brightness);
Debug.Print(Brightness.ToString());
Thread.Sleep(100);
}
for (uint Brightness = 100; Brightness > 0; --Brightness)
{
Led1.SetDutyCycle(Brightness);
Debug.Print(Brightness.ToString());
Thread.Sleep(100);
}
}
}
}
}
I did a meter reading on the PWM pin and gnd on the netduino, the voltage climbs to 1.83v around 50% and then begins to fall back to zero as it gets to 100% and then vice versa from 100% to 50% it climbs to 1.83v and then 50% to 0% it falls to 0v?
I was expecting 0% to 100% to be 0v to 3.3v right?
Andy
I guess the meter is showing average (or RMS) value, you'd probably need to increase the delay duration in Thread.Sleep(), so it has enough time to adapt. You should get 3.3 V for 100% duty cycle, yes.
I have increased the thread sleep to 500 and I still observe the above. The meter is on DC voltage up to 20V.
I have a logic analyser but I haven't used it yet, so if you can guide me what to connect to what I can give it a go and post my results?
Cheers.
Andy
One thing though how come the Netduino.PWM(....) didn't work as per the example in the toolbox?
I have increased the thread sleep to 500 and I still observe the above. The meter is on DC voltage up to 20V.
One thing crossed my mind - do you have the LED connected during measurement? Because if yes, the measured value could be the LED voltage drop (is it red?) or supply voltage minus the LED voltage drop. If you wanted to dig deeper, could you sketch the circuit, marking the measurement points?
I will try adding the PWM.dll, I didn't realise I needed to do that, thanks.
I'm not using a LED I have a transistor which controls a 2 wire pc fan and a 12v supply.
I will fritz the circuit when I get home no problem.
Thanks,
Andy
Hi,
Tried adding the PWM.dll from here C:\Program Files (x86)\Secret Labs\Netduino SDK\Assemblies\v4.2\SecretLabs.NETMF.Hardware.PWM.dll
And I still get the errors on netduino.PWM ?
Andy