Esempio n. 1
0
        // Send power to the heater
        private void pwmHeater(object sender, object e)
        {
            if (BrewingTimer.StillCounting())
            {
                counter++;
                double cykle = Math.Min(u, 100 - u);
                cykle = (int)Math.Round(100 / cykle);
                if (counter < 100)
                {
                    double modu = counter % cykle;
                    if (u > 50)
                    {
                        modu = 1 - modu;
                    }

                    if (modu > 0 && heaterOn)
                    {
                        heaterPin.Write(GpioPinValue.Low);
                        indicatorPin.Write(GpioPinValue.Low);
                        heaterOn = false;
                    }
                    else if (modu <= 0 && !heaterOn)
                    {
                        heaterPin.Write(GpioPinValue.High);
                        indicatorPin.Write(GpioPinValue.High);
                        heaterOn = true;
                    }
                    else
                    {
                        // heaterPin is in correct state; do nothing
                    }
                }

                else
                {   // Cykle finnished sett heaterPin low for safty issues
                    counter = 0;
                    heaterPin.Write(GpioPinValue.Low);
                    indicatorPin.Write(GpioPinValue.Low);
                    heaterOn = false;
                }
            }
            else if (heaterOn)
            {
                heaterPin.Write(GpioPinValue.Low);
                indicatorPin.Write(GpioPinValue.Low);
            }
        }
Esempio n. 2
0
        // part of simulator
        private void updateTemp(object sender, object e)
        {
            convertADCreadingsToTempature();
            if (BrewingTimer.StillCounting())
            {
                // error
                var error = setTemp[MainPage.index] - curTemp;

                if (!userSetPower)
                {
                    Debug.Write("I 1: " + ((1.0 / Ti) * error));
                    // Regulator
                    p  = Kp * error;
                    i += (1.0 / Ti) * error;
                    Debug.Write(" I 2:" + i);
                    //i = i * Kp;
                    //Debug.WriteLine("I 3:" + i);
                    i = Math.Max(Math.Min((100.0 / Kp), i), (-100.0 / Kp));  // Anti windup
                    Debug.Write(" I 3:" + i);
                    Debug.WriteLine(" I 4:" + (i * Kp));
                    u = p + (i * Kp);
                    u = Math.Max(Math.Min(100, u), 0);  // Min value 0 Max value 100
                }
                // Change in temp (Simulated data remp region 0-105)
                //var dTemp = u * (PMAX / (double)(CP * M));
                //var tempDiff = 20 - curTemp;
                //curTemp += (dTemp + (0.2 * tempDiff));
                //curTemp = Math.Min(Math.Max(curTemp, 0), 102);
                if (setTemp[MainPage.index] - curTemp < 1)
                {
                    ready = true;
                }
                else
                {
                    ready = false;
                }
                //System.Diagnostics.Debug.WriteLine("Set temp = " + setTemp + " Cur temp = " + curTemp + " Pådrag = " + dTemp);
            }
            else
            {
                u = 0;
            }
        }