UD435 fails when using PWM3.4
Closed this issue · 1 comments
MMajo commented
Using PWM3.4 in combination with UD435 causes UD435 to fail on SCM20260D Dev.
Palomino34 commented
I am assuming PWM3.4 = Controller3.PB1. because PB1 because this pin is controller3, channel4. This also connects to Buzzer on 20260Dev. The test code below, I don't see any bug or wrong on display and buzzer sound.
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Pwm;
using GHIElectronics.TinyCLR.Pins;
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Threading;
namespace TestString
{
internal class Program
{
const int BACKLIGHT = SC20260.GpioPin.PA15;
//const int LED1 = SC20260.GpioPin.PA0; // PB0
const int LED1 = SC20260.GpioPin.PB0; // PB0
const int LDR1 = SC20260.GpioPin.PE3; // PB7;
const int SCREEN_WIDTH = 480;
const int SCREEN_HEIGHT = 272;
static GpioPin led1;
static GpioPin ldr1;
static void Main()
{
var controller = GpioController.GetDefault();
led1 = controller.OpenPin(LED1);
ldr1 = controller.OpenPin(LDR1);
led1.SetDriveMode(GpioPinDriveMode.Output);
ldr1.SetDriveMode(GpioPinDriveMode.InputPullUp);
while (true)
{
if (ldr1.Read() == GpioPinValue.Low)
{
while (ldr1.Read() == GpioPinValue.Low) ;
break;
}
}
if (BACKLIGHT != 0)
{
GpioPin backlight = GpioController.GetDefault().OpenPin(BACKLIGHT);
backlight.SetDriveMode(GpioPinDriveMode.Output);
backlight.Write(GpioPinValue.Low);
Thread.Sleep(100);
backlight.Write(GpioPinValue.High);
}
var displayController = GHIElectronics.TinyCLR.Devices.Display.DisplayController.GetDefault();
var controllerSetting = new GHIElectronics.TinyCLR.Devices.Display.ParallelDisplayControllerSettings
{
Width = SCREEN_WIDTH,
Height = SCREEN_HEIGHT,
DataFormat = GHIElectronics.TinyCLR.Devices.Display.DisplayDataFormat.Rgb565,
PixelClockRate = 10000000,
PixelPolarity = false,
DataEnablePolarity = false,
DataEnableIsFixed = false,
HorizontalFrontPorch = 2,
HorizontalBackPorch = 2,
HorizontalSyncPulseWidth = 41,
HorizontalSyncPolarity = false,
VerticalFrontPorch = 2,
VerticalBackPorch = 2,
VerticalSyncPulseWidth = 10,
VerticalSyncPolarity = false,
};
displayController.SetConfiguration(controllerSetting);
displayController.Enable();
var screen = Graphics.FromHdc(displayController.Hdc);
new Thread(() =>
{
while (true)
{
if (ldr1.Read() == GpioPinValue.Low)
{
while (ldr1.Read() == GpioPinValue.Low) ;
break;
}
Thread.Sleep(10);
}
var pwmController3 = PwmController.FromName(SC20260.Timer.Pwm.Controller3.Id);
var pwmChannel4 = pwmController3.OpenChannel(SC20260.Timer.Pwm.Controller3.PB1);
pwmController3.SetDesiredFrequency(1 / 0.0011);
pwmChannel4.SetActiveDutyCyclePercentage(0.25);
pwmChannel4.Start();
}
).Start();
var x = 0;
var y = 0;
var dirx = 1;
var diry = 1;
while (true)
{
screen.Clear();
screen.FillEllipse(new SolidBrush(System.Drawing.Color.FromArgb(255, 0xFF, 0, 0)), x, y, 100, 100);
screen.Flush();
x += (10 * dirx);
y += (5 * diry);
if (x >= SCREEN_WIDTH)
dirx = -1;
else if (x <= 0)
dirx = 1;
if (y >= SCREEN_HEIGHT)
diry = -1;
else if (y <= 0)
diry = 1;
Thread.Sleep(250);
}
}
}
}