Current regulator

Dependencies:   EthernetInterface mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
soren51929277
Date:
Fri Jun 17 07:18:32 2016 +0000
Parent:
0:e3a184a83be0
Commit message:
Testing UDP

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jun 17 06:27:42 2016 +0000
+++ b/main.cpp	Fri Jun 17 07:18:32 2016 +0000
@@ -22,10 +22,10 @@
 Setting status;
  
 //INITS-------------------------------------------------------------------------
-SPI spi(PTD2, NC, PTD1);    // mosi, miso(not used), sclk (reset+rdy not used)
+SPI spi(PTD2, NC, PTD1);    //mosi, miso(not used), sclk (reset+rdy not used)
 DigitalOut cs(PTC12);       //SYNC
 DigitalOut led(LED1);
-DigitalOut ledgreen(LED2);
+//DigitalOut ledgreen(LED2);
 
 AnalogIn BattVolt(A0);      //ADC for the battery voltage resistordivider = 10k/(36k+10k) = 0.217. Measered voltage = (BattVolt*3.3V)/0.217
 AnalogIn CoilVolt(A1);      //ADC for the coil voltage. Measered voltage = (CoilVolt*3.3V)/0.217
@@ -42,7 +42,7 @@
 EthernetInterface eth;      //create ethernet
 UDPSocket server;           //creat server
 Endpoint client;            //create endpoint
-
+/*
 void InitPot(void) {
     cs = 1;                 //Deselect the device
     spi.format(16,1);       //Setup the spi for 16 bit data, SPI mode = 1 
@@ -75,6 +75,7 @@
     result = (Current.read()*30)-45;
     return result;    
 }
+*/
 
 void InitEth(void) {
     eth.init(SERVER_IP, MASK, GATEWAY);                                         //set up IP
@@ -88,12 +89,15 @@
     while(1) {
         int n = server.receiveFrom(client, buffer, sizeof(buffer));  
         memcpy(&status,&buffer[0],sizeof(buffer));
-        pc.printf("Out: \r\n", status.Out);
-    
+        pc.printf("Out:     %3.3f%\r\n", status.Out);
+        pc.printf("Error:   %3.3f%\r\n", status.Error);
+        pc.printf("Iset:    %3.3f%\r\n", status.Iset);
+        pc.printf("Voltage: %3.3f%\r\n", status.Voltage);
+        pc.printf("Current: %3.3f%\r\n", status.Current);      
     }
 }
 
-
+/*
 void UpdateCurrent() {
     
     if(HighMoment == true) {
@@ -116,40 +120,37 @@
         SetPot(int(CurrentPot));
     }
 }
+*/
 
 int main() {
 
-    //InitEth();              //setup Ethernet connection
-    InitPot();              //setup potentiometer
+    InitEth();              //setup Ethernet connection
+    //InitPot();              //setup potentiometer
     led = 1;
     
-    //Thread DbThread(ReadSocketDate, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25));
+    Thread DbThread(ReadSocketDate, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25));
         
     while(1) {
     
-        
         led = !led;    
         
-        UpdateCurrent(CurrentOut, CurrentPot);
+        //UpdateCurrent(CurrentOut, CurrentPot);
  
-        /*for(int i=0; i<1023;i++) {
+        wait(1);
+          
+        /*
+        for(int i=0; i<1023;i++) {
             SetPot(i);
             wait_us(100);
-            }*/
-        wait(1);
-          
-          
-        
-
-        //pc.printf("BatteryPercent: %3.3f%%\n\r", BattVolt.read()*100.0f);
-        //pc.printf("CoilPercent: %3.3f%%\n\r", CoilVolt.read()*100.0f);
-        //pc.printf("CurrentPercent: %3.3f%%\n\r", Current.read()*100.0f);
+        }
+        pc.printf("BatteryPercent: %3.3f%%\n\r", BattVolt.read()*100.0f);
+        pc.printf("CoilPercent: %3.3f%%\n\r", CoilVolt.read()*100.0f);
+        pc.printf("CurrentPercent: %3.3f%%\n\r", Current.read()*100.0f);
         
         PwmSpare = 0.1f;
         PwmAlarm = 0.25f;
         PwmPump = 0.5f;
         PwmFan = 0.75f;
-        
-    
+        */
     }
 }