![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
Diff: FPGAcomms.h
- Revision:
- 22:8f11d1c178ab
- Parent:
- 20:6de191ac7ff3
- Child:
- 23:f9e7e64784be
diff -r 3d9556f5508a -r 8f11d1c178ab FPGAcomms.h --- a/FPGAcomms.h Tue Nov 25 13:48:23 2014 +0000 +++ b/FPGAcomms.h Tue Nov 25 22:32:26 2014 +0000 @@ -103,6 +103,21 @@ case R_PUSH: setMaintenanceSelect(false,false,true,true,false,true); break; + case R_HOME: + setMaintenanceSelect(false,false,true,true,true,false); + break; + case GB_LEFT: + setMaintenanceSelect(false,false,true,true,true,true); + break; + case GB_CENTRE: + setMaintenanceSelect(false,true,false,false,false,false); + break; + case GB_RIGHT: + setMaintenanceSelect(false,true,false,false,false,true); + break; + case maintenanceEND: + setMaintenanceSelect(false,true,false,false,true,false); + break; default: log("Incorrect maintenance command recieved"); printLCD("Incorrect maintenance command recieved"); @@ -110,19 +125,18 @@ } setMaintenanceStart(true);//Bit 7 waitForMaintenanceComplete(); - wait(0.5); + setMaintenanceStart(false); } void waitForDispenseComplete() { //wait(1); //temporary delay - while(!dispenseComplete) { - wait(0.2); + while(!dispenseComplete) { log("Waiting for dispense complete"); printLCD("Waiting for dispense complete"); } - wait(0.6); + //wait(0.6); log("Complete"); } @@ -171,10 +185,10 @@ startDispense = true; //set the startDispense line high. waitForDispenseComplete(); - + log("Setting start dispense to false"); startDispense = false; - + log("Resetting dispense bits to 11"); setDispenseSelect(true,true); @@ -200,12 +214,12 @@ 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); + } @@ -220,6 +234,7 @@ //wait(1); //temporary delay waitForSortComplete(); + log("Setting start sort to false"); startSort = false; @@ -230,8 +245,9 @@ } void checkRecycleTube(){ - if(recycleAmount >=5){ - lift(); + if(recycleAmount >= 5){ + //lift(); + recycleAmount = 0; } } @@ -241,21 +257,25 @@ select = 0; //Setting to operation mode just in case it has not been set. setSortSelect(true,true,true); - log("Recycle"); + log("Sort BLUE"); log("Setting sort bits to 100"); setSortSelect(false,false,true); + recycleAmount++; + log("Setting start sort to true"); startSort = true; //set the startDispense line high. + waitForSortComplete(); + log("Setting start sort to false"); startSort = false; log("Resetting dispense bits to 11"); setSortSelect(true,true,true); - printLCD("RECYCLE COMPLETE"); - recycleAmount++; + printLCD("SORT COMPLETE"); + checkRecycleTube(); } @@ -313,6 +333,7 @@ waitForSortComplete(); + log("Setting start sort to false"); startSort = false; @@ -332,19 +353,19 @@ int blue = blueAmount; for(int r = 0; r < red; r++) { dispense(RED); - wait(0.5); + } redAmount = 0; for(int g = 0; g < green; g++) { dispense(GREEN); - wait(0.5); + } greenAmount = 0; for(int b = 0; b < blue; b++) { dispense(BLUE); - wait(0.5); + } blueAmount = 0; writeFile(redAmount,greenAmount,blueAmount);