Esempio n. 1
0
        // ###################### PGx TEST  ##########################
        private void testPGCPGDEnter()
        {
            float vdd = 0;
            float vpp = 0;

            // set VPP off
            byte[] vppscript = new byte[3];
            vppscript[0] = KONST._VPP_OFF;
            vppscript[1] = KONST._VPP_PWM_OFF;
            vppscript[2] = KONST._MCLR_GND_ON;
            Pk2.SendScript(vppscript);

            Pk2.VddOff();

            buttonCancel.Text = "Finished";

            Thread.Sleep(200); // sleep a bit to let VDD bleed down.

            // check for a powered target first
            if (Pk2.CheckTargetPower(ref vdd, ref vpp) == KONST.PICkit2PWR.selfpowered)
            {
                Pk2.VddOff();
            }
            else
            {
                Pk2.SetVDDVoltage((float)numericUpDown1.Value, 0.85F);
                Pk2.VddOn();
                Thread.Sleep(50);
            }

            // check status next for shorts
            KONST.PICkit2PWR status = Pk2.PowerStatus();
            if ((status == KONST.PICkit2PWR.vdderror) || (status == Constants.PICkit2PWR.vddvpperrors))
            { //VDD short!
                radioButtonPGCHigh.Enabled   = false;
                radioButtonPGCLow.Enabled    = false;
                radioButtonPGDHigh.Enabled   = false;
                radioButtonPGDLow.Enabled    = false;
                radioButtonPGCToggle.Enabled = false;
                radioButtonPGDToggle.Enabled = false;
                labelPGxOScope.Visible       = false;
                labelPGxVDDShort.Visible     = true;
            }
            else if (status == KONST.PICkit2PWR.vpperror)
            {//VPP short
                radioButtonPGCHigh.Enabled   = false;
                radioButtonPGCLow.Enabled    = false;
                radioButtonPGDHigh.Enabled   = false;
                radioButtonPGDLow.Enabled    = false;
                radioButtonPGCToggle.Enabled = false;
                radioButtonPGDToggle.Enabled = false;
                labelPGxOScope.Visible       = false;
                labelPGxVDDShort.Visible     = true;
            }
            else if (status != Constants.PICkit2PWR.no_response)
            {   // status OK, Set PGC/PGC pins outputs low.
                radioButtonPGCHigh.Enabled   = true;
                radioButtonPGCLow.Enabled    = true;
                radioButtonPGDHigh.Enabled   = true;
                radioButtonPGDLow.Enabled    = true;
                radioButtonPGCToggle.Enabled = true;
                radioButtonPGDToggle.Enabled = true;
                labelPGxOScope.Visible       = true;
                labelPGxVDDShort.Visible     = false;

                vppscript[0] = KONST._SET_ICSP_PINS;
                vppscript[1] = 0x00;
                vppscript[2] = KONST._BUSY_LED_OFF; // "NOP"
                Pk2.SendScript(vppscript);

                radioButtonPGDToggle.Checked = false;
                radioButtonPGCToggle.Checked = false;
                radioButtonPGCHigh.Checked   = false;
                radioButtonPGCLow.Checked    = true;
                radioButtonPGDHigh.Checked   = false;
                radioButtonPGDLow.Checked    = true;
            }
        }
Esempio n. 2
0
        private void buttonTestVPP_Click(object sender, EventArgs e)
        {
            float vdd = 0;
            float vpp = 0;

            labelVPPLow.Visible      = false;
            labelVPPMCLR.Visible     = false;
            labelVPPMCLROff.Visible  = false;
            labelVPPPass.Visible     = false;
            labelVPPShort.Visible    = false;
            labelVPPVDDShort.Visible = false;
            labelReadVPP.Text        = "";

            Thread.Sleep(250); // sleep a bit to let VDD bleed down.

            // check for a powered target first
            if (Pk2.CheckTargetPower(ref vdd, ref vpp) == KONST.PICkit2PWR.selfpowered)
            {
                Pk2.VddOff();
            }
            else
            {
                Pk2.SetVDDVoltage((float)numericUpDown1.Value, 0.85F);
                Pk2.VddOn();
            }
            // Set VPP voltage
            float expectedVPP;

            if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].Vpp > 1)
            {
                expectedVPP = Pk2.DevFile.Families[Pk2.GetActiveFamily()].Vpp;
            }
            else
            {
                expectedVPP = (float)numericUpDown1.Value;
            }
            Pk2.SetVppVoltage(expectedVPP, 0.50F);
            byte[] vppscript = new byte[8];
            vppscript[0] = KONST._VPP_OFF;
            vppscript[1] = KONST._VPP_PWM_ON;
            vppscript[2] = KONST._DELAY_LONG;
            vppscript[3] = 30;
            vppscript[4] = KONST._MCLR_GND_OFF;
            vppscript[5] = KONST._VPP_ON;
            vppscript[6] = KONST._DELAY_LONG;
            vppscript[7] = 20;
            Pk2.SendScript(vppscript);

            // check status first for shorts
            KONST.PICkit2PWR status = Pk2.PowerStatus();
            if ((status == KONST.PICkit2PWR.vdderror) || (status == Constants.PICkit2PWR.vddvpperrors))
            { //VDD short!
                labelVPPVDDShort.Visible = true;
            }
            else if (status == KONST.PICkit2PWR.vpperror)
            {//VPP short
                labelVPPShort.Visible = true;
                labelReadVPP.Text     = "Short!";
            }
            else if (status != Constants.PICkit2PWR.no_response)
            {   // status OK, read VPP voltage
                if (Pk2.ReadPICkitVoltages(ref vdd, ref vpp))
                {
                    labelReadVPP.Text = string.Format("{0:0.0} V", vpp);
                    if ((expectedVPP - vpp) > 0.3F)
                    {
                        labelVPPLow.Visible = true;
                    }
                    else
                    {
                        labelVPPPass.Visible = true;
                    }
                }
            }
        }