The program driving Kasubana was written in C. Timer 0 was used to set a 1 ms time base for the software counters and timers. Upon initialization, the software proceeds to calibrate the base values of each electrode for 5400ms. The base value then serves as a reference voltage for each of the electrodes.
The software monitors the values of the E-field sensor by activating each one of the seven external electrodes and two of the reference electrodes every 100ms. A delay of 1 ms is needed to allow the electrode to be fully activated. The output of the E-field sensor is sent to the ADC of the MCU which is represented in 10 bits. Based on the change of values from the reference electrodes, the base value of each external electrode is re-adjusted. Significant changes in E-field readings result in activation of a pulse width modulator (PWM) to power the nitinol actuation. Timer 2 was used to provide the PWM signal because Port B3 of Timer 0 was used as an electrode selection control signal to the E-field sensor.
In order to prevent the nitinol wires from overheating and subsequently melting, the input voltage is pulse-width modulated at a value of OCR2 = 60. The electrode at which the most significant voltage change was detected is then determined and the stepper motor is activated to orient the plant towards that particular electrode.
Given seven electrodes, each lying side by side, there are seven final positions of the flower, respectively at 22.5, 35.36, 48.21, 73.93, 86.79, 99.64 and 112.5 degrees with respect to the horizontal axis. A counter increments each half step and the stepper motor is disable once the desired position is reached.
If no significant voltage change is detected in any of the electrodes, the PWM is turned off and the flower remains at the last position it was in until further directions from the MCU. Fig. 9 shows the flow chart of our program.
For the complete source code, please see Appendix.
Developed by Ming-Zher Poh & Yuk Kee Cheung, © 2005