Library for Modtronix NZ32 STM32 boards, like the NZ32-SC151, NZ32-SB072, NZ32-SE411 and others
Diff: nz32s.cpp
- Revision:
- 5:e1297df8ee0d
- Parent:
- 3:99cb87ee1792
- Child:
- 10:213d6350f0a8
--- a/nz32s.cpp Sun Aug 30 09:29:08 2015 +1000 +++ b/nz32s.cpp Sun Aug 30 11:59:06 2015 +1000 @@ -1,5 +1,5 @@ /** - * File: modtronix_nz32s.cpp + * File: nz32s.cpp * * Author: Modtronix Engineering - www.modtronix.com * @@ -18,6 +18,8 @@ * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. */ +#define THIS_IS_NZ32S_CPP + #include "mbed.h" #include <stdarg.h> #include <stdio.h> @@ -35,10 +37,76 @@ // GLOBAL VARIABLES /////////////////////////////////////////////////////////// +// STATIC OBJECTS ///////////////////////////////////////////////////////////// +DigitalOut NZ32S::led1(LED1); +DigitalIn NZ32S::btn1(USER_BUTTON, PullDown); +IWDG_HandleTypeDef NZ32S::hiwdg; //Watchdog Timer +#if (DONT_USE_A13_A14 == 0) +DigitalInOut NZ32S::enableFastCharge(PA_14, PIN_INPUT, PullNone, 0); +#endif + + // Function Prototypes //////////////////////////////////////////////////////// -IWDG_HandleTypeDef NZ32S::hiwdg; //Watchdog Timer +/** Get the battery voltage. + */ +uint16_t NZ32S::get_batt_mv() { + MX_DEBUG("\r\nnz32s_getBattMV()"); + + //uint16_t getBattMV(void) { + // float fval = 0; + // + //#if (DONT_USE_A13_A14 == 1) + //// uint16_t meas; + //// + //// //Measure Vbatt. It doesn't seem to make lots of a difference if we disable the DC/DC converter! + //// ctrVBatt = 0; + //// ctrVBatt.output(); + //// wait_ms(150); + //// meas = ainVBatt.read_u16(); // Converts and read the analog input value + //// ctrVBatt.input(); + //// //fval = ((float)meas / (float)0xffff) * 6600; //6600 = 3300*2, because resistor divider = 2 + //// fval = meas * ((float)6600.0 / (float)65535.0); + //#endif + // + // return (uint16_t) fval; + return 0; +} + + +/** + * Get Vusb or 5V supply voltage in millivolts. + */ +uint16_t NZ32S::get_supply_mv(void) { + // float fval; + // uint16_t meas; + // + // //Following voltages were measured at input of ADC: + // // + // //----- Vusb=0V & 5V supply=0V ----- + // //Value is typically 4mV + // // + // //----- Vusb=5V & 5V supply=0V ----- + // //When only VUSB is supplied, the value is typically 1.95V + // // + // //----- Vusb=0V & 5V supply=5V ----- + // //When only VUSB is supplied, the value is typically 1.95V + // // + // //The reason this circuit does not work, is because of the reverse voltage of the diodes. It is given + // //as about 40 to 80uA. With a resistor value of 470K, this will put 5V on other side of diode. + // //Thus, no matter if 5V is at Vusb, Vsupply, or both, the read value will always be 1.95V. + // //To solve problem, resistors must be lowered to value where 80uA will no longer give more than 5V + // //voltage drop = 62k. Using two 47k resistors should work. + // + // //Measure Vusb/5V sense input + // meas = ainVSense.read_u16(); // Converts and read the analog input value + // fval = ((float) meas / (float) 0xffff) * 3300; + // + // return (uint16_t) fval; + return 0; +} + /** * Reset I2C bus