Hi All,
This is in part a continuation of this thread: https://www.ghielectronics.com/community/forum/topic?id=15557
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.
[b]
My Code:
[/b]
```cs
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...
// https://www.ghielectronics.com/docs/237/update-preparation-loader-tinybooter-and-firmware-tinyclr
// 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...
Debug.GC(false);
while (true)
{
if (Decrement)
{
Frequency = Frequency - GetPercentage(Frequency);
ConfigPWM();
Thread.Sleep(10);
if (Frequency <= 100)
{
Decrement = false;
}
}
else
{
Frequency = Frequency + GetPercentage(Frequency);
ConfigPWM();
Thread.Sleep(10);
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;
StartPWM();
}
private uint CalculateHarmonic(uint Frequency, int HarmonicInterval)
{
// Harmonic frequencies are 2f, 3f, 4f, 5f ...
uint Harmonic = ((uint)HarmonicInterval * Frequency);
return Harmonic;
}
private void StartPWM()
{
MyPWM1.Start();
MyPWM2.Start();
}
I did read a bit about this before in another post but it was not resolved? Any word on this issue?
All the Best
Chris