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:
10:8c0696b99692
Parent:
9:8d78eb55ad5e
Child:
11:06f6e82b40a8
--- a/FPGAcomms.h	Mon Nov 10 19:01:43 2014 +0000
+++ b/FPGAcomms.h	Wed Nov 12 20:14:45 2014 +0000
@@ -1,8 +1,8 @@
 #include "mbed.h"
-
+#include "Colour.h"
 //Setup pins to FPGA
 DigitalOut startSort(p5);       //A positive edge tells the FPGA to start sorting.
-
+DigitalIn sortComplete(p16);
 /*
   The command codes for the three sort select bits(ColourBit1 - ColourBit2)
     000     Sort red chip
@@ -29,5 +29,118 @@
 DigitalOut dispenseBit1(p19);  //The 2 bits below are select bits for the dispenser.p10
 DigitalOut dispenseBit2(p20); //p11
 
-DigitalIn complete(p12);    //FPGA sets to 1 once complete until another signal is recieved.
-DigitalOut select(p15); //0 for control, 1 for maintenance.
\ No newline at end of file
+DigitalIn dispenseComplete(p12);    //FPGA sets to 1 once complete until another signal is recieved.
+DigitalOut select(p15); //0 for control, 1 for maintenance.
+
+void dispense(Colour colour){
+    
+        select = 0; //Setting to operation mode just in case it has not been set.
+        dispenseBit1 = true;
+        dispenseBit2 = true;
+        switch(colour){
+            case RED:
+                log("RED");
+                log("Setting dispense bits to 00");
+                dispenseBit1 = false;
+                dispenseBit2 = false;               
+                
+            break;
+            case GREEN:
+                log("GREEN");
+                log("Setting dispense bits to 10");
+                dispenseBit1 = true;
+                dispenseBit2 = false;
+                
+            break;
+            case BLUE:
+                log("BLUE");
+                log("Setting dispense bits to 01");
+                dispenseBit1 = false;
+                dispenseBit2 = true;
+                
+            break;
+        }
+        
+     
+        log("Setting start dispense to true");
+        startDispense = true; //set the startDispense line high.
+       
+        
+        //wait(1); //temporary delay
+        while(!dispenseComplete){
+            wait(0.1);
+            log("Waiting for dispense complete");
+            printLCD("Waiting for dispense complete");           
+        }
+        
+        wait(0.1);
+        log("Complete");
+        log("Setting start dispense to false");
+        startDispense = false;
+        
+        log("Resetting dispense bits to 11");       
+        dispenseBit1 = true;    //reset the dispense select to do nothing
+        dispenseBit2 = true;    //reset the dispense select to do nothing
+        
+      
+       
+        printLCD("DISPENSE COMPLETE");
+    }
+    
+void sort(Colour colour){
+        select = 0; //Setting to operation mode just in case it has not been set.
+        colourBit1 = true;
+        colourBit2 = true;
+        colourBit3 = true;
+        switch(colour){
+            case RED:
+                log("Sort RED");
+                log("Setting sort bits to 000");
+                colourBit1 = false;
+                colourBit2 = false;
+                colourBit3 = false;              
+                
+            break;
+            case GREEN:
+                log("Sort GREEN");
+                log("Setting sort bits to 001");
+                colourBit1 = true;
+                colourBit2 = false;
+                colourBit3 = false;
+                
+            break;
+            case BLUE:
+                log("Sort BLUE");
+                log("Setting sort bits to 010");
+                colourBit1 = false;
+                colourBit2 = true;
+                colourBit3 = false;
+                
+            break;
+        }
+        
+     
+        log("Setting start sort to true");
+        startSort = true; //set the startDispense line high.
+       
+        
+        //wait(1); //temporary delay
+        while(!sortComplete){
+            wait(0.1);
+            log("Waiting for sort complete");
+            printLCD("Waiting for sort complete");            
+        }
+        
+        
+        log("Complete");
+        wait(0.1);
+        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("SORT COMPLETE");
+        
+}
\ No newline at end of file