Simple test application for X-NUCLEO-IKA01A1 expansion board.
Dependencies: X_NUCLEO_IKA01A1 mbed
Fork of HelloWorld_IKA01A1 by
Simple test application for X-NUCLEO-IKA01A1 expansion board.
Platform compatibility issues
- NUCLEO-F302R8: use pin D5 for LED Driver configuration
- LPCXpresso11U68: use pin D3 as PWM for LED Driver configuration. Use a free Dx pin as Signal2 for Windows Comparator configuration.
Diff: main.cpp
- Revision:
- 19:a8d8f1ef04f6
- Parent:
- 16:2159a3dc888e
- Child:
- 20:7f25e4cedd1a
--- a/main.cpp Thu Apr 14 10:21:05 2016 +0000 +++ b/main.cpp Tue May 09 11:58:20 2017 +0000 @@ -1,48 +1,95 @@ +/** + ****************************************************************************** + * @file main.cpp + * @author CLab + * @version V1.0.0 + * @date 2-December-2016 + * @brief Simple Example application for using the X_NUCLEO_IKA01A1 + * Analog expansion board. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** +*/ + + +/* Includes ------------------------------------------------------------------*/ + +/* mbed specific header files. */ #include "mbed.h" -#include "x_nucleo_ika01a1_class.h" + +/* Board specific header files. */ +#include "XNucleoIKA01A1.h" + + +/* Variables -----------------------------------------------------------------*/ Serial pc(USBTX, USBRX); +//Serial pc(SERIAL_TX, SERIAL_RX); +DigitalOut myled(LED1); -//Serial pc(SERIAL_TX, SERIAL_RX); -DigitalOut myled(LED1); +/* Functions -----------------------------------------------------------------*/ int main() { - X_NUCLEO_IKA01A1 *analog_expansion_board = X_NUCLEO_IKA01A1::Instance(X_NUCLEO_IKA01A1_PIN_INSTRUMENTATION_AMP, - X_NUCLEO_IKA01A1_PIN_CURRENT_SENSING, - X_NUCLEO_IKA01A1_PIN_PHOTO_SENSOR, - X_NUCLEO_IKA01A1_PIN_WINDOWS_COMP_SIGNAL_1, - X_NUCLEO_IKA01A1_PIN_WINDOWS_COMP_SIGNAL_2, - X_NUCLEO_IKA01A1_PIN_PWM_LED_DRIVER_OUTPUT, - 5000); - analog_expansion_board->Init(); - TSZ124 *instrAmp = analog_expansion_board->tsz124; - TSU104 *photoSensor_windComp = analog_expansion_board->tsu104; - - TSV734 *led_Driver = analog_expansion_board->tsv734; - double dutyCycle = 0; + XNucleoIKA01A1 *analog_expansion_board = XNucleoIKA01A1::instance(X_NUCLEO_IKA01A1_PIN_INSTRUMENTATION_AMP, + X_NUCLEO_IKA01A1_PIN_CURRENT_SENSING, + X_NUCLEO_IKA01A1_PIN_PHOTO_SENSOR, + X_NUCLEO_IKA01A1_PIN_WINDOWS_COMP_SIGNAL_1, + X_NUCLEO_IKA01A1_PIN_WINDOWS_COMP_SIGNAL_2, + X_NUCLEO_IKA01A1_PIN_PWM_LED_DRIVER_OUTPUT, + 5000); + analog_expansion_board->init(); + TSZ124 *instr_amp = analog_expansion_board->tsz124; + TSU104 *photo_sensor_wind_comp = analog_expansion_board->tsu104; + TSV734 *led_driver = analog_expansion_board->tsv734; + double duty_cycle = 0; while(1) { - pc.printf("\nwhile loop\n"); - - unsigned int opAmpVoltage = instrAmp->GetVoltage(); - unsigned int opAmpCurrent = instrAmp->GetCurrent(); + pc.printf("\nLooping...\n"); + + unsigned int op_amp_voltage = instr_amp->get_voltage(); + unsigned int op_amp_current = instr_amp->get_current(); // pass the analog pin name on which voltage is to be read (e.g. A3 on LPCxpresso lpc11u68) - unsigned int photoSensorVoltage = photoSensor_windComp->GetVoltage(); - unsigned int windComPin1 = photoSensor_windComp->GetSignal1(); - unsigned int windComPin2 = photoSensor_windComp->GetSignal2(); + unsigned int photoSensorVoltage = photoSensor_windComp->get_voltage(); + unsigned int windComPin1 = photo_sensor_wind_comp->get_signal1(); + unsigned int windComPin2 = photo_sensor_wind_comp->get_signal2(); - pc.printf("\nopAmp measured voltage(mV): %u \n", opAmpVoltage); - pc.printf("\nopAmp measured Current(mA): %u \n", opAmpCurrent); - pc.printf("\nphotodiode sensor output voltage(mV): %u \n", photoSensorVoltage); - pc.printf("\nWindows comparator: signal 1 value(pin D2): %u \n", windComPin1); - pc.printf("\nWindows comparator: signal 1 value(pin D4): %u \n", windComPin2); + pc.printf("\nopAmp measured voltage(mV): %u \n", op_amp_voltage); + pc.printf("\nopAmp measured Current(mA): %u \n", op_amp_current); + pc.printf("\nphotodiode sensor output voltage(mV): %u \n", photo_sensor_voltage); + pc.printf("\nWindows comparator: signal 1 value(pin D2): %u \n", wind_com_pin1); + pc.printf("\nWindows comparator: signal 1 value(pin D4): %u \n", wind_com_pin2); - dutyCycle += 0.1; - if(dutyCycle>=1) - dutyCycle -= 1; + duty_cycle += 0.1; + if (duty_cycle >= 1) + duty_cycle = 0; - pc.printf("\nLED Driver: duty cycle: %.2lf percent \n", led_Driver->SetDutyCycle(dutyCycle)); + pc.printf("\nLED Driver: duty cycle: %.2lf percent \n", led_Driver->set_duty_cycle(duty_cycle)); myled = !myled; wait(1);