Closed-loop control of filter wheel for 70 cm GROWTH telescope
The GROWTH (Global Relay of Observatories Watching Transients Happen) – India telescope at Hanle in Ladakh is India’s first effort towards a fully robotic telescope. It is also the first one dedicated for a rapid follow-up of transient events in the universe. Mounted in between the CCD camera and the output port of the GROWTH telescope is a filter wheel which houses 6 filters whose centers are located on the same pitch circle. These filters are rotated into position in a specified sequence by a stepper motor coupled to the filter wheel shaft. A closed-loop positioning system has been designed to rotate the filter wheel and ensure that the correct filter is positioned before the camera in the required sequence, in line with stringent performance requirements. This filter wheel controller system is realized with a 16-bit dsPIC33F microcontroller. The Quadrature Encoder Interface module is used to interface with an optical encoder attached to the filter wheel shaft. The Output compare module on the microcontroller has been used to generate the pulses to the stepper motor driver which will be used to move the stepper motor. The stepper motor rotation is ramped by varying the frequency of the pulses from pre-defined maximum to minimum frequencies to reduce the inertial effects of the filter wheel. An algorithm has been designed to calculate the shortest distance between any two filters and rotate the motor accordingly in either direction. As a marked improvement from the previous system, an interrupt system has been designed to ensure that the encoder values and desired position match with a very high accuracy. The electronic components have been carefully chosen keeping in mind the low temperatures of the observation floor of the telescope at Hanle. A GUI has been designed to allow the user to select the required filter, after which, the filter wheel is rotated to the position within 6 arc seconds of the position in a maximum of 25 seconds.
Keywords: closed-loop positioning system, quadrature encoder interface, filter wheel controller
|QEI||Quadrature Encoder Interface|
|PWM||Pulse Width Modulation|
|UART||Universal Asynchronous Receiver Transmitter|
|ISR||Interrupt Service Routine|
The 70 cm GROWTH telescope is located at the Indian Astronomical Observatory (IAO) at Hanle in Ladakh. It is a joint project of the Indian Institute of Astrophysics (IIA) and the Indian Institute of Technology Bombay (IITB). This telescope is part of a multi-country collaboration of telescopes dedicated to observe short-lived cosmic transients and near-earth asteroids. Cosmic transients are high-energy events in the universe that are relatively short-lived. It is crucial that these fast-fading events are followed up quickly after the discovery is made. Therefore, a relay of several telescopes spanning several time-zones on earth are required to pass the baton amongst each other to effectively extend the seeing conditions of night-time darkness. The goal of the telescope is to study the optical counterparts of Binary Neutron Star merger events detected by the Laser Interferometer Gravitational-wave Observatory (LIGO), as well as supernovae explosions and nearby asteroids. Transient phenomena such as supernovae are important parts of time-domain astronomy, which is a less- explored frontier in astronomy.
These events emit different frequencies of light, from infrared to ultraviolet. To capture this data, filters are mounted before the Charge Coupled Device camera. The CCD camera captures grayscale images, so different filters are placed before the camera, capturing images in a certain bandwidth. These images are processed to recreate the final image with all the required wavelengths.
These filters are housed in a filter wheel, and must be rotated into place before the camera. As the whole telescope system must eventually be made robotic, a closed loop control system must be designed to ensure the correct filter is positioned into place when the command to move to a certain filter is sent by the user.
The existing filter wheel system at the observatory had several issues related to positioning the filters which surfaced during the operation of the system. At times it would move to an incorrect position or it would not have moved at all. During the homing sequence, the wheel was reported to be continually rotating, without stopping at the Home position. The homing position is the zero point from where all the other positions are calculated. These problems were reported to be more pronounced when the temperature dropped, as the observation floor at Hanle is exposed to temperatures as low as -25 °C. The existing system also had the limitation of unidirectional rotation. This greatly increased the time between transitions, even if the current filter and required filter were close to each other. The existing system also rotates at a fixed speed. This introduces inertial effects which compromises accuracy.These issues needed to be rectified as any future endeavour to make the system entirely robotic would require an extremely accurate and reliable filter wheel control system. The system would have to be a closed-loop control system to minimize human intervention.
The objective is to design a reliable closed-loop control system for a stepper motor that is in line with the stringent accuracy requirements. The transitions between filters must happen smoothly and quickly. The entire system must also be fit for use in the extremely cold environments at the high-altitude location of the observatory at Hanle.
Many improvements were introduced to the existing system. These included ramping the filter wheel, wherein the motor accelerates and decelerates between two pre-determined speeds. Ramping of the filter wheel reduces the overshoot of the filter position significantly. Although conventional methods of ramping have been very well documented, this system required a variant of them so as to reduce the amount of mechanical jitter while the wheel was stationary. The motor rotates at the maximum speed chosen, but as the target position is approached, a low speed is required. A smooth transition must be made between the minimum and maximum frequencies while ensuring that too much time is not spent rotating the motor at low frequencies.
The inaccuracy in positioning was addressed by generating an interrupt when the filter wheel reaches the desired position.
Bidirectional rotation was implemented and an algorithm was developed to calculate the shortest path and direction for the filter wheel to traverse. This is executed every time a new filter position command is given by the user.
Electronic ICs were selected which were rated for -20°C or lower, to ensure that the low temperatures the system will be regularly subjected to would not be compromised.
The microcontroller used to design this system is a dsPIC33FJ128MC802 microcontroller manufactured by Microchip. Datasheets and application notes from Microchip were consulted to implement the various modules and features present in the microcontroller.
The dsPIC33FJ128MC802-I/SP microcontroller is part of a family of 16-bit Digital Signal Controllers with Motor Control PWM. It is a 28 pin DIP IC with up to 128 KB Flash and 16K SRAM. This microcontroller was chosen because it is a military grade IC, meaning that it is rated for an operating temperature from -40 ° C to + 125 ° C. It also has two Quadrature Encoder Interface modules, four PWM signal generators, two UART modules, five 16-bit timers that can also be coupled as 32-bit timers. It has a PWM resolution of 25 ns and a 40 MHz internal clock. Some pins are also 5V enabled.
The main draw of this microcontroller is the fact that it can operate reliably at low temperatures and the presence of an in-built QEI module. The closed-loop control system requires a high-resolution sensor that provides exact positional data of the filter wheel. This data is then processed by the microcontroller and the motor is rotated till the required position is reached.
The sensor used is an Incremental Encoder (Hengslter make RI 58-F). This is an incremental hollow shaft encoder that provides data of 10,000 pulses per revolution. This means that one 360° revolution is broken into 10,000 parts. A number ranging from 0 to 9999 is the output from this sensor to the microcontroller, from which the position of the filter wheel can be deduced. The encoder houses a slotted wheel attached to the shaft of the motor and an emitter/detector module that senses the slots in the wheel. There are three data lines that the encoder produces. These are a channel A, channel B and an INDEX channel. These provide information on the movement of the motor shaft, including distance and direction. The Phase A and Phase B channels have a unique relationship. If Phase A leads Phase B, the direction of the motor is deemed positive, or forward. If Phase A lags Phase B, the direction of the motor is deemed negative, or reverse. The Index pulse occurs once per mechanical revolution and is used as a reference to indicate an absolute position. The data from the encoder is differential in nature, meaning that there are 6 output lines, two for each channel. These 6 differential lines must be passed through a differential line receiver, the AM26LS32A, which produces three lines corresponding to signals A, B and INDEX.
These signals are decoded in the QEI module of the microcontroller. The quadrature decoder increments or decrements the 16-bit Up/Down Counter depending on an UP/DOWN signal that it generates. The QEI module consists of decoder logic to interpret the A and B signals, and the counter accumulates the count. If the encoder is rotating in the forward direction (A leads B), the POSCNT counter is incremented and if the encoder is rotating in the backward direction (B leads A), it is decremented. The value of this counter can then be read directly into a variable, thereby allowing closed-loop control. The decoder can be used in 2x mode and 4x mode. This filter wheel control system implements the 2x mode, which means that the POSCNT register updates its value for every edge of the Phase A signal, producing 20,000 counts from the encoders pulses.
There are two modes of operation of the QEI module, the Maximum Count mode and the Index Mode. In the Index Mode, the Position Counter is reset on detection of the Index Pulse. This is useful during the Homing sequence of the filter wheel, where the filter wheel is rotated until the index pulse is generated. An interrupt is generated at this point, and an Interrupt Service Routine is programmed that services this interrupt. In the Max Count mode, the MAXCNT register is filled with the desired number of encoder counts, and an interrupt is produced when the POSCNT value matches the MAXCNT value. The POSCNT is also reset to zero at this point. This is used when we have to move between filters.
The QEI module has four user accessible registers. The QEI Control register (QEICON) must be configured for either the Index or the Max Count modes. This register controls the QEI operation and provides status flags for the state of the QEI module. The Digital Filter Control register (DFLTCON) controls the digital input filter operation. The other two registers are the POSCNT and the MAXCNT register.
The PWM module of the microcontroller has been configured to produce the pulses that will drive the stepper motor. This is achieved by using the Output Compare module. The Output Compare module can compare the value of a selected time base with the value of one or two Compare registers (depending on the operation mode selected). Furthermore, it has the ability to generate a train of output pulses, on a compare match event. Either Timer 1 or Timer 2 can be selected as the time base for the OC module. The ISR of the timer interrupt used must simply clear the interrupt flag. The main advantage of this approach is the ability to execute on-the-fly frequency changes of the PWM signal. This is required to allow ramping of the stepper motor. The PWM duty cycle is specified by writing to the OCRS register. The duty cycle value can be written at any time, but the duty cycle value is not latched onto the OCR register until the timer resets on a period match. This provides a double buffer for the PWM duty cycle and is essential for glitch-free PWM operation.
The Universal Asynchronous Receiver Transmitter (UART) is a full-duplex asynchronous system that can communicate with peripheral devices, such as personal computers, RS-232 and RS-485 interfaces. It interfaces with the PC via a MAX232 IC to interpret the serial commands. The UART uses the standard Non-Return-to-Zero (NRZ) format (one Start bit, eight or nine Data bits and one or two Stop bits). An on-chip, dedicated, 16-bit Baud Rate Generator can be used to derive standard baud rate frequencies from the oscillator. The UART transmits and receives the Least Significant Bit (LSB) first. The transmitter and receiver of the UART module are functionally independent, but use the same data format and baud rate.
Stepper Motor Driver
The RMCS-1102 Micro-Stepping Motor Driver from Rhino Motion Controls is used as the driver for the Slo-Syn M061-LS06 stepper motor. The stepper motor is a hybrid type bi-polar stepper motor, which has a current rating of 1 Amp. The driver allows the low current signals from the microcontroller to control the stepper motor, which requires higher current than the microcontroller produces. It is basically a currentwhich accepts the low current signal from the controller and converts it into a high current signal which then drives the motor. The driver consists of an H-bridge circuit which allows the motor to be rotated in the clockwise or anticlockwise direction or to be held stationary at a specific position. This driver also allows the user to vary the extent of microstepping of the stepper motor, which means that the resolution of the rotation of the stepper motor can be controlled as well. The Pulse input of the driver takes the PWM signals from the microcontroller and generates signals which are fed to the 2 coils of the stepper motor. The sequence of this signal determines the direction of rotation and extent of microstepping. There is also a direction input which can be used to set the direction of rotation to clockwise or anticlockwise.
As mentioned earlier in Section 2.1.1, there are two modes of operation of the QEI module, the Index Mode and the Max Count mode. The QEI module supports one QEI Interrupt, and this interrupt is triggered by different events in each of these modes. In the Index mode, the interrupt is triggered on detection of the Index pulse. This Index pulse is triggered at a single position of the encoder, which will be considered as the Home position. When this pulse is detected, the POSCNT register is also reset. If the encoder was moving in the forward direction, it is reset to zero, and if it was moving in the backward direction, it is reset to the MAXCNT register value. In this mode, the MAXCNT register stores the value 2N – 1, where N is the maximum encoder counts, which is 10,000. Therefore, the MAXCNT register stores the value 19,999 during Index Mode. When the interrupt is generated, the motor is stopped and the interrupt flag is reset. This happens in the ISR. This mode is used in the Homing mode of the filter wheel. When the command to go to the Home position is received, the motor rotates the filter wheel until the home position is detected. The default configuration is a PWM signal of 2.5 kHz is generated and the filter wheel moves in the anticlockwise direction.
In the Maximum Count mode, an interrupt occurs on position underflow or overflow. This means that when the POSCNT register’s value matches the MAXCNT register’s value, an interrupt occurs. The POSCNT register is also reset. If the filter wheel was rotating in the forward direction, it is reset to zero, and if it was moving in the backward direction, it is reset to the MAXCNT register value. This mode is used when the filter wheel must be moved between filters. Once the number of counts between the current position and the required position is calculated, this value is stored in the MAXCNT register and the motor is rotated. When the interrupt is generated, the motor is stopped and the interrupt flag is reset. This happens in the ISR. This necessitates an algorithm to calculate the smallest number of counts for the filter wheel to traverse, and also change the Direction output to the motor driver.
The filter wheel has 6 filters, as shown in Figure 1. This means that each filter is 60 ° apart from the next. In our setup, the Home position occurs between Filters 4 and 5. Once Home position is reached, it is the zero point of the encoder. From here, all the other filter positions can be calculated. Once a command is received to move to a particular filter, the corresponding value is stored in the MAXCNT register, and the filter wheel is rotated in the required direction. When the filter wheel reaches the desired position, the interrupt occurs, and the stepper motor stops rotating.
Mode switching is implemented using the QEIM bits of the QEICON register. When QEIM= 4, it is in Index Mode and when QEIM = 5, it is in Max Count Mode. The corresponding value is placed in the QEIM bits when the Homing command is received from the user, or when any of the other commands for the filter positions are received.
During operation, it was noticed that there is a slight jerk in the clockwise direction every time the motor began rotating. In Max Count mode, if the encoder is travelling in the forward direction (A leads B), and the value in the POSCNT register matches the value in the MAXCNT register, POSCNT resets to ‘0’ on the next occurring quadrature pulse edge that increments POSCNT. An interrupt event is generated on this rollover event. If the encoder is travelling in the reverse direction (B leads A), and the value in the POSCNT register counts down to ‘0’, the POSCNT register is loaded with the value in the MAXCNT register on the next occurring quadrature pulse edge that decrements POSCNT. An interrupt event is generated on this underflow event. The essence of this is that the counter increments towards the required count value from zero in the forward direction of the encoder, and decrements from the count value to zero in the backward direction of the encoder. This caused an interrupt to be generated as soon as the slight jerk occurred, causing the motor to be stopped. It was also noticed that this problem only surfaced during rotation in the backward direction. This compromised the entire positioning system.
To rectify this, the SWPAB bits in the QEICON register were used. The direction of quadrature counting is determined by the Phase A and Phase B Input Swap Select bit, SWPAB. If SWPAB = 0, the Phase A input is fed to the A input of the quadrature counter, and the Phase B input is fed to the B input of the quadrature counter. Therefore, as the Phase A signal leads the Phase B signal, the quadrature counter is incremented on each edge. This means that clockwise direction is considered to be the forward direction of the encoder. Setting the SWPAB bit to a logic ‘1’ causes the Phase A input to be fed to the B input of the quadrature counter, and the Phase B signal to be fed to the A input of the quadrature counter. Therefore, if the Phase A signal leads the Phase B signal, the Phase A input to the quadrature counter lags the Phase B input. This means that the anticlockwise direction is recognized as rotation in the forward direction.
The SWPAB bit is 0 whenever the filter wheel is to be rotated in the clockwise direction and 1 whenever it is rotated in the anticlockwise direction. This means that rotation in both directions will increment the POSCNT register, which effectively nullified the effect of the slight jerk in the gear system.
The previous system employed a different method to stop the motor at the required position. The values from the encoder were continuously polled, and when the value matched with the required filter position, the motor was stopped. This means that there is a time delay, as the time to poll the values must also be taken into account. The program checked whether the values matched, and if so, the motor would be stopped. If the value was not polled at the instant when it matched the filter position, the motor would continue rotating another 360°. This caused the filter wheel to often miss the desired position. The interrupt system designed is a better approach as the POSCNT and MAXCNT registers are compared instantly and an interrupt is triggered.
The flow chart shown in Figure 3 depicts this interrupt system.
Once the system is switched on, it enters into the Idle Mode. Once the Homing command is received, the PWM pulses are produced till the Index Pulse Interrupt is triggered. After this, the system re-enters the Idle Mode. If any of the Filters are requested, the Encoder Value of that Filter is loaded to MAXCNT and the pulses are turned on till the Max Count Interrupt is triggered. Then the system re-enters the Idle Mode.
The block diagram of the entire closed loop system is shown in Figure 4.
Commands are sent from the User PC to the UART Module via the MAX232 IC. The Processor controls the QEI Module and the PWM Module, which uses a Timer (Timer 2) to generate the time base. The Encoder sends data to the QEI Module via the Differential Line Receiver. The Processor continuously sends back the current position of the filter wheel to the User PC. Based on the command received, the Direction is set and the PWM Module generates pulses until the QEI Module detects the QEI Interrupt. The PWM signals are fed to the Motor Driver, which sends the current amplified signals to the stepper motor, which rotates the filter wheel.
The speed of the motor is determined by the frequency of the PWM signal generated by the microcontroller. The higher the frequency, the faster the motor rotates. But at high speeds, the accuracy of the positioning of the filters is compromised as the inertial effects of the filter wheel becomes large. To prevent this from happening, the motor must rotate slowly as the required position approaches. Therefore, ramping must be implemented.
When the command is received, the frequency is slowly increased from the minimum frequency to the maximum frequency, and as it approaches the required position, it decreases from the maximum to minimum frequency. The corresponding Period Register (PR) of the PWM time base timer (Timer 2) is calculated and updated for each frequency along the ramp. The PWM module allows on-the-fly frequency changes as it possesses a buffer to store the next Period Register values. The frequency can be written at any time, but this value is not latched to the OCR register until the timer reset on a period match.
The minimum value of the frequency chosen is 200 Hz, as the positioning accuracy is very good at this frequency. If the motor is held at 200 Hz, however, there is jitter in the system. This jitter was observed also at 300 Hz. The graphs in Figure 5 and 6 show the oscillations from the required position of the filter wheel system. Each of the spikes represent a deviation from the position of approximately 6 arc seconds.
At 500 Hz Holding frequency, these spikes are very rare, only one spike can be seen from more than three times the samples of the 200 Hz and 300 Hz cases. This can be seen in Figure 7.
Thus, 500 Hz was chosen as the optimal value for when the motor is stationary.
The maximum motor frequency was chosen to be 2500 Hz. Any frequency higher than this resulted in noisy rotation of the filter wheel.
The gear ratio is 5.2. The extent of microstepping is 12,500 steps per rotation.
The maximum and minimum speeds can then be calculated to be 2.31 rpm and 0.18 rpm respectively.
The ramping profile of the entire system is shown in Figure 8. The data was sampled over two transitions between filters. While the filter wheel is stationary, the frequency is 500 Hz. When the command is sent by the user, the frequency is increased to 2.5 KHz. The filter wheel accelerates in this phase. After the maximum frequency is attained, the motor continues to coast at this speed, until the filter wheel is 600 encoder counts short of the required filter position. From here, it decrements to 200 Hz and maintains this frequency until the required position is reached. Once the position is reached, the frequency increases back up to 500 Hz and the motor is held at this frequency till the next command is sent by the user.
In the graph shown in Figure 9, we can observe the ramping profile over one transition between filters, which is 3333 encoder counts. The frequency starts to drop from the encoder value 2733 until it reaches 200 Hz, then it stays constant at 200 Hz till the value 3333 is obtained. During the acceleration phase, the frequency increases from 500 Hz to 2.5 kHz in less than 600 steps. The frequency gradient during both the acceleration and deceleration phases are equal.
The User can send the required filter positions through a Graphical User Interface (GUI). The first step is to initiate the Homing Sequence. Once Homing is done, the Target and Current Positions can be seen, as shown in Figure 10.
The User can change the encoder values corresponding to each filter position. When the button for any of the filters is clicked, Target Position is updated and the value is sent via RS232 to the microcontroller. The filter wheel is rotated.
The current encoder values can be seen on the Current Position icon.
This allows the position of the filter wheel to be known even during rotation of the motor as shown in figure 11, which shows a transition to Filter 2. As the motor rotates, the Filter Wheel Status LED will be red, and once the rotation stops, it turns green. This indicates that new commands can be sent to the microcontroller.
The final state is shown in Figure 12, after the filter wheel has been moved to Filter 2.
To overcome the problems of the previous system, an interrupt system was developed. The closed loop control system also incorporates bidirectional rotation, in order to save time during transitions. The stringent accuracy requirements were met while keeping the time between transitions to a minimum. Algorithms to decide shortest number of steps to travel and the direction to rotate were designed and implemented. Ramping was used to improve the overall accuracy of the system, while still maintaining fast transitions. The frequency range was chosen with a maximum of 2.5 kHz and minimum of 200 Hz keeping in mind the trade-off between quick transitions and accuracy of the system. Data was collected on the motor stability at various frequencies to determine the range. The ramping profile of the entire system was also obtained.
The filter wheel control system positions the filters in the required positions, with high accuracy and reliability.
Figure 13 shows the filter wheel setup.
Figure 14 shows the gear coupled to the stepper motor on the right and the filter wheel on the left.
In order to test the reliability of the system in the low temperatures it will be exposed to during observations, cold room testing should be done. This will ensure that none of the components used will fail while exposed to long periods of time in temperatures as low as those at Hanle, Ladakh. A single Printed Circuit Board will be made with all the electronics.
The system developed is an upgrade from the existing system. It can also be easily integrated with any future systems. This allows it to be incorporated into the future plans to make the entire telescope system robotic.
1. dsPIC33FJ32MC302/304, dsPIC33FJ64MCX02/X04 and dsPIC33FJ128MCX02/X04 16-bit Digital Signal Controllers (up to 128 KB Flash and 16K SRAM) with Motor Control PWM and Advanced Analog
2. Section 15: Quadrature Encoder Interface (QEI)
3. GS002 Measuring Speed and Position with the QEI Module
4. AN1307 Stepper Motor Control with dsPIC DSCs
5. Universal Asynchronous Receiver Transmitter (UART)
6. Output Compare
7. Section 32: Interrupts (Part 3)
8. Section 30: Peripheral Pin Select
9. Section 10: I/O Ports
10. Section 11: Timers
11. Section 14: Motor Control PWM
1. Hengstler Technical datasheet, Incremental Encoder RI 58-F
2. AM26LS32AC Quadruple Line Differential Line Receiver
3. MAX3232 3-V to 5.5-V Multichannel RS-232 Line Driver /Receiver
Documents and Application Notes
1. Atmel AVR446: Linear speed control of stepper motor
2. Control of Stepping Motors, A Tutorial; by Douglas W. Jones, The University of Iowa, Department o
3. Analog Devices AN-960 Application Note, RS-485/RS-422 Circuit Implementation Guide by Hein Marais
4. Rhino Motion Controls RMCS-1102 Micro-Stepping Motor Driver Installation Manual and Datasheet
I would like to thank my guide Dr. G. C Anupama, and D.V.S Phanindra for all their help and support.