OrganProject

Check-in [95f796cc4d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:System integration to card reader. Reallocated pins for a more sensible layout on the RBBB in the card reader. Changed LED timings to reflect the hypothesis that there are two distinct clock phases, not a quadrature signal. Changed terminal code to pull the PS/2 connector pins actively HIGH momentarily before attaching a pullup resistor. This makes a cleaner transition on the cable and avoids spurious interrupts at the LED controller.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:95f796cc4db4a92561135f0d06678d5af45c9c11
User & Date: 200002852 2009-09-01 02:48:15
Context
2009-09-05
17:11
Add the schematics and datasheets for the LED control Leaf check-in: 0b63f0d802 user: 200002852 tags: trunk
2009-09-01
02:48
System integration to card reader. Reallocated pins for a more sensible layout on the RBBB in the card reader. Changed LED timings to reflect the hypothesis that there are two distinct clock phases, not a quadrature signal. Changed terminal code to pull the PS/2 connector pins actively HIGH momentarily before attaching a pullup resistor. This makes a cleaner transition on the cable and avoids spurious interrupts at the LED controller. check-in: 95f796cc4d user: 200002852 tags: trunk
2009-08-24
02:45
Added the code to fire the LED's. Breadboard now demonstrates stop selection end-to-end check-in: 41508259dd user: 200002852 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ledcontrol/ledcontrol.pde.

14
15
16
17
18
19
20
21
22
23
24
25
26
27



28
29
30
31
32
33
34
...
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
...
462
463
464
465
466
467
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
...
666
667
668
669
670
671
672

673
674
675
676
677
678
679
 *                                                                            *
 *                                  PS/2 PORT                                 *
 *                                                                            *
 ******************************************************************************/

/* Definitions */

#define PS2_CLOCK_PIN	2	/* Clock pin */
#define PS2_DATA_PIN	3	/* Data pin */
#define PS2_CLOCK_INTR	0	/* Clock interrupt number */

#define PS2_RING_BUFFER_SIZE 64	/* Length of the input buffer */

#define PS2_MAX_FRAME_TIME 3




/* RAM */

typedef enum {
  PS2_IDLE,			/* Port is idle */
  PS2_READ_DATA_BIT = 0x1,	/* Port is expecting a data bit */
  PS2_READ_PARITY = 0x9,	/* Port is expecting the parity bit */
................................................................................
/*
 ******************************************************************************
 *                                                                            *
 *			LED SYSTEM					      *
 *                                                                            *
 ******************************************************************************/

#define LED_CARD_PRESENT_PIN	8 /* Row 12 of card = 'card present' */
#define LED_PH1_PIN	       13 /* Row 8 of card = clock phase 1 */
#define LED_PH2_PIN	       14 /* Row 9 of card = clock phase 2 */
#define LED_COUNT 	       10 /* Number of LEDs being controlled */

#define LED_CLOCK_PERIOD_MS     4 /* Number of milliseconds per clock
				   * period (six clock periods per data
				   * byte) */

/* PROGRAM MEMORY */

const byte ledPins[] PROGMEM = {
  7, 6, 5, 9, 10, 11, 12,	/* 7 data bits */
  LED_PH2_PIN, LED_PH1_PIN,	/* 2 clock bits */
  LED_CARD_PRESENT_PIN		/* Card present */
};
#define LED_PH1_INDEX	8
#define LED_PH2_INDEX   7

enum LedState {
................................................................................
      ledDelay = LED_CLOCK_PERIOD_MS * 24;
      break;
    case LED_CARD_ENTERING_0:
      ledDataByte(wavetable[ledWaveIndex++]);
      ledState = LED_CARD_ENTERING_1;
      break;
    case LED_CARD_ENTERING_1:
      ledOn(LED_PH1_INDEX);
      ledState = LED_CARD_ENTERING_2;
      break;
    case LED_CARD_ENTERING_2:
      ledDataByte(0); ledOff(LED_PH2_INDEX);
      ledState = LED_CARD_ENTERING_3;

      break;
    case LED_CARD_ENTERING_3:
      ledOff(LED_PH1_INDEX);
      if (ledWaveIndex == 16) {
	ledState = LED_CARD_LEAVING_0;
	ledDelay = LED_CLOCK_PERIOD_MS * 24;
      } else {
	ledState = LED_CARD_ENTERING_0;
	ledDelay = LED_CLOCK_PERIOD_MS * 3;
      }
      break;
    case LED_CARD_LEAVING_0:
      ledOn(LED_PH1_INDEX);
      ledState = LED_CARD_LEAVING_1;
      break;
    case LED_CARD_LEAVING_1:
      ledDataByte(wavetable[--ledWaveIndex]);
      ledState = LED_CARD_LEAVING_2;
      break;
    case LED_CARD_LEAVING_2:
      ledOff(LED_PH1_INDEX);
      ledState = LED_CARD_LEAVING_3;
      break;
    case LED_CARD_LEAVING_3:
      ledDataByte(0); ledOff(LED_PH2_INDEX);
      if(ledWaveIndex == 0) {
	ledState = LED_CARD_EXITING;
	ledDelay = LED_CLOCK_PERIOD_MS * 24;
      } else {
	ledState = LED_CARD_LEAVING_0;
	ledDelay = LED_CLOCK_PERIOD_MS * 3;
      }
      break;
    case LED_CARD_EXITING:
      ledRemoveCard();
      ledState = LED_IDLE;
      break;
    case LED_IDLE:
................................................................................
 *-----------------------------------------------------------------------------
 */

void
cpPoll(void)
{
  byte b;

  if (ps2GetByte(&b)) {
    Serial.print(b, BYTE);
    if (b == '\n') {
      cpAction();
    } else if (cpState == CP_STOP) {
      cpAccumStop(b);
    } else if (cpState == CP_IDLE) {







|
|
|



|
>
>
>







 







|
|
|


|
|





|







 







|



<

>








<







|



|









<







 







>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
...
465
466
467
468
469
470
471
472
473
474
475

476
477
478
479
480
481
482
483
484
485

486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
...
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
 *                                                                            *
 *                                  PS/2 PORT                                 *
 *                                                                            *
 ******************************************************************************/

/* Definitions */

#define PS2_CLOCK_PIN	3	/* Clock pin */
#define PS2_DATA_PIN	2	/* Data pin */
#define PS2_CLOCK_INTR	1	/* Clock interrupt number */

#define PS2_RING_BUFFER_SIZE 64	/* Length of the input buffer */

#define PS2_MAX_FRAME_TIME 30   /* Frames are transmitted at at least
				 * 10k baud and are 11 bits long, so
				 * should terminate in 1.1 ms.  Be totally
				 * unreasonable and allow 30 ms. */

/* RAM */

typedef enum {
  PS2_IDLE,			/* Port is idle */
  PS2_READ_DATA_BIT = 0x1,	/* Port is expecting a data bit */
  PS2_READ_PARITY = 0x9,	/* Port is expecting the parity bit */
................................................................................
/*
 ******************************************************************************
 *                                                                            *
 *			LED SYSTEM					      *
 *                                                                            *
 ******************************************************************************/

#define LED_CARD_PRESENT_PIN   18 /* Row 12 of card = 'card present' */
#define LED_PH1_PIN	       10 /* Row 8 of card = clock phase 1 */
#define LED_PH2_PIN	       9 /* Row 9 of card = clock phase 2 */
#define LED_COUNT 	       10 /* Number of LEDs being controlled */

#define LED_CLOCK_PERIOD_MS     6 /* Number of milliseconds per clock
				   * period (four clock periods per data
				   * byte) */

/* PROGRAM MEMORY */

const byte ledPins[] PROGMEM = {
  17, 16, 15, 14, 13, 12, 11,	/* 7 data bits */
  LED_PH2_PIN, LED_PH1_PIN,	/* 2 clock bits */
  LED_CARD_PRESENT_PIN		/* Card present */
};
#define LED_PH1_INDEX	8
#define LED_PH2_INDEX   7

enum LedState {
................................................................................
      ledDelay = LED_CLOCK_PERIOD_MS * 24;
      break;
    case LED_CARD_ENTERING_0:
      ledDataByte(wavetable[ledWaveIndex++]);
      ledState = LED_CARD_ENTERING_1;
      break;
    case LED_CARD_ENTERING_1:
      ledDataByte(0); ledOff(LED_PH2_INDEX);
      ledState = LED_CARD_ENTERING_2;
      break;
    case LED_CARD_ENTERING_2:

      ledState = LED_CARD_ENTERING_3;
      ledOn(LED_PH1_INDEX);
      break;
    case LED_CARD_ENTERING_3:
      ledOff(LED_PH1_INDEX);
      if (ledWaveIndex == 16) {
	ledState = LED_CARD_LEAVING_0;
	ledDelay = LED_CLOCK_PERIOD_MS * 24;
      } else {
	ledState = LED_CARD_ENTERING_0;

      }
      break;
    case LED_CARD_LEAVING_0:
      ledOn(LED_PH1_INDEX);
      ledState = LED_CARD_LEAVING_1;
      break;
    case LED_CARD_LEAVING_1:
      ledOff(LED_PH1_INDEX);
      ledState = LED_CARD_LEAVING_2;
      break;
    case LED_CARD_LEAVING_2:
      ledDataByte(wavetable[--ledWaveIndex]);
      ledState = LED_CARD_LEAVING_3;
      break;
    case LED_CARD_LEAVING_3:
      ledDataByte(0); ledOff(LED_PH2_INDEX);
      if(ledWaveIndex == 0) {
	ledState = LED_CARD_EXITING;
	ledDelay = LED_CLOCK_PERIOD_MS * 24;
      } else {
	ledState = LED_CARD_LEAVING_0;

      }
      break;
    case LED_CARD_EXITING:
      ledRemoveCard();
      ledState = LED_IDLE;
      break;
    case LED_IDLE:
................................................................................
 *-----------------------------------------------------------------------------
 */

void
cpPoll(void)
{
  byte b;

  if (ps2GetByte(&b)) {
    Serial.print(b, BYTE);
    if (b == '\n') {
      cpAction();
    } else if (cpState == CP_STOP) {
      cpAccumStop(b);
    } else if (cpState == CP_IDLE) {

Changes to terminal/terminal.pde.

727
728
729
730
731
732
733

734

735
736

737
738
739
740
741
742
743
744
745
....
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
 */

void
ps2WritePin(byte pin,		/* Pin number */
	    byte value)		/* Value to write */
{
  if (value) {

    pinMode(pin, INPUT);

  } else {
    pinMode(pin, OUTPUT);

  }
  digitalWrite(pin, value);
}
 
/*
 *-----------------------------------------------------------------------------
 *
 * ps2Init --
 *
................................................................................
    ps2SendByte(pgm_read_byte(HexTable + (selectedStop[i] >> 4)));
    ps2SendByte(pgm_read_byte(HexTable + (selectedStop[i] & 0xf)));
  }
  ps2SendByte('\n');
  menuShow(menuCurrent);
}
 
/* TEMP */

void
setup() {

  kpInit();			/* Initialize the keypad */
  dispInit();			/* Initialize the display */
  ps2Init();			/* Initialize the communication port */

  now = millis();
  menuLastKeyMillis = now;
  menuShow(&mainMenu);

  /* TEMP - Prime the PS/2 port with some test data */

  {
    char* p;
    byte c;
    for (p = PSTR("TEST U*U*U*U*U*U*U*U*U*U*U*U*\r\n");
	 (c = pgm_read_byte(p)) != '\0';
	 ++p) {
      ps2SendByte(c);
    }
  }
  
}

void
loop() {

  now = millis();








>

>


>

<







 







<












|
<
<


<
|
<



<







727
728
729
730
731
732
733
734
735
736
737
738
739
740

741
742
743
744
745
746
747
....
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232


1233
1234

1235

1236
1237
1238

1239
1240
1241
1242
1243
1244
1245
 */

void
ps2WritePin(byte pin,		/* Pin number */
	    byte value)		/* Value to write */
{
  if (value) {
    digitalWrite(pin, HIGH);	/* Try to drive a clean transition */
    pinMode(pin, INPUT);
    digitalWrite(pin, HIGH);
  } else {
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
  }

}
 
/*
 *-----------------------------------------------------------------------------
 *
 * ps2Init --
 *
................................................................................
    ps2SendByte(pgm_read_byte(HexTable + (selectedStop[i] >> 4)));
    ps2SendByte(pgm_read_byte(HexTable + (selectedStop[i] & 0xf)));
  }
  ps2SendByte('\n');
  menuShow(menuCurrent);
}
 


void
setup() {

  kpInit();			/* Initialize the keypad */
  dispInit();			/* Initialize the display */
  ps2Init();			/* Initialize the communication port */

  now = millis();
  menuLastKeyMillis = now;
  menuShow(&mainMenu);

  {				/* TEMP - Send a comment for debugging */


    char* p;
    byte c;

    for (p = PSTR("TEST\n"); (c = pgm_read_byte(p)) != '\0'; ++p) {

      ps2SendByte(c);
    }
  }

}

void
loop() {

  now = millis();