Overview of the servo system A servo is a device that has a shaft that can be positioned to specific angular positions

by sending the servo a coded signal. As long as the coded signal exists on the input line, the servo will maintain the angular position of the shaft. As the coded signal changes, the angular position of the shaft changes. The servo is an automatic device that uses error-sensing feedback to correct the performance of a mechanism. The term correctly applies only to systems where the feedback or error-correction signals help control mechanical position or other parameters. A common type of servo provides position control. Servos are commonly electrical or partially electronic in nature, using an electric motor as the primary means of creating mechanical force. Other types of servos use hydraulics, pneumatics, or magnetic principles. Usually, servos operate on the principle of negative feedback, where the control input is compared to the actual position of the mechanical system as measured by some sort of transducer at the output. Any difference between the actual and wanted values is amplified and used to drive the system in the direction necessary to reduce or eliminate the error. This procedure is one widely used application of control theory. There are various types of servo motors, the ones employed here are: • • RC servo motor and DC servo motor

RC servo motor: RC servos are composed of an electric motor mechanically linked to a potentiometer. Pulsewidth modulation (PWM) signals sent to the servo are translated into position commands by electronics inside the servo. When the servo is commanded to rotate, the motor is powered until the potentiometer reaches the value corresponding to the commanded position. The servo will move based on the pulses sent over the control wire, which set the angle of the actuator arm. The servo expects a pulse every 20 ms in order to gain correct information about the angle. The width of the servo pulse dictates the range of the servo's angular motion. A servo pulse of 1.5 ms width will set the servo to its neutral position, or 90°. For example a servo pulse of 1.25 ms could set the servo to 0° and a pulse of 1.75 ms could set the servo to 180°. The physical limits and

but a general servo's angular motion will travel somewhere in the range of 180° .210° and the neutral position is almost always at 1.timings of the servo hardware varies between brands and models.5 ms . .

The device with flash program memory allows the same device package to be used for prototyping and production. The separate instruction and data buses of the Harvard architecture allow a 14 bit wide instruction word with a separate 8 bit wide data bus. a large register set is used to achieve high performance level. thus reducing cost. except for program branches (which require two cycles). This is useful on the development of many applications where the device may not be easily applicable. fully static 8bit microcontroller. The two stage pipeline allows all instructions to execute in single cycle. A total of 130 instructions are available. clock. Microcontrollers are designed for small or dedicated applications. enhancing system reliability and reducing power consumption. Microcontrollers are used in automatically controlled products and devices. and memory. CMOS. high performance. (such as rate information). Additionally. as well as a typically small amount of RAM. A highly reliable watchdog timer with its own ON-CHIP RC oscillator provides protection against software lock-up. The user can wake the chip from sleep through several external and internal interrupts. low power microcontroller with advanced RISC architecture. timers. resets. The sleep mode offers power saving. I/O ports. Program memory in the form of flash or OTP ROM is also often included on chip. . In circuit reprogram ability allows the code to be updated without the device being removed from the application. but the prototypes may require code updates as well as in remote applications.An insight on AVR Atmega8 microcontroller Introduction to microcontrollers A microcontroller is a small computer on a single integrated circuit consisting internally of a relatively simple CPU. The AtmegaX family has special features to reduce external components. Why Atmega8? It is a high performance. The AtmegaX family is of low cost.

