Skip to main content

AN-CM-258 Flex Sensor-Controlled Servo Motor

Contents

Terms and Definitions

ADC Analog-to-digital converter
OpAmp Operational amplifier
PGA Programmable gain amplifier
PWM Pulse-width modulation

References

For related documents and software, please visit:

https://www.dialog-semiconductor.com/configurable-mixed-signal.

Download our free GreenPAK Designer software [1] to open the .gp files [2] and view the proposed circuit design. Use the GreenPAK development tools [3] to freeze the design into your own customized IC in a matter of minutes. Dialog Semiconductor provides a complete library of application notes [4] featuring design examples as well as explanations of features and blocks within the Dialog IC.

  1. GreenPAK Designer Software, Software Download and User Guide, Dialog Semiconductor
  2. AN-CM-258 Flex Sensor-Controlled Servo Motor.gp, GreenPAK Design File, Dialog Semiconductor
  3. GreenPAK Development Tools, GreenPAK Development Tools Webpage, Dialog Semiconductor
  4. GreenPAK Application Notes, GreenPAK Application Notes Webpage, Dialog Semiconductor

Author: Oleh Horodechnyi

Introduction

The design uses a GreenPAK to control duty cycle signal for a servo motor, and a Micropower Operational Amplifier to provide and adjust the signal from the flex sensor to the GreenPAK.

Construction and Operating Principle

This design consists of a flexible sensor, dual CMOS Op Amp, GreenPAK IC, and a servo motor. The connection diagram is shown in Figure 1.

Figure 1: Typical Application Circuit

The flex sensor used in this design is the SparkFun SEN-08606. An image is shown in Figure 2. This flex sensor is a variable resistor. The flex sensor is a sensor that changes its resistance depending on the amount the sensor is bent. The flex sensor converts the amount of bend to electrical resistance - the more the bend, the higher the resistance value. Sensors like these were used in the Nintendo Power Glove.

Figure 2: Flex Sensor

The Dual CMOS OpAmp is used as a signal amplifier and to adjust the voltage at the GreenPAK analog input (ADC input detection range is from 30 mV to 1030 mV). The OpAmps are supplied by a single voltage source, therefore, in the design we used a part of the scheme where a virtual ground is implemented. The scheme of the OpAmp external circuitry connection is typical of inverting amplifiers with dual voltage supply OpAmps. The formula for calculating the output voltage is shown below:

where VVGND = 2.5 V

The GreenPAK operates as an analog voltage converter into a PWM signal with the necessary parameters for controlling a servo motor.

The servo motor used in this design is the TowerPro SG90 - Micro Servo, as shown in Figure 3. One can substitute other servo motors having the same control type.

Figure 3: TowerPro SG90 - Micro Servo

This servo can rotate approximately 180 degrees (90 in each direction) and works just like a standard radio control (RC) model servo. Typical with RC servos, the position is determined by the PWM duty cycle. The center position "0" corresponds with ~1.5 ms pulse width. The right most position "90" – ~2.5 ms, and the most left position "-90" – ~0.5 ms.

Design

The design implementation with the GreenPAK is shown in Figure 4.

Figure 4: Design Implementation with GreenPAK

The design is based on three parts:

  1. Input voltage to time width converter;
  2. 50 Hz generator;
  3. Pulse width shaper.

The first part was implemented using PGA, ADC and CNT3/DLY3/FSM1 blocks. The PGA block is configured with default settings, so the PGA output will equal the input signal on PIN6 (A_IN). The ADC block is configured with default settings as well (see Figure 5).

Figure 5: The ADC Block Properties

The ADC block converts input voltage within the range of 30 mV to 1030 mV into an 8-bit digital code (min value is 0 for 30 mV and max value is 255 for 1030 mV). The CNT3/DLY3/FSM1 block is configured as a delay that takes counter data from the ADC. This ensures voltage to time delay conversion.

The second part was implemented using 2-bit LUT0 and CNT0/DLY0 blocks. LUT0 was configured as an inverter. The CNT0/DLY0 block is configured as a delay for 19.98 ms (~50 Hz). The combination of these blocks implements a signal generator where its period equals the delay time.

The third part was implemented with CNT1/DLY1, OSC, CNT2/DLY2/FSM0 and CNT3/DLY3/FSM1 blocks. The CNT1/DLY1 block generates a constant pulse having a width of 0.5 ms which is equal to one of the extreme positions of the servo motor. The OSC and CNT2/DLY2/FSM0 blocks form the clock pulses for CNT3/DLY3/FSM1 block. With these blocks we can control the pulse width that provides the other extreme position of the servo motor. The CNT3/DLY3/FSM1 block with the maximum counter data of 255 and the frequency (clock) formed by the combination of OSC and CNT2/DLY2/FSM0 blocks provides a pulse width of 2 ms. The functionality waveforms of the design operation are shown in Figure 6 and Figure 7 (Channel 1 is PIN6 (A_IN); Channel 2 is PIN14 (OUT)).

Figure 6: GreenPAK Design Operation Scope Shot
Figure 7: PWM Signal for Center Servo Position

Conclusions

This application note describes how to control a servo motor using a flex sensor and Dialog GreenPAK IC. This design can be helpful in robotic controls, robotic handlers, or other similar devices. The design is easy to reconfigure for any customization (flex sensor resistive parameter or servo motor PWM frequency and pulse width parameter). The Dialog GreenPAK has several advantages compared to competing solutions such as its small size, lower power consumption, simplicity and functionality, and low cost.