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:
17:6a0bb0ad5bb4
Parent:
15:0c5f20e15b6a
Child:
19:78d4b78fa736
--- a/FPGAcomms.h	Sun Nov 23 18:45:52 2014 +0000
+++ b/FPGAcomms.h	Mon Nov 24 14:00:46 2014 +0000
@@ -6,6 +6,7 @@
 DigitalIn sortComplete(p16);
 /*
   The command codes for the three sort select bits(ColourBit1 - ColourBit2)
+  See datasheet for furter information
     000     Sort red chip
     001     Sort green chip
     010     Sort blue chip
@@ -174,17 +175,59 @@
     for(int i = g; i >= 0;i--){
         dispense(BLUE);
         }
-    }    
+    }
+    
+void recycle(){
+       
+       select = 0; //Setting to operation mode just in case it has not been set.
+        colourBit1 = true;
+        colourBit2 = true;
+        colourBit3 = true;
+       
+        log("Recycle");
+        log("Setting sort bits to 100");
+        colourBit1 = false;
+        colourBit2 = false;
+        colourBit3 = true;
+        
+        log("Setting start sort to true");
+        startSort = true; //set the startDispense line high.
+        
+        //wait(1); //temporary delay
+        while(!sortComplete){
+            wait(0.5);
+            log("Waiting for sort complete");
+            printLCD("Waiting for sort complete");            
+        }
+        
+        
+        log("Complete");
+        wait(0.5);
+        log("Setting start sort to false");
+        startSort = false;     
+        
+        log("Resetting dispense bits to 11");       
+        colourBit1 = true;    //reset the dispense select to do nothing
+        colourBit2 = true;    //reset the dispense select to do nothing
+        colourBit3 = true;
+        printLCD("RECYCLE COMPLETE");
+           
+    }     
 void sort(Colour colour){
         if(colour == NONE){
             return;
         }else{
+            
         select = 0; //Setting to operation mode just in case it has not been set.
         colourBit1 = true;
         colourBit2 = true;
         colourBit3 = true;
         switch(colour){
             case RED:
+                if(redAmount >= tubeSize){
+                    recycle();
+                    return;
+                    }
                 log("Sort RED");
                 log("Setting sort bits to 000");
                 colourBit1 = false;
@@ -193,6 +236,10 @@
                 redAmount++;
             break;
             case GREEN:
+                if(greenAmount >= tubeSize){
+                    recycle();
+                    return;
+                    }
                 log("Sort GREEN");
                 log("Setting sort bits to 001");
                 colourBit1 = true;
@@ -201,6 +248,10 @@
                 greenAmount++;
             break;
             case BLUE:
+                if(blueAmount >= tubeSize){
+                    recycle();
+                    return;
+                    }
                 log("Sort BLUE");
                 log("Setting sort bits to 010");
                 colourBit1 = false;
@@ -215,13 +266,6 @@
                 colourBit2 = true;
                 colourBit3 = false;
             break;
-            case RECYCLE:
-                log("Recycle");
-                log("Setting sort bits to 100");
-                colourBit1 = false;
-                colourBit2 = false;
-                colourBit3 = true;
-            break;
         }