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:
Fri Nov 07 20:16:23 2014 +0000
Revision:
6:e64796f1f384
Child:
7:6ba00694f9cd
Recovered from the attack of Euan

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 6:e64796f1f384 1 char readBit(int bitNumber){
IonSystems 6:e64796f1f384 2 int value = 0;
IonSystems 6:e64796f1f384 3 switch(bitNumber){
IonSystems 6:e64796f1f384 4 case 1:
IonSystems 6:e64796f1f384 5 value = cardBit1;
IonSystems 6:e64796f1f384 6 break;
IonSystems 6:e64796f1f384 7 case 2:
IonSystems 6:e64796f1f384 8 value = cardBit2;
IonSystems 6:e64796f1f384 9 break;
IonSystems 6:e64796f1f384 10 case 3:
IonSystems 6:e64796f1f384 11 value = cardBit3;
IonSystems 6:e64796f1f384 12 break;
IonSystems 6:e64796f1f384 13 case 4:
IonSystems 6:e64796f1f384 14 value = cardBit4;
IonSystems 6:e64796f1f384 15 break;
IonSystems 6:e64796f1f384 16 case 5:
IonSystems 6:e64796f1f384 17 value = cardBit5;
IonSystems 6:e64796f1f384 18 break;
IonSystems 6:e64796f1f384 19 case 6:
IonSystems 6:e64796f1f384 20 value = cardBit6;
IonSystems 6:e64796f1f384 21 break;
IonSystems 6:e64796f1f384 22 }
IonSystems 6:e64796f1f384 23 return valueToChar(value);
IonSystems 6:e64796f1f384 24 }
IonSystems 6:e64796f1f384 25
IonSystems 6:e64796f1f384 26 void processMessage(char c){
IonSystems 6:e64796f1f384 27 switch(c){
IonSystems 6:e64796f1f384 28 case 'a' : //servo 1 clockwise
IonSystems 6:e64796f1f384 29 sendCharacter('a'); //bounce back for acknowledgement
IonSystems 6:e64796f1f384 30 printLCD("S1 clockwise");
IonSystems 6:e64796f1f384 31 break;
IonSystems 6:e64796f1f384 32 case 'b' : //servo 1 anticlockwise
IonSystems 6:e64796f1f384 33 sendCharacter('b'); //bounce back for acknowledgement
IonSystems 6:e64796f1f384 34 printLCD("S1 anticlockwise");
IonSystems 6:e64796f1f384 35 break;
IonSystems 6:e64796f1f384 36 case 'c':
IonSystems 6:e64796f1f384 37 sendCharacter('c'); //bounce back for acknowledgement
IonSystems 6:e64796f1f384 38 printLCD("S1 stop");
IonSystems 6:e64796f1f384 39 break;
IonSystems 6:e64796f1f384 40 case 'C':// Read card command
IonSystems 6:e64796f1f384 41 sendCharacter('R'); //Notify PC that command has been recieved
IonSystems 6:e64796f1f384 42 printLCD("Reading Card");
IonSystems 6:e64796f1f384 43 //read card here
IonSystems 6:e64796f1f384 44 char value = ' ';
IonSystems 6:e64796f1f384 45 for(int num = 1;num <= 6;num++){
IonSystems 6:e64796f1f384 46 value = readBit(num);
IonSystems 6:e64796f1f384 47 // sendCharacter('R');
IonSystems 6:e64796f1f384 48 sendCharacter(value);
IonSystems 6:e64796f1f384 49 printLCD("Bit read");
IonSystems 6:e64796f1f384 50 //wait(0.1);
IonSystems 6:e64796f1f384 51 }
IonSystems 6:e64796f1f384 52 sendCharacter('C'); //Tells PC that the card has been read
IonSystems 6:e64796f1f384 53 printLCD("Card read done");
IonSystems 6:e64796f1f384 54 break;
IonSystems 6:e64796f1f384 55 case 'X':
IonSystems 6:e64796f1f384 56 sendCharacter('X'); //Notify the PC that this is an MBED
IonSystems 6:e64796f1f384 57 printLCD("Connected to PC");
IonSystems 6:e64796f1f384 58 break;
IonSystems 6:e64796f1f384 59 case 'd': //Dispense a chip
IonSystems 6:e64796f1f384 60 sendCharacter('D');
IonSystems 6:e64796f1f384 61 printLCD("Dispensing chip");
IonSystems 6:e64796f1f384 62
IonSystems 6:e64796f1f384 63 //read from color sensor
IonSystems 6:e64796f1f384 64 //convert readings to colour
IonSystems 6:e64796f1f384 65 //convert colour to 3-bit colour code
IonSystems 6:e64796f1f384 66 //set the FPGA colour inputs to the colour code
IonSystems 6:e64796f1f384 67 startSort = true;
IonSystems 6:e64796f1f384 68 break;
IonSystems 6:e64796f1f384 69 case 't'://Test 180 servo
IonSystems 6:e64796f1f384 70 sendCharacter('T');
IonSystems 6:e64796f1f384 71 printLCD("Servo signal on");
IonSystems 6:e64796f1f384 72 servoTest = true;
IonSystems 6:e64796f1f384 73 break;
IonSystems 6:e64796f1f384 74 case 'w'://Test 180 servo
IonSystems 6:e64796f1f384 75 sendCharacter('W');
IonSystems 6:e64796f1f384 76 printLCD("Servo signal off");
IonSystems 6:e64796f1f384 77 servoTest = false;
IonSystems 6:e64796f1f384 78 break;
IonSystems 6:e64796f1f384 79
IonSystems 6:e64796f1f384 80
IonSystems 6:e64796f1f384 81 else if (operationMode){
IonSystems 6:e64796f1f384 82 switch(c){
IonSystems 6:e64796f1f384 83 case 'n':// Start sorting
IonSystems 6:e64796f1f384 84 sendCharacter('N'); //Confirm to PC that we are processing the instruction.
IonSystems 6:e64796f1f384 85 startSort = true; //Pulse the startSort control line to FPGA
IonSystems 6:e64796f1f384 86 wait(0.1);
IonSystems 6:e64796f1f384 87 startSort = false;
IonSystems 6:e64796f1f384 88 break;
IonSystems 6:e64796f1f384 89 case 'o': //Start dispensing
IonSystems 6:e64796f1f384 90 sendCharacter('O');
IonSystems 6:e64796f1f384 91 startDispense = true; //Pulse the startDispense control line to FPGA
IonSystems 6:e64796f1f384 92 wait(0.1);
IonSystems 6:e64796f1f384 93 startDispense = false;
IonSystems 6:e64796f1f384 94 break;
IonSystems 6:e64796f1f384 95 case 'p': //
IonSystems 6:e64796f1f384 96 sendCharacter('P');
IonSystems 6:e64796f1f384 97 break;
IonSystems 6:e64796f1f384 98 }
IonSystems 6:e64796f1f384 99 }
IonSystems 6:e64796f1f384 100 }
IonSystems 6:e64796f1f384 101
IonSystems 6:e64796f1f384 102 void sendCharacter(char ch){
IonSystems 6:e64796f1f384 103 pc.putc(ch);
IonSystems 6:e64796f1f384 104 }
IonSystems 6:e64796f1f384 105
IonSystems 6:e64796f1f384 106 void sendString(char* ch){
IonSystems 6:e64796f1f384 107 pc.puts(ch);
IonSystems 6:e64796f1f384 108 }