Invert Pin - PWM on FEZ Hydra - VS2012, .NETMF 4.3, GHI NETMF v4.2

Hi All,

This is in part a continuation of this thread:

I wonder if anyone has an answer to this already?

My Problem: Apparently the Invert Pin Boolean is not working in the Method PWM. Where ‘false’ indicates that the Pin is not inverted:

If I was to change this Boolean to true, it appears that it is not working.

My Code:


using System;
using System.Threading;
using System.Collections;

// Microsoft Statements...
using Microsoft.SPOT;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Presentation.Controls;

// Gadgeteer Statements...
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

// Gadgeteer Statements...
using Gadgeteer.Networking;
using Gadgeteer.Modules.GHIElectronics;

namespace Hydra_PWM_TEST
public partial class Program
// ALLWAYS do Firmware Update...

// Config the PWM...
private PWM MyPWM1;
private PWM MyPWM2;

private uint Frequency = 900000;
private double Duty = 0.5;

// This method is run when the mainboard is powered up or reset.   
void ProgramStarted()
bool Decrement = true;

MyPWM1 = new PWM(Cpu.PWMChannel.PWM_1, Frequency, Duty, false);
MyPWM2 = new PWM(Cpu.PWMChannel.PWM_2, Frequency, Duty, false);

// Turn Off the Garbage Collector...

while (true)
if (Decrement)
Frequency = Frequency - GetPercentage(Frequency);

if (Frequency <= 100)
Decrement = false;
Frequency = Frequency + GetPercentage(Frequency);


if (Frequency >= 900000)
Decrement = true;

private uint GetPercentage(uint Frequency)
uint F = 0;

F = ((Frequency  * 1) / 100);

return F;

private void ConfigPWM()
uint Harmonic = CalculateHarmonic(Frequency, 3);
MyPWM1.Frequency = Frequency;
MyPWM2.Frequency = Harmonic;

MyPWM1.DutyCycle = Duty;
MyPWM2.DutyCycle = Duty;


private uint CalculateHarmonic(uint Frequency, int HarmonicInterval)
// Harmonic frequencies are 2f, 3f, 4f, 5f ...
uint Harmonic = ((uint)HarmonicInterval * Frequency);
return Harmonic;

private void StartPWM()

I did read a bit about this before in another post but it was not resolved? Any word on this issue?

All the Best


I don’t know about invert not working, but would a workaround be:

invertedDutyCycle = 1.0 - dutyCycle

1 Like

Hi Mike,

My Search: invertedDutyCycle

Returns nothing of use.

Where abouts does ‘invertedDutyCycle’ sit in the documentation? Its not in the PWM Class where I was expecting to find it.

Can anyone suggest a better way to follow the documentation, I seem to be having soo much trouble now. Since the 4.2 changes that is. Before that I was able to follow it nicely.


All the Best


PWM is a core netmf capability, so the reference will be on MSDN. In your case, PWM Constructor | Microsoft Learn is the specific PWM class constructor.

Hi Brett,

Thanks for the info. I realised this is the case and already searched for ‘invertedDutyCycle’ in the Microsoft library’s.

Its not in the PWM Class where I was expecting to find it.[/quote]

then I did the search on GHI to see it was listed on the site anywhere.

I cant find ‘invertedDutyCycle’ anywhere.

unless Mike meant:

All the Best


Mike was right, after my tired brain clicked, Mikes solution does work. 1+ Mike thanks.

@ All

Just thought I let everyone know. I ran Firmware update again and the Invert Boolean is now working. So to reiterate:

PWM MyPWM1 = new PWM(Cpu.PWMChannel.PWM_1, 1000, 0.5, false);

changing to this:

PWM MyPWM1 = new PWM(Cpu.PWMChannel.PWM_1, 1000, 0.5, true);

Does now invert the pin. Go figure re-applying the Firmware…

All the Best