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.SetPulse equivalent in .NETMF 4.2


  • Please log in to reply
6 replies to this topic

#1 Anshul

Anshul

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 25 January 2014 - 10:25 PM

Is there a standard way of upgrading the PWM.SetPulse method from .NETMF4.1 to the newer "channel-based" PWM in .NETMF 4.2? I'm trying to port the following code:

public Tlc5940New(PWM gsclk, PWM blank, OutputPort xlat, OutputPort sin, OutputPort sclk)        {            GSCLKPin = gsclk;            BLANKPin = blank;            XLATpin = xlat;            SINPin = sin;            SCLKPin = sclk;            // Clear the channels, and disable the output            GSCLKPin.DutyCycle = 0;            BLANKPin.DutyCycle = 0;            XLATpin.Write(false);            SINPin.Write(false);            SCLKPin.Write(false);            GSCLKPin.SetPulse(gsclk_period, 1);            BLANKPin.SetPulse((gsclk_period * 4096), 1);                }

The error is happening on the lines GSCLKPin.SetPulse(gsclk_period, 1); and BLANKPin.SetPulse((gsclk_period * 4096), 1); because SetPulse is not supported by the new 4.2 libraries so I have to come up with equivalent code. I took this code from somewhere else so I do not know how exactly I should use the 4.2 PWM in place of this 4.1 code.

 

Any help is greatly appreciated.



#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 26 January 2014 - 08:28 PM

Hi Anshul,

 

I recall I had a few issues with the upgrade from v4.1 to v4.2. :(

 

I did manage to get the SetPulse method working:

PWM leftPwmPort = new PWM(Pins.GPIO_PIN_D6);leftPwmPort.SetPulse(20000, 0); // 20ms period (50Hz)

I think the trick was getting the correct combination of using statements to select the Secret labs enumeration and class rather than the Microsoft ones!

using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;	   // Pins enum

Hope this helps - Paul



#3 Anshul

Anshul

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 27 January 2014 - 01:31 AM

Paul,

 

In 4.2, I believe the way to instantiate a PWM is like the following:

PWM blank = new PWM(Cpu.PWMChannel.PWM_3, 10000, 0, false);

so the Pins enumeration won't matter since it requires the PWM "channel" instead of the pin. Are you sure your statements are from 4.2? Maybe from an earlier version of 4.2? Also because it's 4.2, the SetPulse method isn't available at all, from what I'm seeing at least. Are you able to get that code to work in 4.2?



#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 27 January 2014 - 07:35 PM

Nope, that is my v4.2 code - I just double cheked that I did not copy the code from my older v4.1 code.

I have a you tube video to prove it B).

 

I had to update everything to v4.2 to make the Ethernet work

 

I have a feeling the using statements affect the Pins enumeration and the PWM class.

 

The only other thing to say is that I am using this code on a Netuino Plus v1 (not a v2). So perhaps the your mention of it being an early version of 4.2 could be an issue.

 

I would try creating a new empty project with minimal using statements and see if you can get it working without any other baggage.

 

Let us know what happens - Paul



#5 Anshul

Anshul

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 28 January 2014 - 02:53 AM

I'm also using a Netduino Plus v1. I am definitely using NETMF 4.2 :

 

Posted Image

 

That is a picture of the PWM reference in my project. Whenever I type in SetPulse, Visual Studio marks it as a syntax error. Could you post your using statements and check the version of the Microsoft.SPOT.Hardware.PWM assembly in your project references? I am not doubting that you are correct, I'm just trying to figure out why it won't work on my machine. 



#6 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 28 January 2014 - 08:09 PM

Hi Anshul,

 

I am still using the Secret Labs PWM class - your screen shot is for the Microsoft one.

(How did you get to that display? - I tried a few things and could not find it.) EDIT: Found it!

 

I just ran up a test harness, this builds without errors, but I have not deployed it:

  • Open Visual Studio Express C# 2010
  • click New project
    • Select Netduino Plus 1 Application
    • Set name "Pwm_TestHarness", OK
  • File->Save All
  • From the Solution explorer, Open "Program.cs"
  • Replace code in Program.cs with:
using System;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace NetduinoPlusApplication1{	public class Program	{		public static void Main()		{			// write your code here			PWM secretLabsPwm = new PWM(Pins.GPIO_PIN_D5);			secretLabsPwm.SetPulse(20000, 10000);		}	}}

[color=#ff0000;]PWM class is initially underlined in red[/color]

  • In the Solution explorer, expand references
  • right click on [color=#0000ff;]Microsoft.SPOT.Hardware.PWM[/color] - click remove
  • right click on references, click Add Reference,
  • select [color=#0000ff;]SecretLabs.NETMF.Hardware.PWM[/color] (Bottom of list v4.2.2.0)
[*]Build solution
[*]Smile
[/list]

 

Hope this is the building block you need to get this going.

I remember this was very frustrating when I did it - Paul



#7 Anshul

Anshul

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 29 January 2014 - 02:52 PM

I see it now. Thanks for the help. Although I wanted to use this for porting some old code from 4.1 to 4.2, turns out that code is not working. So I wrote my own code and ended up not needing it at the moment :) But I will undoubtedly need it going forward and it's always good to know why there weird things are happening. 






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.