CS 452/652 Spring 2022 - Lecture 2
May 5, 2022
prev next
Timers
- Chapter 18 in EP93xx User Guide
- memory-mapped device registers
- configuration
- load start/reset value
- read current value
- timer counter width: 16 bit vs 32 bit
- timer mode: free-running vs. periodic
- periodic can be used for configurable interrupt generation
- timer speed: 2 kHz vs. 508 kHz → 508 kHz is recommended
- time horizon = timer counter width / timer speed
- debug/watchdog timers: usage optional
- here: no time of day needed, no remote synchronization (very hard problem)
Serial Interface (UART)
- Chapter 14 in EP93xx User Guide
- in particular, read "UART Register Descriptions" in Section 14.1
- ignore "Modem Register Descriptions" starting on Page 14-25
- character device: 1 byte at a time, asynchronous transmission
- memory-mapped device registers
- configuration: speed, byte representation, fifo
- UART1 = COM1, train control, 2400 baud, 8N2, flow control
- UART2 = COM2, terminal, 115200 baud, 8N1, no flow control
- RX/TX status
- receive status (discard byte, reset after error)
- data in/out
- timing: 2400 baud with 8N2 → 240 bytes/sec
- character in UART vs. character transmitted
- flow control: character transmission vs. reception & processing (details later)
- A0: where necessary, add short pauses
- fifo: throughput vs. latency trade-off - review with interrupts
Track/Train Specifics
- train speed: 0-14; 15 for reverse (add 16 to turn on lights)
- model trains simulate real-world stopping by gradually slowing down
- we want to preserve this important characteristic
⇒ do not directly reverse rolling train!
- turnout commands: straight, curved
- NOTE: the middle turnouts should always be set to S/C or C/S → avoid C/C, S/S
- special command: turn off (last) solenoid
- IMPORTANT: After sending a turnout command, you must wait at least 100ms and at most 500ms. Then, either switch another turnout (which automatically turns off the previous solenoid) or explicitly turn off the last solenoid!
- sensors: query some/all
- tracks have 5x16 sensors
- set reset mode (single command byte 0xC0)
- read reports after query
- IMPORTANT: track communication is half-duplex, i.e., no control while receiving sensor data
Polling Loop with Busy Wait?
for (;;) {
while (!c1);
a1();
while (!c2);
a2();
...
}
cannot handle c2 while waiting for c1, etc...