I believe I have found a bug in the G30, the PWM outputs stop when receiving serial data. I have created this test setup to illustrate the problem. This shows the G30 dev board connected to a pc via the serial port with a scope on the Serial port receive and the PWM output used in the sample code I have.
This image shows the scope traces of the serial data and the PWM trace stopping.The code running on the G30 creates a PWM output, creates a serial port and reads but does nothing wit the data. Every 20 seconds it disposes the PWM and creates and output port to hold the PWM line high for a test. It then disposes the output port and recreates the PWM object. `using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.IO.Ports;
using System.Threading;
using GHI.Pins;
namespace GHIPWM
{
public class Program
{
private static PWM PWM;
private static OutputPort PWMPin;
private static SerialPort Com;
public static void Main()
{
PWM = new PWM(GHI.Pins.G30.PwmOutput.PA8, 10000, 5000, PWM.ScaleFactor.Microseconds, true);
PWM.Start();
Com = new SerialPort("COM2", 2400, Parity.Even);
Com.Open();
Com.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);
while (true)
{
Thread.Sleep(20000);
EnablePwm(false);
// DoTest();
EnablePwm(true);
}
}
private static void EnablePwm(bool pwm)
{
if (pwm)
{
PWMPin.Dispose();
PWMPin = null;
PWM = new PWM(GHI.Pins.G30.PwmOutput.PA8, 10000, 5000, PWM.ScaleFactor.Microseconds, true);
PWM.Start();
}
else
{
PWM.Stop();
PWM.Dispose();
PWM = null;
PWMPin = new OutputPort(GHI.Pins.G30.Gpio.PA8, true);
}
}
private static void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
int Bytes = Com.BytesToRead;
byte[] Data = new byte[Bytes];
Com.Read(Data, 0, Bytes);
}
catch (Exception ex)
{
Debug.Print(ex.Message);
}
}
}
}
`
The code running on the PC to send serial data opens com1 and on any key press will stream 10,000 random bytes at the G30 and will quit if Q is pressed.
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
namespace SerialTest
{
class Program
{
private static SerialPort Com;
static void Main(string[] args)
{
Com = new SerialPort("COM1", 2400, Parity.Even);
Com.Open();
Com.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);
ConsoleKeyInfo key =Console.ReadKey();
while (key.Key.ToString() != "Q")
{
int i;
int c;
Random rnd = new Random();
for (i = 0; i < 10000; i++) {
c = rnd.Next(255);
Com.Write(Convert.ToChar(c).ToString());
System.Threading.Thread.Sleep(4);
}
key = Console.ReadKey();
}
Com.Close();
}
private static void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
int Bytes = Com.BytesToRead;
byte[] Data = new byte[Bytes];
Com.Read(Data, 0, Bytes);
}
catch (Exception ex)
{
}
}
}
}
`
Whenever I run these programs and stream data the PWM output stops and remains low until the restarted every 20 seconds and then it will stop again and so on. This code is cut down from a larger project where I had this problem which I mentioned in a thread on the old forum https://www.ghielectronics.com/community/forum/topic?id=24403 To ship the product we had to add an additional microprocessor to do the PWM. I have created these simplified programs so that you can test them to confirm this problem is repeatable and to see if there’s some way to fix it.
Thanks, David.