The MBED firmware used on the Chipin sorter, developed over 12 weeks for a 3rd year university systems project. Chipin is a token sorter, it sorts tokens by colours and dispenses them to order through an online booking system and card reader. This program interfaces with an FPGA, PC and LCD screen to control the sorter. The sorter has an operation mode where it can process orders when a card is entered into the machine. There is also a maintenance mode where the device responds to maintenance instructions such as 'dispense all'. More information at http://www.ionsystems.uk/

Dependencies:   MCP23017 TCS3472_I2C WattBob_TextLCD mbed-rtos mbed

Revision:
14:31ba3e56c788
Parent:
13:0661d658d9d1
Child:
15:0c5f20e15b6a
--- a/FPGAcomms.h	Thu Nov 20 11:15:47 2014 +0000
+++ b/FPGAcomms.h	Thu Nov 20 22:02:54 2014 +0000
@@ -48,6 +48,7 @@
     }
 void waitForMaintenanceComplete(){
     while(!sortComplete){
+        printLCD("Waiting for REC");
         wait(0.1);
         }
 }
@@ -82,6 +83,10 @@
         case R_PUSH:
             setMaintenanceSelect(false,false,true,true,false,true);
         break;
+        default:
+            log("Incorrect maintenance command recieved");
+            printLCD("Incorrect maintenance command recieved");
+        break;
     }    
     setMaintenanceStart(true);//Bit 7
     waitForMaintenanceComplete();
@@ -95,9 +100,11 @@
         select = 0; //Setting to operation mode just in case it has not been set.
         dispenseBit1 = true;
         dispenseBit2 = true;
+        /* A dispense operation can only take place if there are more than zero chips
+        */
         switch(colour){
             case RED:
-            if(redAmount > 0 || operationMode == false){
+            if(redAmount > 0 || operationMode == false){    
                     log("RED");
                     log("Setting dispense bits to 00");
                     dispenseBit1 = false;
@@ -126,8 +133,8 @@
                 validDispense = true;
                 }
             break;
-            writeFile(redAmount,greenAmount,blueAmount);
-        }
+            
+        }writeFile(redAmount,greenAmount,blueAmount);
         
      if(validDispense || operationMode == false){
         log("Setting start dispense to true");
@@ -156,7 +163,14 @@
         
         }
     }
-    
+void dispenseOrder(int r, int g, int b){
+    for(int i = r; r >= 0;i--){
+        dispense(RED);
+        }
+    for(int i = g; i >= 0;i--){
+        
+        }
+    }    
 void sort(Colour colour){
         if(colour == NONE){
             return;