K Andres / Mbed 2 deprecated SCIboard

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SCIboard_MOSFET.cpp Source File

SCIboard_MOSFET.cpp

00001 /* SCIboard(TM) MOSFET.cpp
00002 Copyright (c) 2013 K. Andres
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 #include "SCIboard_MOSFET.h"
00024 
00025 #define ADC_SCALE_FACTOR    14.2376
00026 
00027 // LEDs
00028 extern DigitalOut led1;
00029 extern DigitalOut led2;
00030 extern DigitalOut led3;
00031 extern DigitalOut led4;
00032 
00033 // Buzzer
00034 extern DigitalOut alert;
00035 
00036 // FET controls
00037 extern DigitalOut fet_out1;
00038 extern DigitalOut fet_out2;
00039 extern DigitalOut fet_out3;
00040 extern DigitalOut fet_out4;
00041 
00042 // ADC inputs
00043 extern AnalogIn batt_mon;
00044 extern AnalogIn fet_mon1;
00045 extern AnalogIn fet_mon2;
00046 extern AnalogIn fet_mon3;
00047 extern AnalogIn fet_mon4;
00048 
00049 // Timers
00050 Timeout timeoutFet1, timeoutFet2, timeoutFet3, timeoutFet4;
00051  
00052 
00053 SCIboard_Mosfet::SCIboard_Mosfet(void) {
00054 }
00055 
00056 
00057 // Timeout subroutines
00058 void fet1_Off() {
00059     led1 = 0;
00060     fet_out1 = 0;
00061     timeoutFet1.detach();
00062 }
00063 
00064 void fet2_Off() {
00065     led2 = 0;
00066     fet_out2 = 0;
00067     timeoutFet1.detach();
00068 }
00069 
00070 void fet3_Off() {
00071     led3 = 0;
00072     fet_out3 = 0;
00073     timeoutFet1.detach();
00074 }
00075 
00076 void fet4_Off() {
00077     led4 = 0;
00078     fet_out4 = 0;
00079     timeoutFet1.detach();
00080 }
00081 
00082 
00083 // Command MOSFET on for duration (seconds)
00084 void SCIboard_Mosfet::setFet(int iFetNum, float fDuration) {
00085     switch(iFetNum) {
00086         case 1:
00087             led1 = 1;
00088             fet_out1 = 1;
00089             timeoutFet1.attach(&fet1_Off, fDuration);
00090             break;
00091             
00092         case 2:
00093             led2 = 1;
00094             fet_out2 = 1;
00095             timeoutFet2.attach(&fet2_Off, fDuration);
00096             break;
00097             
00098         case 3:
00099             led3 = 1;
00100             fet_out3 = 1;
00101             timeoutFet1.attach(&fet3_Off, fDuration);
00102             break;
00103             
00104         case 4:
00105             led4 = 1;
00106             fet_out4 = 1;
00107             timeoutFet1.attach(&fet4_Off, fDuration);
00108             break;
00109             
00110         default:        
00111             break;
00112     }
00113 }
00114 
00115 
00116 // CAUTION: Small current flows through sense resistor (30K ohm)
00117 //   whenever arm switch is on. Used to determine continuity of circuit
00118 // Does not include reverse polarity protection diode voltage drop
00119 float SCIboard_Mosfet::getFetVoltage(int iFetNum) {
00120     float f;
00121 
00122     switch(iFetNum) {
00123         case 1:
00124             f = fet_mon1;
00125             break;
00126             
00127         case 2:
00128             f = fet_mon2;
00129             break;
00130             
00131         case 3:
00132             f = fet_mon3;
00133             break;
00134             
00135         case 4:
00136             f = fet_mon4;
00137             break;
00138 
00139         default:
00140             f=0;
00141             break;            
00142     }
00143     return(f * ADC_SCALE_FACTOR);
00144 }
00145 
00146 // Does not include reverse polarity protection diode voltage drop
00147 float SCIboard_Mosfet::getBattVoltage(void) {
00148     return(batt_mon * ADC_SCALE_FACTOR);
00149 }