Ejemplo n.º 1
0
 private void Regs_Struct_Reset(RegsStruct RegsStruct)
 {
     RegsStruct.ABS_POS    = 0;
     RegsStruct.EL_POS     = 0;
     RegsStruct.MARK       = 0;
     RegsStruct.SPEED      = 0;
     RegsStruct.ACC        = 0x08A;
     RegsStruct.DEC        = 0x08A;
     RegsStruct.MAX_SPEED  = 0x041;
     RegsStruct.MIN_SPEED  = 0;
     RegsStruct.FS_SPD     = 0x027;
     RegsStruct.KVAL_HOLD  = 0x29;
     RegsStruct.KVAL_RUN   = 0x29;
     RegsStruct.KVAL_ACC   = 0x29;
     RegsStruct.KVAL_DEC   = 0x29;
     RegsStruct.INT_SPD    = 0x0408;
     RegsStruct.ST_SLP     = 0x19;
     RegsStruct.FN_SLP_ACC = 0x29;
     RegsStruct.FN_SLP_DEC = 0x29;
     RegsStruct.K_THERM    = 0;
     RegsStruct.OCD_TH     = 0x8;
     RegsStruct.STALL_TH   = 0x40;
     RegsStruct.STEP_MODE  = 0x7;
     RegsStruct.ALARM_EN   = 0xFF;
     RegsStruct.CONFIG     = 0x2E88;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Sets the registers to the passed in register values
 /// </summary>
 /// <param name="RegsStruct">Register values to set the values to</param>
 public void SetRegisters(RegsStruct RegsStruct)
 {
     SetParam(Registers.ABS_POS, RegsStruct.ABS_POS);
     SetParam(Registers.EL_POS, RegsStruct.EL_POS);
     SetParam(Registers.MARK, RegsStruct.MARK);
     SetParam(Registers.SPEED, RegsStruct.SPEED);
     SetParam(Registers.ACC, RegsStruct.ACC);
     SetParam(Registers.DEC, RegsStruct.DEC);
     SetParam(Registers.MAX_SPEED, RegsStruct.MAX_SPEED);
     SetParam(Registers.MIN_SPEED, RegsStruct.MIN_SPEED);
     SetParam(Registers.FS_SPD, RegsStruct.FS_SPD);
     SetParam(Registers.KVAL_HOLD, RegsStruct.KVAL_HOLD);
     SetParam(Registers.KVAL_RUN, RegsStruct.KVAL_RUN);
     SetParam(Registers.KVAL_ACC, RegsStruct.KVAL_ACC);
     SetParam(Registers.KVAL_DEC, RegsStruct.KVAL_DEC);
     SetParam(Registers.INT_SPD, RegsStruct.INT_SPD);
     SetParam(Registers.ST_SLP, RegsStruct.ST_SLP);
     SetParam(Registers.FN_SLP_ACC, RegsStruct.FN_SLP_ACC);
     SetParam(Registers.FN_SLP_DEC, RegsStruct.FN_SLP_DEC);
     SetParam(Registers.K_THERM, RegsStruct.K_THERM);
     SetParam(Registers.OCD_TH, RegsStruct.OCD_TH);
     SetParam(Registers.STALL_TH, RegsStruct.STALL_TH);
     SetParam(Registers.STEP_MODE, RegsStruct.STEP_MODE);
     SetParam(Registers.ALARM_EN, RegsStruct.ALARM_EN);
     SetParam(Registers.CONFIG, RegsStruct.CONFIG);
 }
Ejemplo n.º 3
0
        private void InitializeChip()
        {
            regsStruct = new RegsStruct();
            Regs_Struct_Reset(regsStruct);

            /* Acceleration rate settings to 466 steps/s2, range 14.55 to 59590 steps/s2 */
            regsStruct.ACC = AccDec_Steps_to_Par(466);
            /* Deceleration rate settings to 466 steps/s2, range 14.55 to 59590 steps/s2 */
            regsStruct.DEC = AccDec_Steps_to_Par(466);
            /* Maximum speed settings to 488 steps/s, range 15.25 to 15610 steps/s */
            regsStruct.MAX_SPEED = MaxSpd_Steps_to_Par(488);
            /* Minimum speed settings to 0 steps/s, range 0 to 976.3 steps/s */
            regsStruct.MIN_SPEED = MinSpd_Steps_to_Par(0);
            /* Full step speed settings 252 steps/s, range 7.63 to 15625 steps/s */
            regsStruct.FS_SPD = FSSpd_Steps_to_Par(252);
            /* Hold duty cycle (torque) settings to 10%, range 0 to 99.6% */
            regsStruct.KVAL_HOLD = Kval_Perc_to_Par(10);
            /* Run duty cycle (torque) settings to 10%, range 0 to 99.6% */
            regsStruct.KVAL_RUN = Kval_Perc_to_Par(10);
            /* Acceleration duty cycle (torque) settings to 10%, range 0 to 99.6% */
            regsStruct.KVAL_ACC = Kval_Perc_to_Par(10);
            /* Deceleration duty cycle (torque) settings to 10%, range 0 to 99.6% */
            regsStruct.KVAL_DEC = Kval_Perc_to_Par(10);
            /* Intersect speed settings for BEMF compensation to 200 steps/s, range 0 to 3906 steps/s */
            regsStruct.INT_SPD = IntSpd_Steps_to_Par(200);
            /* BEMF start slope settings for BEMF compensation to 0.038% step/s, range 0 to 0.4% s/step */
            regsStruct.ST_SLP = BEMF_Slope_Perc_to_Par((float)0.038);
            /* BEMF final acc slope settings for BEMF compensation to 0.063% step/s, range 0 to 0.4% s/step */
            regsStruct.FN_SLP_ACC = BEMF_Slope_Perc_to_Par((float)0.063);
            /* BEMF final dec slope settings for BEMF compensation to 0.063% step/s, range 0 to 0.4% s/step */
            regsStruct.FN_SLP_DEC = BEMF_Slope_Perc_to_Par((float)0.063);
            /* Thermal compensation param settings to 1, range 1 to 1.46875 */
            regsStruct.K_THERM = KTherm_to_Par(1);
            /* Overcurrent threshold settings to 1500mA */
            regsStruct.OCD_TH = (byte)Overcurrent_Detection_Threshold.OCD_TH_1500mA;
            /* Stall threshold settings to 1000mA, range 31.25 to 4000mA */
            regsStruct.STALL_TH = StallTh_to_Par(1000);
            /* Step mode settings to 128 microsteps */
            regsStruct.STEP_MODE = (byte)Step_Select.STEP_SEL_1_128;
            /* Alarm settings - all alarms enabled */
            regsStruct.ALARM_EN = (byte)Alarm_Enable.ALARM_EN_OVERCURRENT | (byte)Alarm_Enable.ALARM_EN_THERMAL_SHUTDOWN
                                  | (byte)Alarm_Enable.ALARM_EN_THERMAL_WARNING | (byte)Alarm_Enable.ALARM_EN_UNDER_VOLTAGE | (byte)Alarm_Enable.ALARM_EN_STALL_DET_A
                                  | (byte)Alarm_Enable.ALARM_EN_STALL_DET_B | (byte)Alarm_Enable.ALARM_EN_SW_TURN_ON | (byte)Alarm_Enable.ALARM_EN_WRONG_NPERF_CMD;

            /* Internal oscillator, 2MHz OSCOUT clock, supply voltage compensation disabled, *
            * overcurrent shutdown enabled, slew-rate = 290 V/us, PWM frequency = 15.6kHz   */
            regsStruct.CONFIG = (ushort)CONFIG_OSC_MGMT.CONFIG_INT_16MHZ_OSCOUT_2MHZ | (ushort)CONFIG_SW_MODE_TypeDef.CONFIG_SW_HARD_STOP
                                | (ushort)CONFIG_EN_VSCOMP.CONFIG_VS_COMP_DISABLE | (ushort)CONFIG_OC_SD.CONFIG_OC_SD_ENABLE | (ushort)CONFIG_POW_SR.CONFIG_SR_290V_us
                                | (ushort)CONFIG_F_PWM_INT.CONFIG_PWM_DIV_2 | (ushort)CONFIG_F_PWM_DEC.CONFIG_PWM_MUL_1;

            /* Program all dSPIN registers */
            SetRegisters(regsStruct);
        }