private void buttonVDDOn_Click(object sender, EventArgs e)
        {
            float vdd = 0;
            float vpp = 0;

            labelGood.Visible     = false;
            labelVDDShort.Visible = false;
            labelVDDLow.Visible   = false;
            labelReadVDD.Text     = "";

            // set VDD with a low threshold
            float voltage = (float)numericUpDown1.Value;

            if (Pk2.SetVDDVoltage(voltage, 0.45F))
            {
                // turn on VDD
                Pk2.ForcePICkitPowered();
                if (Pk2.VddOn())
                {
                    // check status first for shorts
                    if (Pk2.PowerStatus() != KONST.PICkit2PWR.vdd_on)
                    { //short!
                        labelVDDShort.Visible = true;
                        labelReadVDD.Text     = "Short!";
                    }
                    else
                    {// status OK, read VDD voltage
                        if (Pk2.ReadPICkitVoltages(ref vdd, ref vpp))
                        {
                            labelReadVDD.Text = string.Format("{0:0.0} V", vdd);
                            float expectedVDD = (float)numericUpDown1.Value;
                            if (expectedVDD > 4.6F)
                            {
                                expectedVDD = 4.6F;  // There is a typical drop for VDD > 4.6V
                                                     // don't count that
                            }
                            if ((expectedVDD - vdd) > 0.2F)
                            {
                                labelVDDLow.Visible = true;
                            }
                            else
                            {
                                labelGood.Visible = true;
                            }
                        }
                    }
                }
            }
        }
Example #2
0
 private void buttonNext_Click(object sender, EventArgs e)
 {
     if (panelIntro.Visible)
     {
         panelIntro.Visible = false;
         panelSetup.Visible = true;
         buttonBack.Enabled = true;
     }
     else if (panelSetup.Visible)
     {
         panelSetup.Visible      = false;
         panelCal.Visible        = true;
         buttonCalibrate.Enabled = true;
         labelGoodCal.Visible    = false;
         labelBadCal.Visible     = false;
         textBoxVDD.Text         = "4.000";
         textBoxVDD.Focus();
         textBoxVDD.SelectAll();
         Pk2.SetVoltageCals(0x0100, 0x00, 0x80); // set to defaults.
         Pk2.SetVDDVoltage(4.0F, 3.4F);
         Pk2.VddOn();
     }
     else if (panelCal.Visible)
     {
         panelCal.Visible        = false;
         panelUnitID.Visible     = true;
         buttonSetUnitID.Enabled = true;
         labelAssignedID.Visible = false;
         textBoxUnitID.Text      = Pk2.UnitIDRead();
         textBoxUnitID.Focus();
         textBoxVDD.SelectAll();
         buttonNext.Enabled = false;
         buttonCancel.Text  = "Finished";
         Pk2.VddOff();
     }
 }
        // ###################### 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;
            }
        }
        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;
                    }
                }
            }
        }