The PWM resolution in bits can be calculated using the following equation: . Phase and frequency correct frequency mode. motor speed. electronic locks. The I/O flexibility makes the AtmegaX very versatile even in areas where no microcontroller use has been considered before (example: timer functions. However. In Atmega8 there are three PWM modes namely Fast PWM mode. these modes are preferred for motor control applications. The main difference between the phase correct and the phase and frequency correct PWM mode is that the time OCR1x Register is updated by the OCR1x Buffer Register. The serial in system programming features offers flexibility of customizing after complete assembly and testing. the Output Compare (OC1x) is cleared on the Compare Match between TCNT1 and OCR1x while up counting. serial communication. security codes etc. The PWM resolution for the phase and frequency correct PWM mode can be defined by either ICR1 or OCR1A. In inverting Compare Output mode. The phase and frequency correct PWM mode is based on a dual-slope operation. Servo motor control with Atmega8: The servo motor is controlled using PWM pulses. and the maximum resolution is 16-bit (ICR1 or OCR1A set to MAX). The counter counts repeatedly from BOTTOM (0x0000) to TOP and then from TOP to BOTTOM. The dual-slope operation gives a lower maximum operation frequency compared to the single-slope operation. due to the symmetric feature of the dual-slope PWM modes. receiver frequency. motor direction. and set on the Compare Match while down counting. The phase and frequency PWM mode (WGM13:0 = 8 or 9-waveform generation mode) provides a high resolution phase and frequency correct PWM waveform generation option. In non-inverting Compare Output mode. the operation is inverted. Phase correct PWM mode. capture & compare mode and PWM functions ). security devices and smart cards.The AtmegaX fits perfectly in the applications ranging from high speed automotive and appliance motor control to low power remote senses. We use the Phase and frequency correct PWM mode to control the servo motor. The minimum resolution allowed is 2-bit (ICR1 or OCR1A set to 0x0003). The Flash/EEPROM technology makes customization of application programs (transmitter codes. This feature can be used to serialize a product.) extremely fast and convenient. store and calibrate data.

The small horizontal line marks on the TCNT1 slopes represent compare matches between OCR1x and TCNT1. The diagram includes non-inverted and inverted PWM outputs. The counter has then reached the TOP and changes the count direction. The TCNT1 value will be equal to TOP for one timer clock cycle. The figure shows phase and frequency correct PWM mode when OCR1A or ICR1 is used to define TOP. The timing diagram for the phase correct and frequency correct PWM mode is shown on Figure . The OC1x Interrupt Flag will be set when a Compare .In phase and frequency correct PWM mode the counter is incremented until the counter value matches either the value in ICR1 (WGM13:0 = 8). or the value in OCR1A. The TCNT1 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation.

When either OCR1A or ICR1 is used for defining the TOP value. the OC1A or ICF1 Flag set when TCNT1 has reached TOP. timing diagram. The Interrupt Flags can then be used to generate an interrupt each time the counter reaches the . Figure : Phase and frequency correct PWM mode. The Timer/Counter Overflow Flag (TOV1) is set at the same timer clock cycle as the OCR1x Registers are updated with the double buffer value (at BOTTOM).Match occurs.

If the OCR1x is set equal to BOTTOM the output will be continuously low and if set equal to TOP the output will be set to high for non-inverted PWM mode.TOP or BOTTOM value. if the base PWM frequency is actively changed by changing the TOP value. In phase and frequency correct PWM mode. the length of the rising and the falling slopes will always be equal. the OCR1A Register is free to be used for generating a PWM output on OC1A. This gives symmetrical output pulses and is therefore frequency correct. As Figure shows the output generated is. the compare units allow generation of PWM waveforms on the OC1x pins. For inverted PWM the output will have the opposite logic values. The actual OC1x value will only be visible on the port pin if the data direction for the port pin is set as output (DDR_OC1x). The PWM waveform is generated by setting (or clearing) the OC1x Register at the Compare Match between OCR1x and TCNT1 when the counter increments. Since the OCR1x Registers are updated at BOTTOM. a Compare Match will never occur between the TCNT1 and the OCR1x. in contrast to the Phase Correct mode. By using ICR1. However. Using the ICR1 Register for defining TOP works well when using fixed TOP values. symmetrical in all periods. and clearing (or setting) the OC1x Register at Compare Match between OCR1x and TCNT1 when the counter decrements. or 1024). 256. using the OCR1A as TOP is clearly a better choice due to its double buffer feature. Setting the COM1x1:0 bits to 2 will produce a noninverted PWM and an inverted PWM output can be generated by setting the COM1x1:0 to 3. 64. . 8. The PWM frequency for the output when using phase and frequency correct PWM can be calculated by the following equation: The N variable represents the prescaler divider (1. When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of all of the Compare Registers. The extreme values for the OCR1x Register represent special cases when generating a PWM waveform output in the phase correct PWM mode. If the TOP value is lower than any of the Compare Registers.

Flowchart: START Set control input Initialize TCCR1x register for bit resolution Initialize TCCR1x register for prescaler Initialize OCR1x for required duty cycle END .

Sign up to vote on this title
UsefulNot useful