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

Committer:
IonSystems
Date:
Mon Nov 10 19:01:43 2014 +0000
Revision:
9:8d78eb55ad5e
Parent:
8:b7771391adc9
Child:
10:8c0696b99692
red dispenser currently controlled by button 2 on MBED for testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 0:8d54ffcf256e 1 #include "mbed.h"
IonSystems 6:e64796f1f384 2 #include <sstream>
IonSystems 6:e64796f1f384 3 #include "lcdCommands.h"
IonSystems 6:e64796f1f384 4 #include "mbedStorage.h"
IonSystems 6:e64796f1f384 5 #include "rgbLED.h"
IonSystems 6:e64796f1f384 6 #include "mbedLCD.h"
IonSystems 7:6ba00694f9cd 7 #include "stateMachine.h"
IonSystems 8:b7771391adc9 8 #include "FPGAcomms.h"
IonSystems 5:644bca33c1ca 9
IonSystems 0:8d54ffcf256e 10
IonSystems 6:e64796f1f384 11 Serial pc(USBTX, USBRX);
IonSystems 3:97668a4cd69d 12
IonSystems 7:6ba00694f9cd 13 StateMachine stateMachine;
IonSystems 7:6ba00694f9cd 14
IonSystems 3:97668a4cd69d 15
IonSystems 6:e64796f1f384 16 //Boolean values to easily enable and disable certain features for individual testing
IonSystems 6:e64796f1f384 17 bool colourSensor = true;
IonSystems 6:e64796f1f384 18 bool cardReader = true;
IonSystems 6:e64796f1f384 19 bool sorter = true;
IonSystems 6:e64796f1f384 20 bool dispensor = true;
IonSystems 6:e64796f1f384 21
IonSystems 6:e64796f1f384 22 bool cardDataAcquired = false;
IonSystems 6:e64796f1f384 23 bool colourDataAcquired = false;
IonSystems 6:e64796f1f384 24 bool chipDetected = false;
IonSystems 6:e64796f1f384 25 bool operationMode = true; //the MBED starts in operation mode.
IonSystems 3:97668a4cd69d 26
IonSystems 8:b7771391adc9 27 void processState(StateMachine stateMachine){
IonSystems 8:b7771391adc9 28 switch(stateMachine){
IonSystems 8:b7771391adc9 29 case INITIALISING:
IonSystems 8:b7771391adc9 30 setupLCD();
IonSystems 8:b7771391adc9 31 printLCD("Welcome to the Chipin Sorter");
IonSystems 8:b7771391adc9 32 wait(1);
IonSystems 8:b7771391adc9 33 break;
IonSystems 8:b7771391adc9 34 case READING_RGB_VALUES:
IonSystems 8:b7771391adc9 35 readChipNumbers();
IonSystems 8:b7771391adc9 36 break;
IonSystems 8:b7771391adc9 37 case DISPENSE_RED:
IonSystems 8:b7771391adc9 38 printLCD("DISPENSING A RED CHIP");
IonSystems 8:b7771391adc9 39 select = 0; //Setting to operation mode just in case it has not been set.
IonSystems 9:8d78eb55ad5e 40 dispenseBit1 = true;
IonSystems 9:8d78eb55ad5e 41 dispenseBit2 = true;
IonSystems 9:8d78eb55ad5e 42
IonSystems 9:8d78eb55ad5e 43 dispenseBit2 = false;
IonSystems 9:8d78eb55ad5e 44 dispenseBit1 = false;
IonSystems 9:8d78eb55ad5e 45 wait(0.01);
IonSystems 9:8d78eb55ad5e 46 startDispense = true; //set the startDispense line high.
IonSystems 9:8d78eb55ad5e 47
IonSystems 9:8d78eb55ad5e 48
IonSystems 8:b7771391adc9 49 //wait(1); //temporary delay
IonSystems 9:8d78eb55ad5e 50 while(!complete){
IonSystems 9:8d78eb55ad5e 51 wait(0.1);
IonSystems 9:8d78eb55ad5e 52 printLCD("Waiting to complete");
IonSystems 9:8d78eb55ad5e 53 }
IonSystems 9:8d78eb55ad5e 54 dispenseBit1 = true; //reset the dispense select to do nothing
IonSystems 9:8d78eb55ad5e 55 dispenseBit2 = true; //reset the dispense select to do nothing
IonSystems 9:8d78eb55ad5e 56 //startDispense = false;
IonSystems 9:8d78eb55ad5e 57 printLCD("RED DISPENSE COMPLETE");
IonSystems 9:8d78eb55ad5e 58
IonSystems 8:b7771391adc9 59 break;
IonSystems 8:b7771391adc9 60 }
IonSystems 8:b7771391adc9 61 }
IonSystems 6:e64796f1f384 62
IonSystems 6:e64796f1f384 63 int main() {
IonSystems 7:6ba00694f9cd 64 stateMachine = INITIALISING;
IonSystems 8:b7771391adc9 65 processState(stateMachine);
IonSystems 7:6ba00694f9cd 66 writeFile(2,6,22);
IonSystems 8:b7771391adc9 67 stateMachine = READING_RGB_VALUES;
IonSystems 8:b7771391adc9 68 processState(stateMachine);
IonSystems 8:b7771391adc9 69
IonSystems 8:b7771391adc9 70 while(true){
IonSystems 9:8d78eb55ad5e 71 if(par_port->read_bit(9)){
IonSystems 8:b7771391adc9 72 stateMachine = DISPENSE_RED;
IonSystems 8:b7771391adc9 73 processState(stateMachine);
IonSystems 8:b7771391adc9 74 }
IonSystems 8:b7771391adc9 75 }
IonSystems 9:8d78eb55ad5e 76
IonSystems 9:8d78eb55ad5e 77
IonSystems 9:8d78eb55ad5e 78
IonSystems 8:b7771391adc9 79
IonSystems 8:b7771391adc9 80
IonSystems 8:b7771391adc9 81
IonSystems 8:b7771391adc9 82
IonSystems 8:b7771391adc9 83
IonSystems 8:b7771391adc9 84
IonSystems 8:b7771391adc9 85 //printStoredChipValues();
IonSystems 6:e64796f1f384 86 /*
IonSystems 0:8d54ffcf256e 87 while(1){
IonSystems 3:97668a4cd69d 88 if(par_port->read_bit(11)) resetForNextCustomer();
IonSystems 7:6ba00694f9cd 89
IonSystems 3:97668a4cd69d 90 if(cardDetect & !cardDataAcquired) cardAcquisition();
IonSystems 3:97668a4cd69d 91 setLEDs();
IonSystems 3:97668a4cd69d 92 readButtons();
IonSystems 3:97668a4cd69d 93
IonSystems 4:f3be545b3826 94 if(chipDetected & !colourDataAcquired){
IonSystems 4:f3be545b3826 95 Colour colour = readColourSensor();
IonSystems 4:f3be545b3826 96 sendColourSignal(colour);
IonSystems 4:f3be545b3826 97 }
IonSystems 4:f3be545b3826 98
IonSystems 5:644bca33c1ca 99 writeFile(redQueue, greenQueue, blueQueue);
IonSystems 4:f3be545b3826 100 readFile();
IonSystems 4:f3be545b3826 101 wait(2);
IonSystems 4:f3be545b3826 102
IonSystems 0:8d54ffcf256e 103 }
IonSystems 6:e64796f1f384 104 */
IonSystems 6:e64796f1f384 105
IonSystems 8:b7771391adc9 106 /* setLEDcolour(255,0,0);
IonSystems 6:e64796f1f384 107 wait(0.1);
IonSystems 6:e64796f1f384 108 setLEDcolour(0,255,0);
IonSystems 6:e64796f1f384 109 wait(0.1);
IonSystems 6:e64796f1f384 110 setLEDcolour(0,0,255);
IonSystems 6:e64796f1f384 111 wait(0.1);
IonSystems 6:e64796f1f384 112
IonSystems 8:b7771391adc9 113 displayOperationMode(); */
IonSystems 3:97668a4cd69d 114
IonSystems 6:e64796f1f384 115 }