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:
20:6de191ac7ff3
Parent:
19:78d4b78fa736
Child:
22:8f11d1c178ab
--- a/FPGAcomms.h	Tue Nov 25 12:06:26 2014 +0000
+++ b/FPGAcomms.h	Tue Nov 25 12:59:11 2014 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 //#include "Colour.h"
 #include "colourProcessing.h"
+int recycleAmount = 0;
 //Setup pins to FPGA
 DigitalOut startSort(p5);       //A positive edge tells the FPGA to start sorting.
 DigitalIn sortComplete(p16);
@@ -196,6 +197,44 @@
     }
 }
 
+void waitForSortComplete()
+{
+    while(!sortComplete) {
+        wait(0.5);
+        log("Waiting for sort complete");
+        printLCD("Waiting for sort complete");
+    }
+    log("sortComplete signal recieved from FPGA");
+    wait(0.6);
+
+}
+
+void lift()
+{
+    select = 0; //Setting to operation mode just in case it has not been set.
+    setSortSelect(true,true,true);
+    setSortSelect(true,false,true);
+    log("Setting start sort to true, FPGA should begin sorting now");
+    startSort = true; //set the startDispense line high.
+
+
+    //wait(1); //temporary delay
+    waitForSortComplete();
+    log("Setting start sort to false");
+    startSort = false;
+
+    log("Resetting sort bits to 111");
+    setSortSelect(true,true,true);
+    printLCD("LIFT COMPLETE");
+    recycleAmount = 0;
+}
+
+void checkRecycleTube(){
+    if(recycleAmount >=5){
+        lift();
+        }
+    }
+
 void recycle()
 {
 
@@ -209,36 +248,18 @@
     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);
+    waitForSortComplete();
     log("Setting start sort to false");
     startSort = false;
 
     log("Resetting dispense bits to 11");
     setSortSelect(true,true,true);
     printLCD("RECYCLE COMPLETE");
-
+    recycleAmount++;
+    checkRecycleTube();
 }
 
-void waitForSortComplete()
-{
-    while(!sortComplete) {
-        wait(0.5);
-        log("Waiting for sort complete");
-        printLCD("Waiting for sort complete");
-    }
-    log("sortComplete signal recieved from FPGA");
-    wait(0.6);
 
-}
 
 void sort(Colour colour)
 {
@@ -302,25 +323,8 @@
     }
 }
 
-void lift()
-{
-    select = 0; //Setting to operation mode just in case it has not been set.
-    setSortSelect(true,true,true);
-    setSortSelect(true,false,true);
-    log("Setting start sort to true, FPGA should begin sorting now");
-    startSort = true; //set the startDispense line high.
 
 
-    //wait(1); //temporary delay
-    waitForSortComplete();
-    log("Setting start sort to false");
-    startSort = false;
-
-    log("Resetting sort bits to 111");
-    setSortSelect(true,true,true);
-    printLCD("LIFT COMPLETE");
-}
-
 void dispenseAll()
 {
     int red = redAmount;