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 Setup


  • Please log in to reply
2 replies to this topic

#1 Novice Alex

Novice Alex

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 27 August 2012 - 04:03 AM

Hi Guys,

I am trying to setup a PWM to generate constant pulse for my monitoring project.
Below are the codes.

Public WithEvents Supply As InterruptPort
Public PWM_Supply As New SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5)

Supply = New InterruptPort(Pins.GPIO_PIN_D0, False, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh)

Dim period As UInt32 = 1 * 1000 * 1000 '1 seconds
Dim duration As UInt32 = 5 * 100 * 1000 '0.5 seconds
PWM_Supply.SetPulse(period, duration)

After executing the last command "SetPulse", the below exception will be trigger
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.PWM.dll

Can anyone highlight the problem in this declaration?
Thanks in advance.

Regards,
Novice Alex

#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 27 August 2012 - 06:21 AM

I have not really verified that, but I don't think PWM is able to handle such long pulses. It is usually used for pulses that have duration of microseconds or milliseconds. You could use a timer instead.

#3 Victor M.

Victor M.

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts
  • LocationRio de Janeiro, Brazil

Posted 27 August 2012 - 11:20 AM

Hello Alex,
The problem is the very large value of period that you are using in your code. I don't know why but is could be possible because this PWM is a hardware PWM and the comparator register have a limit size. This code is working well:

Public WithEvents Supply As InterruptPort

	Sub Main()
    	' write your code here
    	Dim PWM_Supply As New SecretLabs.NETMF.Hardware.PWM(Pins.GPIO_PIN_D5)
   	

    	'Supply = New InterruptPort(Pins.GPIO_PIN_D0, False, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh)

    	Dim period As UInt32 = 1 * 1000 * 10  '1 seconds
    	Dim duration As UInt32 = 5 * 100 * 10 '0.5 seconds
    	PWM_Supply.SetPulse(CType(period, UInteger), CType(duration, UInteger))
	End Sub

[]s,
Victor




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.