0

我正在使用 MicroChip 的 ADM00308 开发板。该板具有 PIC16F883 处理器。代码示例可以从他们的网站下载。我正在使用步进电机 ST4118m0706,步进为 1.8 度。我计算了步进电机的最大速度:

在此处输入图像描述

从这个网站

RPMmax = 24V/(2⋅0,032mh⋅0,5A) = 3,75n/s (3,75⋅60 = 225rpm)

每步的最短时间 = (2⋅0,032mh⋅0,5)/24V = 0,00133 秒。

所以理论上,步进电机应该能够在不振荡的情况下处理 225rpm。现在的软件。

代码示例提供了最高 45rpm 左右的可变速度。这太慢了,因为我的目标是 130rpm。这是原始代码:

脉冲宽度、最大速度和扫描

// Prescale: Must change both values together - PRESCALE Divisor and BIT MASK */
// 1 = 0b00000000, 2 = 0b00010000, 4 = 0b00100000, 8 = 0b00110000
//#define REF_PWM_PRESCALE 8
//#define REF_PWM_PRESCALE_MASK 0b00110000
// The Rollover Count is the period of the timer.
// The timer period = 0 - Rollover Count.
//#define REF_PWM_PERIOD =  ((float) ((1.0 / (((float)_XTAL_FREQ) / 4.0)) * (REF_PWM_PRESCALE * REF_RWM_ROLLOVER_COUNT)))
//#define REF_FREQ ((float) (1.0 / REF_PERIOD) )
// Set minimum speed by (65535 - MAX_SPEED_COUNT) * usec per bit
// 12 msec =
#define MIN_MOTOR_PULSEWIDTH (0.015)
#define MAX_SPEED_COUNT  ((unsigned int) (65535.0 - ((float) ((MIN_MOTOR_PULSEWIDTH / (1.0 / (((float)_XTAL_FREQ) / 4.0))) /  (ROTATION_PRESCALE * 2)))))
#define SPEED_INPUT_SPAN ((unsigned int) 900)
#define SPEED_INPUT_COUNTS_PER_BIT ((unsigned int) (MAX_SPEED_COUNT / SPEED_INPUT_SPAN))

#define ROTATION_ROLLOVER_COUNT (MAX_SPEED_COUNT + 100)
#define ROTATION_PRESCALE 8
#define ROTATION_PRESCALE_MASK 0b00110000
#define ROTATION_PERIOD =  ((float) ((1.0 / (((float)_XTAL_FREQ) / 4.0)) * (ROTATION_PRESCALE * ROTATION_ROLLOVER_COUNT)))
#define ROTATION_FREQ ((float) (1.0 / ROTATION_PERIOD) )

速度更新

FaultTypeEnum SpeedUpdate(void)
{
  FaultTypeEnum Fault;
  unsigned int Speed;

  Fault = NO_FAULT;
  if (SpeedInput < 65)
  {
    /* open/shorted(GND) speed input */
    Speed = 0;
    Fault = SPEED_INPUT_LOW;
  }
  else if (SpeedInput < 100)
  {
    Speed = 0;
    Fault = NO_FAULT;
  }
  else if (SpeedInput > 950)
  {
    Speed = 0;
    Fault = SPEED_INPUT_HIGH;
  }
  else if (SpeedInput > 900)
  {
    /* open/shorted(VDD) speed input */
    Speed = MAX_SPEED_COUNT;
    Fault = NO_FAULT;
  }
  else
  {
    Speed = (SpeedInput - 100) * SPEED_INPUT_COUNTS_PER_BIT;
    Fault = NO_FAULT;
  }

  RotationTimerRolloverCount = MAX_SPEED_COUNT - Speed;

  /* setup the next timer reload value */
  T1CON = 0b00000000; /* Temporarily pause the PWM timer */
    /* use variables to reload timer faster in interrupt routine */
  RotationTimerReloadHi =  (unsigned )(RotationTimerRolloverCount >> 8);
  RotationTimerReloadLo = (unsigned short) RotationTimerRolloverCount;
  T1CON = 0b00000001 | ROTATION_PRESCALE_MASK; // Re-enable PWM timer, set prescale

  return Fault;
}

定时器

 /* Rotation Timer.  Must be fast. */
  if (PIR1bits.TMR1IF)
  {
    PIR1bits.TMR1IF = 0;
    TMR1H = RotationTimerReloadHi;
    TMR1L = RotationTimerReloadLo;

    /* Calculate next stepper rotation state */
    /* HOLD switch sets min_rotation_state = max_rotation_state */
    /* SINGLE STEP switch sets min_rotation_state = max_rotation_state */
    if (System.Bits.Stop)
    {
      /* no current output */
      RotationData.All = ROTATION_STOP;
    }
    else
    {
      /* update stepper driver with last calculated data */
      PORTB = ((PORTB & 0b11000000) | RotationData.All);

我设法通过更改将速度更改为 146rpm:

#define MIN_MOTOR_PULSEWIDTH (0.015)

用于测试

#define MIN_MOTOR_PULSEWIDTH (0.006)

步进器以 98rpm 的速度旋转,电位器完全向左旋转。将该值降低到 0.004 将获得 146rpm 的速度,并且在 24v 电源上具有良好的扭矩(在 12v 电源上扭矩会受到影响)。进一步降低该值,将使电机振荡(您可以听到电机的声音,但它不再旋转)。这很奇怪,因为最大 rpm 应该是 225rpm。但是,主要问题是我似乎无法达到 130 的 rpm。将值更改为 0.005、0.0045 等不会将速度提高到 98 以上,直到 0.004。电位器似乎也有某种预设。通过转动电位器,它从 146rpm 变为 98rpm,变为 73rpm,等等。如果你明白我的意思,它不会流畅地改变速度。因此,我得到了它在预设中编程的想法,我也试图改变它。

固件和资料可在原站下载

4

0 回答 0