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:
26:23ee3ea4ac7c
Parent:
25:7f5d764d8e34
--- a/FPGAcomms.h	Thu Dec 04 11:12:29 2014 +0000
+++ b/FPGAcomms.h	Thu Dec 04 12:31:23 2014 +0000
@@ -256,10 +256,10 @@
     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
+    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);             
+        Thread::wait(1000);             //Carry out a lift operation if the recycle tube is full.
         lift();
         Thread::wait(1000);
         recycleAmount = 0;
@@ -267,55 +267,59 @@
 }
 
 
-
+/*  sort(Colour colour)
+ *  Sort a token into a storage tube. The storage tube is selected using the Colour input 'colour'.
+ */
 void sort(Colour colour)
 {
-    if(colour == NONE) {
+    if(colour == NONE) {    //Return if no colour is given.
         return;
-    } else {
-        startSort = false;
-        select = 0; //Setting to operation mode just in case it has not been set.
-        setSortSelect(true,true,true);
+    } else {                
+        startSort = false;                              //just in case it is high for some reason.
+        select = 0;                                     //Setting to operation mode just in case it has not been set.
+        setSortSelect(true,true,true);                  //Set sort select to 'no nothing' state.
         switch(colour) {
             case RED:                
-                if(redAmount >= tubeSize && operationMode) {
+                if(redAmount >= tubeSize && operationMode) {    //Recycle if red tube full
                     recycle();
                     return;
                 }
-                setSortSelect(false,false,false);
+                setSortSelect(false,false,false);               //Set sort select for red sort
                 if(operationMode) redAmount++;
                 break;
             case GREEN:
-                if(greenAmount >= tubeSize && operationMode) {
+                if(greenAmount >= tubeSize && operationMode) {  //Recycle if green tube full
                     recycle();
                     return;
                 }
-                setSortSelect(true,false,false);
+                setSortSelect(true,false,false);               //Set sort select for green sort
                 if(operationMode) greenAmount++;
                 break;
             case BLUE:
-                if(blueAmount >= tubeSize && operationMode) {
+                if(blueAmount >= tubeSize && operationMode) {   //Recycle if blue tube full
                     recycle();
                     return;
                 }
-                setSortSelect(false,true,false);
+                setSortSelect(false,true,false);               //Set sort select for blue sort
                 if(operationMode) blueAmount++;
                 break;
             case BIN:
-                setSortSelect(true,true,false);
+                setSortSelect(true,true,false);                //Set sort select for bin
                 break;
         }
-        startSort = true;
-        waitForSortComplete();
-        startSort = false;
-        setSortSelect(true,true,true);
+        startSort = true;                                      //Tell the FPGA to start the sort
+        waitForSortComplete();                                 //Wait for the FPGA to complete sort operation and send complete signal
+        startSort = false;                      
+        setSortSelect(true,true,true);                         //Return sort select to 'do nothing' state.
+        //Save tube values to file if in operation mode.
         if(operationMode) writeFile(redAmount,greenAmount,blueAmount,recycleAmount);
-       
     }
 }
 
 
-
+/*  dispenseAll()
+ *  Dispense all the tokens in the three tubes, according to the stored values.
+ */
 void dispenseAll()
 {
     dispenseOrder(redAmount,greenAmount,blueAmount);