Jitter elimination at optical control of servomotors
Abstract
The article describes the application of microcontroller PIC18F25K22 to servomechanism electronics built – in the model of car. Model is controlled optically, in the infrared part of the spectrum. Used microcontroller is optimal for this application – it has timers with capture facilities, sufficient number of PWMs, powerfull instruction set. The main task for microcontroller is to process incoming PWM signals S1, S2 (having jitter) into output PWM signals P1, P2 (jitter free). The P1 controls the angle of wheels, and the P2 handles the speed. Values of incoming signals are continuously summarized and rounded. There was choiced method of hysterezis in sophisticated algorithm for setting output PWM signals P1, P2 using tables of duties.
Full text
THEORETICAL AND APPLIED ELECTRICAL ENGINEERING VOLUME: 12 |NUMBER: 2 |2014 |JUNE Jitter Elimination at Optical Control of Servomotors Radek NOVAK , Karel WITAS Department of Telecommunications, Faculty of Electrical Engineering and Computer Science, VSB–Technical University of Ostrava, 17. Listopadu 15/2172, 708 33 Ostrava, Czech Republic radek.nov[email protected], k[email protected] Abstract. The article describes the application of microcontroller PIC18F25K22 to servomechanism electronics built – in the model of car. Model is controlled optically, in the infrared part of the spectrum. Used microcontroller is optimal for this application – it has timers with capture facilities, sufficient number of PWMs, powerfull instruction set. The main task for microcontroller is to process incoming PWM signals S1, S2 (having jitter) into output PWM signals P1, P2 (jitter free). The P1 controls the angle of wheels, and the P2 handles the speed. Values of incoming signals are continuously summarized and rounded. There was choiced method of hysterezis in sophisticated algorithm for setting output PWM signals P1, P2 using tables of duties. Keywords Electronic, light control, microcontroller, PIC18F25K22, PWM, servomechanism. 1. Introduction The main target of works with car model is to control it using light beams on maximal possible distance, in normal daylight conditions. Block schema is on the Fig. 1. Channel 1 serves for angle wheels control, channel 2 controls the speed. This paper describes one of solved tasks - processing of incoming two PWM signals S1, S2 (from standard electronics, with unwished jitter) and generating two output PWM signals P1, P2. To gain output signals P1, P2 jitter-free, it is the aim of all the application. The parameters of both incoming PWM processed signals - period 7 ms, duty 1.0–2.2 ms. Thanks these parameters the task for microcontroller isn`t time-critical. Processor measures width of incoming PWM pulse, and in the rest of the period it is processing measured value. Then rest of the period is in range 6.0–4.8 ms, it is sufficient time for processing. The PIC18(L)F2X/4XK22 Microchip family is powerfull set of 8-bit microcontrollers, that brings C-compiler optimized architecture, 16-bit wide instructions, 31-level software accesible hardware stack, 8×8single-cycle hardware multiplier, 5 CCP (Capture/Compare/PWM) modules, 7 timers/counters, 33 sources of interrupt, SPI bus, I2C bus, operating frequency from DC to 64 MHz, [3]. 2. General Description of Problem and its Solving There are together two PWM signals in the system, P1 and P2. Together detector of light control signal is photodiode PD, Fig. 1. Existing electronic circuits unfortunately produce some parasit signals, those show themselves finally as some jitter (variation) of width pulse (signals of comparators S1, S2; Fig. 1). In the last time it led to sure mechanical vibration of servomechanism and its heating. Fundament of solution consists in created software, that exploates facilities of PIC18F25K22. The algorithm processing the signal passes over these parts: •measuring of incoming pulse width, •deciding whether actualization of duty for servomechanism is needed. If yes, then new value of duty is red from the table of duties, and is sent to PWM hardware of microcontroller. In channel 2 is only characteristic a few complicated, it has "V" shape (Fig. 3). Shape of characteristic has no influence on speed of application, because difference (compared with channel 1, see Fig. 2) is only in values of duties, that are held in the field of constant values duty2[ ]. Analogic the channel 1 has its values in field duty1[ ]. c 2014 ADVANCES IN ELECTRICAL AND ELECTRONIC ENGINEERING 117
THEORETICAL AND APPLIED ELECTRICAL ENGINEERING VOLUME: 12 |NUMBER: 2 |2014 |JUNE Fig. 1: Block schema of the system. Fig. 2: Convert characteristic Channel_1. Significant simplification, as to the creating table of duties, brings preprocessor of C language [1]. Classic (and lenghty) approach, how to create table values, is to calculate them handly using a calculator. Preprocessor of C enables assignment using arithmetic expression, even conditional arithmetic expression (that was used), [5]. Only a parameters “begin_duty”, “end_duty”, “index” must be specified by a man in the source file. 2.1. Incoming Pulse Width Measuring There was used gated timers CT1 (for signal S1), CT3 (for signal S2) in the solution, in [3]. They are "gate controlled", this facility is used for pulse width measuring. Timer is increasing only if measured signal (pulse) connected to gate control pin is H. If measured signal is L, then timer stays on reached value. Falling edge invokes an interrupt. In interrupt service routine the (reached) value of the timer is red and copied into variable. In final the timer is cleared by instruction. 2.2. Processing of Measured Widths This algorithm is descripted in simplyfied flowchart Fig. 6. So transition to a new duty of PWM is performed only on label "lab_c" of flowchart. If the duty of PWM changes hardly, then servomechanism is susceptible to glimmering. So conclusion operations are necessary for a smooth transition to next duty. There was selected simple principe of arithmetic averaging, Fig. 4. Classic solution how to calculate arithmetic average is to summarize all values v[i] using for cyclus (i= 1 to n), and then to divide the sum by the n. But in described system the task is little different. There is a clever solution, to use field v[ ] by a cyclic manner, and to establish variable "iom" i.e. index of the oldest member in the field v[ ]. In showed example the "iom" has value 5. At the moment of actualization all values will stay unchanged, from sum is substracted the oldest member v[iom], then to sum is added actually measured value, v[iom] is rewritten onto this actually measured value (it becomes by the most actual value), and "iom" is incremented on value 6 (increm. modulo 8, field v[ ] has 8 members). So by this elegant manner the sum is actualized. Described manner [9] is much faster than c 2014 ADVANCES IN ELECTRICAL AND ELECTRONIC ENGINEERING 118
THEORETICAL AND APPLIED ELECTRICAL ENGINEERING VOLUME: 12 |NUMBER: 2 |2014 |JUNE Fig. 3: Convert characteristic Channel_2. Fig. 4: Arithmetic average (iom is index of the oldest member). sumarizing of all values v[i] in cyclus for-type. Now calculating arithmetic average is executed, for this reason suitable size of field is power of 2, in the application was used size 8. Firstly sum is rounded by adding 1 in bit b2 position. Then value of the arithmetic average is simply calculated as sum shifted about 3 positions to right (operation is equal to dividing by 8), it is much faster manner than calculation of dividing "sum / n". Subsequent processing described in part 3 is working with this value of the arithmetic average. 3. Determining of Next Duty There will be explained the situation in channel 1(in channel 2 it is analogous). Principe of the method is shown in Fig. 5, [6], [7]. Microprocessor must determine duty of the output signal P1 for next time. Principle will be explained on concrete values. Used symbols and variables: •aw: actual width of the input signal S1, in shown example it has value 431mc, •duty[ ]: field of fillings for output PWM signal P1, •oi: old index, duty[oi] is just now ruling filling, in the example it has value 26, •ni: new index, its value is calculated from "aw", in example it has value 27, •AZ: attractive zone, it is the size of interval used for characteristic with hysteresis. Value of AZ is 2 in shown example, •IDAZ: interval determined by attractive zone, •IBD: interval of big difference in comparison with "oi", it is used for evaluating of "ni", it is equal to (0, oi −2i∪hoi + 2,255i. It is assumed, that momentarily signal P1 with duty[oi=26] is generated by PWM hardware of microprocessor. This momental duty[26] is the result of last evaluations. The "aw" serves as an argument for calculating the "ni" through rounded value. Rounded value is derived from "aw". Rounding is made on the base of value bit b3 in "aw". So values 392–407 are rounded to 400, 408–423 rounded to 416, 424–439 rounded to 432. It is clear, that rounded values have bits b3—b0 equal to 0. Our "aw" = 431 is rounded to 432. Rest bits b15—b4 of rounded value will become by bits b11–b0 of "ni" (by shift about 4 positions to right). This implies that "ni" in our case is 27. Transition to new duty has next logic. If "ni" ∈IBD that means "ni" is considerably different in comparison with "oi", then transition onto duty[ni] is carried in signal P1, and from this moment "ni" stays by "oi" (oi = ni). Situation "ni" is as to the "oi" different only a few means (ni == (oi −1)) OR ((oi + 1) == ni). Our case (oi = 26, ni = 27) is different only a few, therefore subsequently hysteresis principle is used. Hysteresis principle uses attractive zone "AZ". If "aw" lies in "IDAZ" then transition to new duty[ni = 27] is realized. It is our case, "aw = 431" lies in "IDAZ". It is clear, that the hysteresis depends on the size of "AZ", little size of "AZ" means big hysteresis and vice-versa. Our "AZ" has size 2, hysteresis is big. Using of hysteresis principle in a situation different only a few is necessary. It can be demonstrated on the situation, when exact width of incoming pulse is somewhere between values 423 and 424mc (width of incoming pulse is continuous quantity). Value of "aw" then is sometimes 423, sometimes 424. In solution without hysteresis principle sometimes duty would be of value duty[26], sometimes of value duty[27], and the jitter of length in output impulse P1 would not be eliminated. c 2014 ADVANCES IN ELECTRICAL AND ELECTRONIC ENGINEERING 119
THEORETICAL AND APPLIED ELECTRICAL ENGINEERING VOLUME: 12 |NUMBER: 2 |2014 |JUNE Fig. 5: Width to index transformation. 4. Experimental Application for PIC18F25K22 removing the jitter is a matter of Radek Novak. Electronic circuits was made by K. Witas, total design and realisation electrooptic transmitter and receiver. There was used photodetector BP104F in optical receiver. The threshold optical power limit was found at 15 nW. There are considerably differences as to the indoor experiments and outdoor experiments. The worst case occurred on the roads inside nature, he built optical channel distance was no longer than 4.2 m. Vice-versa the best situation was within house hall and university corridor, The optical information transfer channel held stable up to 9.3 m distance. In all experiments was servomechanics working without jitter, thank to application of PIC18F25K22. The jitter-free solution has a consequence, that angle-wheels positioning is divided on 17 levels (8 for left, 1 for direct, 8 for right); also speed is divided on 17 levels too (8 for forward, 1 for stop, 8 for backward). Optical transmitter can be divided into two parts: the first of them looks after two potentiometers giving information about the angle of wheels and speed. Their voltage levels are translated to the pulses widths and sent off to the power amplifier. Fig. 6: Flowchart diagram. c 2014 ADVANCES IN ELECTRICAL AND ELECTRONIC ENGINEERING 120
THEORETICAL AND APPLIED ELECTRICAL ENGINEERING VOLUME: 12 |NUMBER: 2 |2014 |JUNE Fig. 7: Dependence power on distance. The second part employs two powers LEDs H2W2950 (Roithner Laser Technik) and their current booster. The 950 nm light wavelength has been used. To get square light coverage coming over the line of sight, the beam focused lenses are omitted. The light of LEDs runs to space without any modification. Figure 7 describes the dependence of optical power on the light source distance. Optimal regression curve in this dependence is hyperbolic [2], [4]. Then assumed dependence of power on distance is: p=a+b d,(1) where pis power [µW], a, b are coefficients [µW], [µW.m], and dis distance [m]. Now is for next derivation used a substitution. For constants a, b then was derived formulas [4]: a=PpiPt2 i−PtipiPti nPt2 i−(Pti)2,(2) b=nPtipi−PtiPpi nPt2 i−(Pti)2.(3) Concretely calculated values are a = 1.017 [µW], b = 8.316 [µW.m], they depend on measured values shown in Fig. 7. 5. Conclusion The described application is designed for controlling of two servomotors. It has meaning at combustion engines, because they need conversion of electric signals into mechanical. There is needing e.g. choke valve handling in combustion engine besides direction handling. As to the electromobil, for next time is intended solution with one servomotor only. Control signal then must be modified and gained to be able to supply electromotor. Probably it will lead to conversion of one PWM signal into two signals; the first will contain direction information, and the second will be powerfull PWM having duty 0–90 %. So probably next works will deal with full bridge with the motor in diagonal. There must be defined idle duty of transmitter signal, whereat will be (default) defined straight direction with 0 % duty of powerfull PWM. If the duty from transmitter will increase, then forward movement will stay active with growth of duty towards 90 %. Vice-versa if the duty from transmitter will decrease, then a signal astern will be activated, in this situation powerfull signal will again increase towards 90 % respecting the duty fall. In the current solution the processor PIC18F25K22 was succesfully applied for eliminating jitter of servos. The described application exploates facilities of processor only very little, and it opportunity to increase it about other needed functions in next time. Acknowledgment The research described in this article could be carried out thanks to the active support of the Ministry of Education of the Czech Republic within the project SP2014/147. This article was supported by project VG20102015053(GUARDSENSE-The modern structure of photonic sensors and new innovative principles for intrusion detection systems, integrity and protection of critical infrastructure) and Technology Agency of the Czech Republic TA03020439 and TA04021263. The research has been partially supported by the project no. CZ.1.07/2.3.00/20.0217 (The Development of Excellence of the Telecommunication Research Team in Relation to International Cooperation) within the frame of the operation programme Education for competitiveness financed by the European Structural Funds and from the state budget of the Czech Republic. References [1] Microchip Technology Inc. MPLAB R XC8 C Compiler: User’s Guide [online]. 2012. ISBN 978-162077-206-5. Available at: http://ww1.microchip.com/downloads/en/ DeviceDoc/xc8-v1.21-manual.pdf. [2] BACH, E. and J. O. SHALLIT. Algorithmic number theory. Cambridge, Mass.: MIT Press, 1996. ISBN 0-262-024055-1. [3] Microchip Technology Inc. PIC18(L)F2X/4XK22: Data Sheet [online]. 2010. ISBN 978-1-60932-734c 2014 ADVANCES IN ELECTRICAL AND ELECTRONIC ENGINEERING 121
THEORETICAL AND APPLIED ELECTRICAL ENGINEERING VOLUME: 12 |NUMBER: 2 |2014 |JUNE 7. Available at: http://ww1.microchip.com/ downloads/en/DeviceDoc/41412F.pdf. [4] REKTORYS, K. Prehled uzite matematiky. Praha: Prometheus, 2000. ISBN 978-80-7196-180-21. [5] SALOUN, P. Jazyk C. Praha: Neokortex, 2003. ISBN 80-863-3008-7. [6] ATALLAH, M. J. and M. BLANTON. Algorithms and theory of computation handbook. Boca Raton: CRC Press, 2010. ISBN 978-1-58488-820-8. [7] BRTNIK, B. and D. MATOUSEK. Algoritmy císlicoveho zpracovani signalu. Praha: BEN - technická literatura, 2011. ISBN 978-80-7300-400-2. [8] BRADLEY, A. R. Programming for engineers: a foundational approach to learning C and Matlab. New York: Springer, 2011. ISBN 978-364-2233029. [9] HLAVAC, V. and M. SEDLACEK. Zpracovani signalu a obrazu. Praha: CVUT, 2007. ISBN 97880-01-03110-0. About Authors Radek NOVAK was born in 1961. He received his M.Sc. from VSB–Technical University of Ostrava in 1984. His research interests include single-chip microcontrollers, automation, real-time applications, industrial applications. Karel WITAS was born in 1973. He received his M.Sc. from VSB–Technical University of Ostrava in 1997. His research interests high-tech electronics, fast signal electronics, electronics for very small signals. c 2014 ADVANCES IN ELECTRICAL AND ELECTRONIC ENGINEERING 122