The Nerf N-Strike Elite RapidStrike CS-18 Blaster is a toy blaster mounted on two supporting pillars that are connected to a circular plate that in turn are connected to a stepper motor shaft. This arrangement forms the basis for the horizontal rotation. On one of the pillars, a servo motor is fixed which controls the vertical motion (elevation) of the blaster. There are three DC motors inside the NERF Blaster. Two of these DC motors (with one common control) are responsible for the acceleration of the dart, thus controlling the dart speed. The third motor is responsible for triggering the dart, thus controlling the firing rate (# of darts fired/minute). Horizontal movement is mechanically restricted to one rotation to avoid a wire binding problem. Movement is limited to one rotation by a mechanical stopper connected to ground. Figure 1 shows the NERF Blaster setup, as does this demonstration video:
Figure 1: PSoC 4 BLE controlled NERF Blaster setup (Source: Cypress Semiconductor)
Challenges in the design of a Nerf-Blaster
- Designing the Stepper Motor Controller
A stepper motor is a brushless, synchronous motor that divides one full rotation of the rotor into a number of steps. A stepper motor is designed specifically to be operated in a mode where the rotor is frequently locked in defined angular positions. Stepper motors can be operated in full step mode and half step mode. In full step mode, the motor moves through its basic step angle (1.8 degrees) for 200 steps per revolution. In half step mode, the motor step angle reduces to half the angle in full step (0.9 degree). Now, it takes 400 steps to complete a revolution. The Nerf blaster discussed in this article uses the half step sequence. A 200-step (1.8°per step) stepper motor is used. With half stepping, 400 steps (i.e., 0.9° per step) is achieved.
- Limiting the Current through Stepper Motors
The stepper motor used inside the Nerf blaster is a high torque motor (20 Kg cm/1.45 foot-lbs torque). High torque stepper motors are built with very low resistance windings. Running these motors with a reasonable voltage leads to a faster rise in the current through the windings when they are turned on. This provides faster maximum motor speed. These motors generally consume 2-3 A current when the coils are completely turned on, which will damage the stepper motor windings.
- Designing the Servo Motor control
A servo motor consists of three components: DC motor, potentiometer, and a control circuit. The motor is attached to the potentiometer through a series of gears. As the motor rotates, the resistance of potentiometer changes and provides the control circuit with information regarding the shaft position. When the motor is in the desired position, the power that is provided to the motor is stopped.
- Designing the DC Motor control
DC motors are comparatively easy to control using a pulse width modulator (PWM).
Controlling a Nerf-Blaster Remotely using BLE
Figure 2: Block Diagram of PSoC 4 BLE controlled NERF Blaster (Source: Cypress Semiconductor)
Figure 2 shows the functional block diagram of the system and internal components used in this design built around the Cypress PSoC 4 BLE microcontroller. The NERF blaster is controlled using an Android phone and the communications link is BLE. This article explains how various motions of the NERF blaster are controlled:
- Stepper Motor for Horizontal Motion
- Servo Motor for Vertical Motion
- DC Motors for Firing Speed and Firing Rate
The android application and the BLE configuration for the microcontroller are outside the scope of this article.
Stepper Motor Control
The stepper motor moves in distinct steps during its rotation. Each of these steps is defined by a Step Angle. The stepper motor has two coils with four terminals ( A, /A, B, /B ). For the operation of the stepper motor, the coils have to be excited in a particular sequence based on clockwise or anticlockwise rotation. The stepper motor can be operated in various modes (i.e., full step, half step, and micro step).
Once a particular mode is selected and the coils are excited in a particular sequence, the motor starts to rotate. However, the motor has the tendency to draw very high current because of the low winding resistance of the coils. If this current exceeds the maximum current rating of the stepper motor, the coils can get damaged. Hence it is very important to protect the stepper motor with current protection circuitry.
The following illustrates a half step implementation of the stepper motor using PSoC Creator to create the control code for the PSoC 4 BLE. PSoC Creator is a graphical IDE which allows developers to design projects graphically using a library components. The components required to rotate a stepper motor are PWM, Look Up Table (LUT), and descrete logic. Figure 3 shows the TopDesign configuration (graphical represenation of hardware) of the stepper motor control.
Figure 3. Stepper motor control (Source: Cypress Semiconductor)
Now let’s consider the functionality of each component.
Look Up Table (LUT): You can set up the Lookup Table (LUT) component to perform any logic function with up to five inputs and eight outputs (refer to the LUT datasheet for more details). In our application, we are using it as a state machine to generate the half step sequence of a stepper motor. For illustration, let’s consider two of the eight half step sequences of the stepper motor for clockwise direction (1 0 0 1 and 1 0 0 0).
At every clock cycle, the output signals on out0, out1, out2 and out3 of the LUT will follow the defined sequence in the LUT. The present state of the LUT is passed as the input to decide the next state. The In4 input of the LUT determines the direction of rotation which is controlled by the control register.
With a programmable system-on-chip architecture like the PSoC 4, the LUT can be implemented in programmable hardware using Universal Digital Blocks (UDB). This means the complete system is hardware controlled without firmware intervention. As a result, the CPU is free to perform other tasks or stay in a low power mode. It also increases the reliability of operation by eliminating CPU dependencies on hardware.
PWM: PWM_StepperMotor clocks the LUT to control the rate at which the sequence is provided to the motor coils. Varying the period value of the PWM determines the output frequency controling the angular speed of the stepper motor shaft.
Stepper Motor Current Sense:
Stepper motors have very low resistance windings. Running these motors with a reasonable voltage leads to a faster rise in the current through the windings when they are turned on. These motors generally consume high current when the coils are completely turned on, which might damage the stepper motor windings. Hence external current limiting circuitry is required. The two coils of the stepper motor needs to be enabled or disabled, based on the current through the respective coils. Figure 4 shows the analog front end for such a circuit.
Figure 4: Stepper motor current sense (Source: Cypress Semiconductor)
In this example, the PSoC 4 BLE MCU is interfaced with a Rugged Motor Driver shield that has a DRV8801 H-bridge IC. Current_Sense_A_1 and Current_Sense_B_1 are inputted to the MCU from Motor A current sense and Motor B current sense pins from the driver board, which provide the voltage equivalent of the current consumed by coil A and coil B respectively. These are compared against the programmed reference (using IDAC and an external resistor). If the comparator output is low (i.e., inverting comparator), then the current through the coils is more than the specified limit and the corresponding coil will be disabled. The current profile of the stepper motor coil is shown in Figure 5. Note that this profile also depends on the inductance of the coil and design of motor driver. Using this design, a stepper motor can be fully hardware controlled without any firmware intervention.
Figure 5: Current profile of the stepper motor coil (Source: Cypress Semiconductor)
The Coil_A, Coil_B, En_A, and En_B pins from the MCU are connected to the Dir1, Dir2, Enable 1 and Enable 2 pins of the Rugged Motor Driver respectively. The Coil_A and Coil_B outputs from the MCU control the stepping sequence of the stepper motor. En_A and En_B control the current through the stepper motor coils.
Servo motor and DC motor Control
A servo motor is used to control the vertical motion of the Blaster. The servo is powered externally and controlled using a PWM. The pulse width of the PWM pulse determines the position of the servo motor. For example, consider a PWM clock = 1 MHz and PWM Period = 20000 (20ms):
The ON time of the PWM for a compare value of 1200 is:
By fixing the frequency and period, and by changing the compare value, ON time can be varied. Usually, ON time ranges from 0.5ms to 2.5ms and corresponds to 0 to 180 degrees of the servo motor. DC motors can be controlled using simple PWMs with the speed of the motor proportional to the duty cycle of the PWM. This completes the basic motion controls of the NERF blaster. Advanced features like adjusting the speed of rotation, the speed of bullets, controlled horizontal and vertical motion, automatic object detection with ultrasonic sensors, laser pointer, and so on can also be implemented using the same programmable system-on-chip MCU.
In this rapidly advancing and competitive world, the success of a product launch depends significantly on the time it takes to convert an idea into a product. Highly integrated programmable system-on-chip MCUs like PSoC 4 combine custom digital logic and analog functions with an MCU in a single device enabling developers to integrate many external fixed function blocks. The ability to design a product with a single MCU not only reduces BOM cost, it also results in PCB board layouts that are less congested and more reliable.
Mahesh Balan earned his B.Tech in Electronics and Communication Engineering from Model Engineering College, India. He is currently working as a Sr. Applications Engineer at Cypress Semiconductor on PSoC 3/4/5LP–based projects and assisting customers in their designs.