4.5 Controlling the galvanometer
4.5.1 Pulse Width Modulation
Pulse Width Modulation (PWM) is a modulation technique used to encode a message into a pulsing signal but is mainly used to allow the control of the power supplied electrical devices[63]. The pulsing signal, which is turning the signal on and o, by having a higher frequency than the one that the device can read, it is possible to, with a digital signal, simulate an analog signal. The percentage of time the digital signal is on, is the duty cycle. So, with a duty cycle of 50% on, the output voltage would be around 2,5V.
This method is only available on six of the Arduino pins, which are controlled with a timer. Timer 0 controls the 5 and 6 pins, timer 1 controls 9 and 10 and timer 2 controls pins 3 and 11 for the Arduino UNO.
The use of a low pass lter, which consists in adding a resistor and a capacitator, in a PWM circuit, allows to stabilize the signal curve by charging the capacitator when the digital signal is on and discharging it when its o creating a stabilized DC voltage signal proportional to the duty cycle. This way, the use of a small charge capacitator is advised. Figure 4.2: PWM Shield Yellow Cable Green Cable
Figure 4.3: PWM Shield Schematics
In Figure 4.2, it is visible that the shield, along with the low pass lter, allows the direct connection of a laser pointer and a temperature sensor.
The PWM shield has a logic gate NAND. This logic gate was used to reduce the number of low pass lters, as only two PWM signals would be necessary, one for x and one for y, so the logic gate had the primary function of accepting a PWM signal, already ltered on the low pass lter, and sending it to the positive or the negative wire of the galvanometer axis. With four gates, the control of each gate would be done by an Arduino pin as two gates are used for each axis. The signal of each axis gate group comes from an Arduino PWM pin, in this case the ninth and tenth pins. The axis control is done by pins 7 and 8 for the x axis, positive and negative movement respectively and by pins 5 and 6 for the y axis, also positive and negative respectively.
A logic gate is basically a boolean operation where two digital signals return a logical signal which depends on the value of the rst ones. Digital signals have two positions, on and o which are 1 and 0. The NAND logical gate negates the signal that exist the gate, for example if both signals are 1 the result will be zero. In case of any or both signals being 0 the result will be one. With this information, it was expected that by sending 0 on the digital gate would result in a 1 with any analog signal value and by sending 1, it would result in the analog signal negation which means that instead of a duty cycle of 80%, it would be 20%.
By connecting the logic gate in the previously described way, the Motorola's 74HC00 gate worked well in some gates, as it has four, but, by failing at one gate, this method did not worked. So, to check if it was not a logic gate error, a Philips AND gate 74HC08 was applied but the result was worse, as none of the gates provided the desired eect. The nal step was to send a digital PWM signal to the gate and then use a low pass lter before sending it to the galvanometer, being this the only way for it to work. With this conclusion, the two low pass lters solution had to be changed to a four low pass lter solution where the logic gate has the task of avoiding the use of more than two PWM pins.
For the management of the logic gates of the Motorola 74HC00, the "move x" and "move y" functions mentioned before were used. To move the galvanometer mirror in the x positive axis direction, the function "movexpos" which means "move x positive", will rst see if the last position was on the x positive axis, if not it calls a function called "xpositive", which then sets the x positive high and the x negative low.
Table 4.1: Arduino movement functions Function Name Pin High Pin LOW
xpositive() 7 8
xnegative() 8 7
ypositive() 5 6
ynegative() 6 5
Table 4.2: How the movement functions are called Function Name Functions Called
movexpos() xpositivo() movexneg() xnegativo() moveypos() ypositivo() moveyneg() ynegativo()
The low pass lter solution is calculated according to the PWM frequency, which then sets the resistors and capacitor values. Since the galvanometer draws 20 000 points per second, the Arduino PWM frequency should be higher than that. Then, as the capacitors should have a low value, the resistors value needs to be calculated with these two constraints. The capacitors used have a 10nF capacity and, to have a higher than 20kHz frequency, the resistors had to have less than 8.2kΩ . As the only available resistors have 4.3kΩ, the frequency had to be set to 33862.75 Hz.
Figure 4.4: Frequency calculations for a low pass lter
Other way to control the galvanometer with PWM is the use of built in functions of the Arduino, which are explained in Appendix C.