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
FPGAcomms.h@11:06f6e82b40a8, 2014-11-13 (annotated)
- Committer:
- IonSystems
- Date:
- Thu Nov 13 11:59:39 2014 +0000
- Revision:
- 11:06f6e82b40a8
- Parent:
- 10:8c0696b99692
- Child:
- 12:814a8fdbb6f7
Changed colour values for blue bottom plate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IonSystems | 6:e64796f1f384 | 1 | #include "mbed.h" |
IonSystems | 11:06f6e82b40a8 | 2 | //#include "Colour.h" |
IonSystems | 11:06f6e82b40a8 | 3 | #include "colourProcessing.h" |
IonSystems | 6:e64796f1f384 | 4 | //Setup pins to FPGA |
IonSystems | 6:e64796f1f384 | 5 | DigitalOut startSort(p5); //A positive edge tells the FPGA to start sorting. |
IonSystems | 10:8c0696b99692 | 6 | DigitalIn sortComplete(p16); |
IonSystems | 6:e64796f1f384 | 7 | /* |
IonSystems | 6:e64796f1f384 | 8 | The command codes for the three sort select bits(ColourBit1 - ColourBit2) |
IonSystems | 6:e64796f1f384 | 9 | 000 Sort red chip |
IonSystems | 6:e64796f1f384 | 10 | 001 Sort green chip |
IonSystems | 6:e64796f1f384 | 11 | 010 Sort blue chip |
IonSystems | 6:e64796f1f384 | 12 | 011 Bin the chip |
IonSystems | 6:e64796f1f384 | 13 | 100 Recycle the chip |
IonSystems | 6:e64796f1f384 | 14 | 101 Nothing |
IonSystems | 6:e64796f1f384 | 15 | 110 Nothing |
IonSystems | 6:e64796f1f384 | 16 | 111 Nothing |
IonSystems | 6:e64796f1f384 | 17 | */ |
IonSystems | 6:e64796f1f384 | 18 | |
IonSystems | 6:e64796f1f384 | 19 | DigitalOut colourBit1(p6); //The 3 bits below are select bits for the sorter. |
IonSystems | 6:e64796f1f384 | 20 | DigitalOut colourBit2(p7); |
IonSystems | 6:e64796f1f384 | 21 | DigitalOut colourBit3(p8); |
IonSystems | 9:8d78eb55ad5e | 22 | DigitalOut startDispense(p18); //A positive edge tells the FPGA to start dispensing. p9 |
IonSystems | 6:e64796f1f384 | 23 | /* |
IonSystems | 6:e64796f1f384 | 24 | 00 Dispense red chip |
IonSystems | 6:e64796f1f384 | 25 | 01 Dispense green chip |
IonSystems | 6:e64796f1f384 | 26 | 10 Dispense blue chip |
IonSystems | 6:e64796f1f384 | 27 | 11 Nothing |
IonSystems | 6:e64796f1f384 | 28 | */ |
IonSystems | 6:e64796f1f384 | 29 | |
IonSystems | 9:8d78eb55ad5e | 30 | DigitalOut dispenseBit1(p19); //The 2 bits below are select bits for the dispenser.p10 |
IonSystems | 9:8d78eb55ad5e | 31 | DigitalOut dispenseBit2(p20); //p11 |
IonSystems | 8:b7771391adc9 | 32 | |
IonSystems | 10:8c0696b99692 | 33 | DigitalIn dispenseComplete(p12); //FPGA sets to 1 once complete until another signal is recieved. |
IonSystems | 10:8c0696b99692 | 34 | DigitalOut select(p15); //0 for control, 1 for maintenance. |
IonSystems | 10:8c0696b99692 | 35 | |
IonSystems | 10:8c0696b99692 | 36 | void dispense(Colour colour){ |
IonSystems | 10:8c0696b99692 | 37 | |
IonSystems | 10:8c0696b99692 | 38 | select = 0; //Setting to operation mode just in case it has not been set. |
IonSystems | 10:8c0696b99692 | 39 | dispenseBit1 = true; |
IonSystems | 10:8c0696b99692 | 40 | dispenseBit2 = true; |
IonSystems | 10:8c0696b99692 | 41 | switch(colour){ |
IonSystems | 10:8c0696b99692 | 42 | case RED: |
IonSystems | 10:8c0696b99692 | 43 | log("RED"); |
IonSystems | 10:8c0696b99692 | 44 | log("Setting dispense bits to 00"); |
IonSystems | 10:8c0696b99692 | 45 | dispenseBit1 = false; |
IonSystems | 10:8c0696b99692 | 46 | dispenseBit2 = false; |
IonSystems | 10:8c0696b99692 | 47 | |
IonSystems | 10:8c0696b99692 | 48 | break; |
IonSystems | 10:8c0696b99692 | 49 | case GREEN: |
IonSystems | 10:8c0696b99692 | 50 | log("GREEN"); |
IonSystems | 10:8c0696b99692 | 51 | log("Setting dispense bits to 10"); |
IonSystems | 10:8c0696b99692 | 52 | dispenseBit1 = true; |
IonSystems | 10:8c0696b99692 | 53 | dispenseBit2 = false; |
IonSystems | 10:8c0696b99692 | 54 | |
IonSystems | 10:8c0696b99692 | 55 | break; |
IonSystems | 10:8c0696b99692 | 56 | case BLUE: |
IonSystems | 10:8c0696b99692 | 57 | log("BLUE"); |
IonSystems | 10:8c0696b99692 | 58 | log("Setting dispense bits to 01"); |
IonSystems | 10:8c0696b99692 | 59 | dispenseBit1 = false; |
IonSystems | 10:8c0696b99692 | 60 | dispenseBit2 = true; |
IonSystems | 10:8c0696b99692 | 61 | |
IonSystems | 10:8c0696b99692 | 62 | break; |
IonSystems | 10:8c0696b99692 | 63 | } |
IonSystems | 10:8c0696b99692 | 64 | |
IonSystems | 10:8c0696b99692 | 65 | |
IonSystems | 10:8c0696b99692 | 66 | log("Setting start dispense to true"); |
IonSystems | 10:8c0696b99692 | 67 | startDispense = true; //set the startDispense line high. |
IonSystems | 10:8c0696b99692 | 68 | |
IonSystems | 10:8c0696b99692 | 69 | |
IonSystems | 10:8c0696b99692 | 70 | //wait(1); //temporary delay |
IonSystems | 10:8c0696b99692 | 71 | while(!dispenseComplete){ |
IonSystems | 11:06f6e82b40a8 | 72 | wait(0.2); |
IonSystems | 10:8c0696b99692 | 73 | log("Waiting for dispense complete"); |
IonSystems | 10:8c0696b99692 | 74 | printLCD("Waiting for dispense complete"); |
IonSystems | 10:8c0696b99692 | 75 | } |
IonSystems | 10:8c0696b99692 | 76 | |
IonSystems | 11:06f6e82b40a8 | 77 | wait(0.5); |
IonSystems | 10:8c0696b99692 | 78 | log("Complete"); |
IonSystems | 10:8c0696b99692 | 79 | log("Setting start dispense to false"); |
IonSystems | 10:8c0696b99692 | 80 | startDispense = false; |
IonSystems | 10:8c0696b99692 | 81 | |
IonSystems | 10:8c0696b99692 | 82 | log("Resetting dispense bits to 11"); |
IonSystems | 10:8c0696b99692 | 83 | dispenseBit1 = true; //reset the dispense select to do nothing |
IonSystems | 10:8c0696b99692 | 84 | dispenseBit2 = true; //reset the dispense select to do nothing |
IonSystems | 10:8c0696b99692 | 85 | |
IonSystems | 10:8c0696b99692 | 86 | |
IonSystems | 10:8c0696b99692 | 87 | |
IonSystems | 10:8c0696b99692 | 88 | printLCD("DISPENSE COMPLETE"); |
IonSystems | 10:8c0696b99692 | 89 | } |
IonSystems | 10:8c0696b99692 | 90 | |
IonSystems | 10:8c0696b99692 | 91 | void sort(Colour colour){ |
IonSystems | 10:8c0696b99692 | 92 | select = 0; //Setting to operation mode just in case it has not been set. |
IonSystems | 10:8c0696b99692 | 93 | colourBit1 = true; |
IonSystems | 10:8c0696b99692 | 94 | colourBit2 = true; |
IonSystems | 10:8c0696b99692 | 95 | colourBit3 = true; |
IonSystems | 10:8c0696b99692 | 96 | switch(colour){ |
IonSystems | 10:8c0696b99692 | 97 | case RED: |
IonSystems | 10:8c0696b99692 | 98 | log("Sort RED"); |
IonSystems | 10:8c0696b99692 | 99 | log("Setting sort bits to 000"); |
IonSystems | 10:8c0696b99692 | 100 | colourBit1 = false; |
IonSystems | 10:8c0696b99692 | 101 | colourBit2 = false; |
IonSystems | 10:8c0696b99692 | 102 | colourBit3 = false; |
IonSystems | 10:8c0696b99692 | 103 | |
IonSystems | 10:8c0696b99692 | 104 | break; |
IonSystems | 10:8c0696b99692 | 105 | case GREEN: |
IonSystems | 10:8c0696b99692 | 106 | log("Sort GREEN"); |
IonSystems | 10:8c0696b99692 | 107 | log("Setting sort bits to 001"); |
IonSystems | 10:8c0696b99692 | 108 | colourBit1 = true; |
IonSystems | 10:8c0696b99692 | 109 | colourBit2 = false; |
IonSystems | 10:8c0696b99692 | 110 | colourBit3 = false; |
IonSystems | 10:8c0696b99692 | 111 | |
IonSystems | 10:8c0696b99692 | 112 | break; |
IonSystems | 10:8c0696b99692 | 113 | case BLUE: |
IonSystems | 10:8c0696b99692 | 114 | log("Sort BLUE"); |
IonSystems | 10:8c0696b99692 | 115 | log("Setting sort bits to 010"); |
IonSystems | 10:8c0696b99692 | 116 | colourBit1 = false; |
IonSystems | 10:8c0696b99692 | 117 | colourBit2 = true; |
IonSystems | 10:8c0696b99692 | 118 | colourBit3 = false; |
IonSystems | 10:8c0696b99692 | 119 | |
IonSystems | 10:8c0696b99692 | 120 | break; |
IonSystems | 11:06f6e82b40a8 | 121 | case BIN: |
IonSystems | 11:06f6e82b40a8 | 122 | log("Sort BIN"); |
IonSystems | 11:06f6e82b40a8 | 123 | log("Setting sort bits to 011"); |
IonSystems | 11:06f6e82b40a8 | 124 | colourBit1 = true; |
IonSystems | 11:06f6e82b40a8 | 125 | colourBit2 = true; |
IonSystems | 11:06f6e82b40a8 | 126 | colourBit3 = false; |
IonSystems | 11:06f6e82b40a8 | 127 | break; |
IonSystems | 11:06f6e82b40a8 | 128 | case RECYCLE: |
IonSystems | 11:06f6e82b40a8 | 129 | log("Recycle"); |
IonSystems | 11:06f6e82b40a8 | 130 | log("Setting sort bits to 100"); |
IonSystems | 11:06f6e82b40a8 | 131 | colourBit1 = false; |
IonSystems | 11:06f6e82b40a8 | 132 | colourBit2 = false; |
IonSystems | 11:06f6e82b40a8 | 133 | colourBit3 = true; |
IonSystems | 11:06f6e82b40a8 | 134 | break; |
IonSystems | 10:8c0696b99692 | 135 | } |
IonSystems | 10:8c0696b99692 | 136 | |
IonSystems | 10:8c0696b99692 | 137 | |
IonSystems | 10:8c0696b99692 | 138 | log("Setting start sort to true"); |
IonSystems | 10:8c0696b99692 | 139 | startSort = true; //set the startDispense line high. |
IonSystems | 10:8c0696b99692 | 140 | |
IonSystems | 10:8c0696b99692 | 141 | |
IonSystems | 10:8c0696b99692 | 142 | //wait(1); //temporary delay |
IonSystems | 10:8c0696b99692 | 143 | while(!sortComplete){ |
IonSystems | 11:06f6e82b40a8 | 144 | wait(0.5); |
IonSystems | 10:8c0696b99692 | 145 | log("Waiting for sort complete"); |
IonSystems | 10:8c0696b99692 | 146 | printLCD("Waiting for sort complete"); |
IonSystems | 10:8c0696b99692 | 147 | } |
IonSystems | 10:8c0696b99692 | 148 | |
IonSystems | 10:8c0696b99692 | 149 | |
IonSystems | 10:8c0696b99692 | 150 | log("Complete"); |
IonSystems | 11:06f6e82b40a8 | 151 | wait(0.5); |
IonSystems | 10:8c0696b99692 | 152 | log("Setting start sort to false"); |
IonSystems | 11:06f6e82b40a8 | 153 | startSort = false; |
IonSystems | 10:8c0696b99692 | 154 | |
IonSystems | 10:8c0696b99692 | 155 | log("Resetting dispense bits to 11"); |
IonSystems | 10:8c0696b99692 | 156 | colourBit1 = true; //reset the dispense select to do nothing |
IonSystems | 10:8c0696b99692 | 157 | colourBit2 = true; //reset the dispense select to do nothing |
IonSystems | 10:8c0696b99692 | 158 | colourBit3 = true; |
IonSystems | 10:8c0696b99692 | 159 | printLCD("SORT COMPLETE"); |
IonSystems | 10:8c0696b99692 | 160 | |
IonSystems | 10:8c0696b99692 | 161 | } |