Dependencies:   PWM-Coil-driver

Fork of TEMPFINALInterrupt_copy by Ian Wolf

Files at this revision

API Documentation at this revision

Comitter:
iwolf32
Date:
Thu Sep 07 20:31:32 2017 +0000
Parent:
2:4425049f4174
Commit message:

Changed in this revision

PWM-Coil-driver.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PWM-Coil-driver.lib	Thu Sep 07 20:31:32 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/iwolf32/code/PWM-Coil-driver/#91a84a44c81e
--- a/main.cpp	Thu Aug 31 13:57:01 2017 +0000
+++ b/main.cpp	Thu Sep 07 20:31:32 2017 +0000
@@ -1,114 +1,39 @@
+#include <string>
 #include "mbed.h"
-#include <string>
+#include "coil-driver.h"
 
-// Read temperature from MAX1363 3-channel ADC
-
-I2C i2c(PB_9 , PB_8);
-DigitalOut Relay(D7);
 Serial pc(SERIAL_TX, SERIAL_RX);
+Coil injector(A0, 200, 40, 3);
 
 std::string str;
 char ch;
-double SetTemp=0;
-float x=0;
-
-// address information for the Serenity temperature sensor device
-const int SLAVE_ADDRESS = 0x34 << 1;
-
-// MAX1363 registers
-const unsigned char MAX1363_CONFIG_REG = 0x03;  // single-ended inputs, read CH0-CH1 only
-const unsigned char MAX1363_SETUP_REG  = 0xF2;  // AIN3=output, INT REF always on
-
-// MAX1363 high byte format (byte 2 is D7-D0)
-const unsigned char MAX1363_VALID_MASK = 0x90;      // HIGH bit and 12/10 bit should always be 1
-const unsigned char MAX1363_HIGH_DATA_MASK = 0x0F;
-
-// channel address (0-3) is in CH1/CH0 (bits 5/6)
-const unsigned char MAX1363_CHANNEL_MASK = 0x60;
-const unsigned char MAX1363_CHANNEL_SHIFT = 5;
-
-/** conversion factors */
-const float CONV_COEFF_A3 = 4.39403;
-const float CONV_COEFF_A2 = -11.15;
-const float CONV_COEFF_A1 = 36.4955;
-const float CONV_COEFF_A0 = 266.909;
-
-const int CONV_N = 12;
-const float CONV_VREF = 2.048;
-
-const float CONV_K_TO_C = -272.15;
-
-float AdcToC(unsigned int _adc)
-{
-    float d = CONV_VREF * _adc / (1L << CONV_N);
-    float d2 = d*d;
-    float d3 = d2*d;
-    float temp_k = (CONV_COEFF_A3 * d3) +
-        (CONV_COEFF_A2 * d2) +
-        (CONV_COEFF_A1 * d) +
-        CONV_COEFF_A0;
-    return temp_k + CONV_K_TO_C;
-}
+double frequency=2;
+double dutycycle=0;
+double openvalue=0;
+double offvalue=0;
 
 void callback(){
 ch=pc.getc();
 str+=ch;
-SetTemp= atof(str.c_str());
+dutycycle= atof(str.c_str());
 return;
 }
 
-
 int main() {
     pc.baud(115200);
+    pc.attach(&callback);
+  
     
-    pc.attach(&callback);
-
-    // reserve 4 bytes for transfer
-    char cmd[4];
-
-    // initialize the adc device
-    cmd[0] = MAX1363_CONFIG_REG;
-    cmd[1] = MAX1363_SETUP_REG;
-    i2c.write(SLAVE_ADDRESS, cmd, 2);
-
-    // holds raw adc values as we convert them
-    unsigned int adc[2] = {0};
-    float values[2] = {0};
-
-    while (1) {
-        //Clear string holding the input from serial
-        str.clear();
+    while(1){
+        openvalue=(((1/frequency)*dutycycle/100));
+        offvalue=(1/frequency)-openvalue;
+        if (dutycycle!=0){        
+        injector.on();
+        wait(openvalue);
+        injector.off();
+        wait(offvalue);
+        }
         
-        wait(1);
-
-        // clear buffer, only to detect invalid data
-        cmd[0] = 0x00;
-        cmd[1] = 0x00;
-        cmd[2] = 0x00;
-        cmd[3] = 0x00;
-
-        // read 4 bytes from
-        i2c.read(SLAVE_ADDRESS, cmd, 4);
-
-        for (int i=0; i<4; i+=2) {
-            // first 4 bits contain expected bits and channel id
-            if ((cmd[i] & MAX1363_VALID_MASK) == MAX1363_VALID_MASK) {
-                unsigned char ch = ((cmd[i] & MAX1363_CHANNEL_MASK) >> MAX1363_CHANNEL_SHIFT);
-                adc[ch] = ((int)(cmd[i] & MAX1363_HIGH_DATA_MASK) << 8) | cmd[i+1];
-                values[ch] = AdcToC(adc[ch]);
-            } else {
-                // handle invalid data
-            }
-        }
-        x=values[1];
-        if (x<SetTemp){
-            Relay=0;
-        }
-        if (x>SetTemp+1){
-            Relay=1;
-        }
-        // output temperature data
-        printf("%0.2f\t %0.2f\t %0.2f\r\n", SetTemp, values[0], values[1]);
-
-    }
+        printf("%0.2f\t %0.2f\r\n", frequency, dutycycle);
 }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Thu Sep 07 20:31:32 2017 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#98ba8acb83cfc65f30a8a0771a27c71443ab093a
--- a/mbed.bld	Thu Aug 31 13:57:01 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/fd96258d940d
\ No newline at end of file