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

NetMF Toolbox PWM code


  • Please log in to reply
13 replies to this topic

#1 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 26 November 2012 - 12:11 AM

Hi,

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


Cheers,

Andy

#2 tim c

tim c

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 26 November 2012 - 01:19 AM

Which PWM dll do you have selected in your references?

#3 Stefan

Stefan

    Moderator

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

Posted 26 November 2012 - 07:02 AM

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.
"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

#4 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 26 November 2012 - 10:21 PM

Hi Stefan,

Thanks that was a silly mistake :rolleyes:, 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);
            	}
        	}
    	}
	}
}


#5 Stefan

Stefan

    Moderator

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

Posted 27 November 2012 - 06:58 AM

your code looks ok, maybe it's the type of fan that's an issue?
"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

#6 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 27 November 2012 - 08:35 AM

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

#7 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 27 November 2012 - 08:58 AM

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.

#8 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 27 November 2012 - 09:31 AM

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?

#9 Stefan

Stefan

    Moderator

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

Posted 27 November 2012 - 09:56 AM

One thing though how come the Netduino.PWM(....) didn't work as per the example in the toolbox?

You also have to add Secretlabs.NETMF.Hardware.PWM.dll for that in 4.2
"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

#10 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 27 November 2012 - 04:22 PM

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?

#11 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 27 November 2012 - 05:24 PM

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

#12 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 28 November 2012 - 12:49 AM

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

#13 Stefan

Stefan

    Moderator

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

Posted 28 November 2012 - 04:06 PM

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

Interesting, could you maybe zip the full project? That way I can look at all references and try to see what's wrong.
"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

#14 mcinnes01

mcinnes01

    Advanced Member

  • Members
  • PipPipPip
  • 325 posts
  • LocationManchester UK

Posted 28 November 2012 - 09:29 PM

Hi Stefan, Please find attached the project, its probably something I'm missing but hope it helps. Cheers, Andy

Attached Files






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.