Natalie C. Landon-Brace edited Servos.tex  about 10 years ago

Commit id: 75d70b006df25fba0cc024484c915db437392291

deletions | additions      

       

\subsubsection{Sending Signals to Servo Motors}  The servos are another significant electormechanical component as they are required to turn on the lights. The position of the servo is determined by the Pulse Width Modulation signal (PWM) coming from the PIC's RC2 port. The CCP1CON register was configured for PWM, the Timer2 was initialized and the duty cycle was set for both the "Lights On" (ON) Position and the "Lights Off" (Neutral) Position. The duty cycle for ON was 99\% and the duty cycle for Neutral was 6\%. The code for the neutral position of PWM is shown in Figure \ref{fig:SERVOS}.  \subsubsection{Determining Light Presence}  It was found that the yellow sensors were the most reliable and as such they were also used for presence detection. This was done by sending a 4-bit select signal to an analog mux, and converting the incoming voltage read to a 10-bit binary number using ADC before the candlelights were turned on. The number was then compared to the threshold voltage rating of 0.8 V. If the voltage from the sensor was greater than 0.8, the light was considered not present as it meant the LEDs under the tray were shining through the holes. Conversely, if the voltage rating was less than 0.8 V it meant the light was present, so a temporary "pass" value was recorded. The code for this subroutine is shown in Figure \ref{fig:PRESENCE} and was repeated for each well on the tray.  \subsubsection{Determining if the LED is On}  Determining if the light is on required effectively the same method as determining whether is was present, with a few exceptions. Firstly, all variables involved in light testing were initialized to 0 at the beginning of the LED testing sequence. Secondly, a light was not checked if it had been previously determined to be missing. Finally, 254 data points were taken for the voltage of the light once the switches had been activated to see how many times the voltage measured over the threshold. If the threshold was exceeded at least 10 times, the light was determined to be on and was tested for flikcering. If not, the light was recorded as an LED fail, and the next light was selected. Code for the LED\_TEST subroutine is shown in Figure \ref{fig:LED_TEST1} and Figure \ref{fig:LED_TEST2}.  \subsubsection{Determining if the LED is Flickering}  Determining if the candlelight is flickering requires a little bit more math. The first step is to obtain a "reference voltage" which will be maintained for the remainder of the test. The reference voltage was the first data point for voltage obtained from the light. It is then compared to the new, incoming voltage from the ADC. If the reference is greater, the values in the "reference" register and the "temporary" (new voltage) register are exchanged (code in Figure \ref{fig:FLICKER_SWAP}. The reference is then subtracted from the temporary voltage, and the result is stored in the temporary voltage register. The code to this point can be seen in Figure \ref{fig:FLICKER_TEST1}. The temporary voltage register is compared to the "Flicker Threshold" which is 0.25 V. Comparison code can be seen in Figure \ref{fig:FLICKER_COMPARE}. The flicker threshold is the difference between voltage readings from the phototransistor when the light is on versus flickered off. Each time the threshold is exceeded, the flicker\_flag increments. Once the flicker\_flag exceeds 10, the light is determined to have passed. If it does not pass 10 on the first run through the loop of 254 data points, the process is repeated up to 10 times for a total of 2540 data points. If at this time the flicker flag still does not exceed 10, the light is assigned a flicker fail status. This code can be seen in Figure \ref{fig:FLICKER_TEST2}. The combined test for LED on and LED flickering is repeated for all the lights by stepping through different selection signals for the mux (from 0 to 9).   \subsection{Program Details}  \subsection{Suggestions for Improvement}