ghi-electronics / TinyCLR-Ports

Apache License 2.0
26 stars 13 forks source link

Slow without debugger #618

Closed gus-ghielec closed 5 years ago

gus-ghielec commented 5 years ago

Put this code on dev board with UC55 and run without debugger. Now, open TinyCLR config and attach. The buzzing will double ins speed!

using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Pwm;
using GHIElectronics.TinyCLR.Pins;
using System.Runtime.InteropServices;

class Program {
    static void Blinker() {
        var LED = GpioController.GetDefault().OpenPin(UCMStandard.GpioPin.C);
        LED.SetDriveMode(GpioPinDriveMode.Output);
        var state = false;
        while (true) {
            state = !state;
            LED.Write(state? GpioPinValue.High: GpioPinValue.Low);
            Thread.Sleep(100);
        }
    }
    private static void Main() {
        UCMStandard.SetModel(UCMModel.UC5550);
        new Thread(Blinker).Start();

        //System.IntPtr address = 0x12345678;
        var address = new System.IntPtr(0x12345678);
        Marshal.WriteInt32(address, Marshal.ReadInt32(address) (1<<3));

        var freeq = 1000;
        var BuzzerCon = PwmController.FromName(UCMStandard.PwmChannel.A.Id);
        var BuzzerChan = BuzzerCon.OpenChannel(UCMStandard.PwmChannel.A.Pin);
        BuzzerChan.SetActiveDutyCyclePercentage(0.5);
        BuzzerCon.SetDesiredFrequency(freeq);
        BuzzerChan.Start();
        while (true) {
            BuzzerCon.SetDesiredFrequency(freeq);
            if ((freeq += 100) > 5000)
                freeq = 1000;
            Thread.Sleep(20);
        }
    }
}
Arke64 commented 5 years ago

Might be the same as #584

gus-ghielec commented 5 years ago

I confirm I have added the patch from #584 and it is working fine now!

Palomino34 commented 5 years ago

Duplicate #584 and fixed.