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:
25:7f5d764d8e34
Parent:
24:8868101d01d0
Child:
26:23ee3ea4ac7c
--- a/FPGAcomms.h	Wed Dec 03 17:49:41 2014 +0000
+++ b/FPGAcomms.h	Thu Dec 04 11:12:29 2014 +0000
@@ -152,8 +152,7 @@
 void waitForDispenseComplete()
 {
     while(!dispenseComplete) {
-    }
-    
+    }  
 }
 
 /*  dispense(Colour colour)
@@ -205,13 +204,12 @@
     }
 }
 
-/*  
- *  
+/*  dispenseOrder(int r, int g, int b)
+ *  Dispenses a certain amount of each coloured chip,
+ *  depending on the three input values (one input for each colour).
  */ 
 void dispenseOrder(int r, int g, int b)
 {
-//TODO: Check if there are enough chips of each colour to dispense the order.
-    //operationMode = false;
     for(int i = r; i > 0; i--) {        
         dispense(RED);
         wait(0.2);
@@ -223,42 +221,45 @@
     for(int i = b; i > 0; i--) {
         dispense(BLUE);
     }
-    //operationMode = true;
 }
-
+//Wait for the FPGA to complete a sort operation and send a complete signal.
 void waitForSortComplete()
 {
     while(!sortComplete) {}
 }
-
+/*  lift()
+ *  Communicate with the FPGA to carry out a lift operation.
+ */
 void lift()
 {
     select = 0; //Setting to operation mode just in case it has not been set.
-    setSortSelect(true,true,true);
-    setSortSelect(true,false,true);
-    startSort = true; //set the startDispense line high.
-    waitForSortComplete();
-    startSort = false;
-    setSortSelect(true,true,true);    
+    setSortSelect(true,true,true);  //Setting sort select to 'no nothing' state.
+    setSortSelect(true,false,true); //Setting sort select to 'lift' state.
+    startSort = true;               //Tell the FPGA to start the lift operation
+    waitForSortComplete();          //Wait for the FPGA to complete the lift operation
+    startSort = false;              //Turn off startSort
+    setSortSelect(true,true,true);  //Return sort select to 'no nothing' state.  
 }
 
 
-
+/*  recycle()
+ *  Communicate with the FPGA to carry out a recycle operation.
+ */
 void recycle()
 {
     if(redAmount >= tubeSize && greenAmount >= tubeSize && blueAmount >= tubeSize && operationMode){
         return;
         }
     select = 0; //Setting to operation mode just in case it has not been set.
-    setSortSelect(true,true,true);
-    setSortSelect(false,false,true);
-    if(operationMode)recycleAmount++;
-    startSort = true; //set the startDispense line high.
-    waitForSortComplete();
-    startSort = false;
-    setSortSelect(true,true,true);
-    if(recycleAmount >= 5) {
-        Thread::wait(1000);
+    setSortSelect(true,true,true);      //Setting sort select to 'no nothing' state.
+    setSortSelect(false,false,true);    //Setting sort select to 'recycle' state.
+    if(operationMode)recycleAmount++;   //Increment the amount of chips in the lift, if we are in operation mode.
+    startSort = true;                   //Tell the FPGA to start the recycle operation.
+    waitForSortComplete();              //Wait for the FPGA to complete the recycle operation
+    startSort = false;                  //Turn off startSort
+    setSortSelect(true,true,true);      //Return sort select to 'no nothing' state.  
+    if(recycleAmount >= 5) {            //Check whether the lift is full.
+        Thread::wait(1000);             
         lift();
         Thread::wait(1000);
         recycleAmount = 0;