1 of 18

EE 319K�Introduction to Embedded Systems

Lecture 13: �Lab 10 Requirements, Schedule, Game engine, Sound

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

http://youtu.be/QxDQUUDStOw

13-1

2 of 18

Agenda

  • Recap
    • Lab9
    • UART, Interrupts
    • FIFO Queues
    • Race Condition, Critical section
  • Agenda
    • Lab 10 schedule and requirements,
    • Standard hardware
    • Game engine
      • Call graph, Data flow, Flowchart
    • Timers and sound

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

https://www.youtube.com/watch?v=KgrlOPFZtlo

13-2

3 of 18

Lab10 – Schedule

  • Friday, 4/22, 11pm, submit a proposal, edit the GoogleDoc� �https://docs.google.com/document/d/1CaKjDjtigh_SSH7nRQqYKEKcgx83ilUT-1_nLLkrEqM/edit?usp=sharing
  • All teams must submit a proposal, even if Space Invaders
  • Lab 10 checkout (demo to TA)
    • Tuesday-Wednesday-Thursday, 5/3, 5/4, 5/5,
    • Regular slot 
  • Lab 10 YouTube video
    • Deadline Friday 5/6 by 5pm on Canvas
  • Lab 10 Late checkout
    • Deadline Friday 5/6 by 5pm - any TA, any office hour
  • After 5pm Friday 5/6, no checkout or YouTube submission
  • YouTube voting for “best game” on Canvas
    • Starts Monday 5/9 2pm and ends Friday 5/13 noon
    • YouTube voting is just for fun

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

13-3

4 of 18

Lab10 – Requirements

  • There must be at least two buttons (on-board or external) and one slide pot (a joystick counts as two slide pots). Buttons and slide pot must affect game play. The slide pot must be sampled by the ADC at a periodic rate.
  • There must be at least three sprites/images on the LCD display that move in relation to user input and/or time.
  • There must be sounds appropriate for the game, generated by the DAC developed in Lab 7. However, the interrupt can be of a fixed period.
  • The score should be displayed on the screen (but it could be displayed before or after the game action).
  • At least two interrupt ISRs must be used in appropriate manners.
  • The game must be both simple to learn and fun to play.
  • It must run in at least two languages.
  • Creating a YouTube video of your finished project is worth 0.6% points out of the 6%

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

13-4

5 of 18

Lab10 – Standard Connections

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

These connections are optional

TAs can run your code

Avoid PB7 PB6 because

-PB7 connected to PD1

-PB6 connected to PD0

13-5

6 of 18

Lab 10 – Extra Features

Here are some extra features you may consider implementing if you want your game to stand out. Doing these features is also a good exam preparation strategy:

  • Edge-Triggered Interrupts, hardware debounce with capacitor
  • Multi-player game with multiple controllers
  • UART used for communication with two LaunchPads
  • More than 4 awesome sound effects connected to game events
  • Multiple levels in game with demonstrable rise in intelligence and difficulty
  • Layering of graphics, showing one image over top other images
  • Use of any specialized hardware (note you must write all software). An accelerometer or joystick makes for fun games.
  • Soldered on a solder-board
  • Digital Signal Processing. You must explain what it does and how it works.
  • Solved a distributed computing problem in a multi-player game. Each player has its own thread, and the computer executes the threads independent of each other. The threads may be running on different LaunchPads or running on the same LaunchPad, independent of each other.

Spring 2022 has no extra credit in Lab 10

13-6

7 of 18

EE319H Software Design

  • Modular programming
    • Make it easier to understand
      • Each screen is a complete story without scrolling
    • Maximize the number of modules
    • Minimize the interdependency
      • Bandwidth coupling: data passed from one to another
      • Control coupling: actions in one cause effects in another
      • Innovation coupling: one module calls another
      • Shared variables (very bad)

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Move code into same module

13-7

8 of 18

Game Engine – Call graph

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

13-8

9 of 18

Game Engine – Data Flow

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

6 bits

6-bit DAC

13-9

10 of 18

Software Testing

  • Design for test
    • Consider how it will be tested while designing
    • Module has three files
      • Header: What the module does
      • Code: How it works
      • Test: A main program used to test the module
  • Incremental development
    • Write a module (sound, slidepot, switches…)
    • Debug the module separately
    • Combine modules and test again

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

It is SO SAD to see students in office hours, asking “Why does my game not work?”

13-10

11 of 18

Resource Constrained

  • LCD graphics 192 by 128 pixels
  • 256 kibibytes ROM, 32 kibibytes of RAM
  • Free version of Keil 32k size limit
      • Ask your professor for 1-year full version
  • 1024 bytes of stack
  • Time (processor time)
    • A fun game requires careful control of time
  • Input/Output
    • Switches, slide pot, DAC, LCD
    • A fun game requires careful use of I/O

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

50% of the time is spent sending images to the LCD

13-11

12 of 18

Game Engine – Flowchart

Bard, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

Could use GPIO edge-triggered interrupts

  • All LCD output in main
  • Do not erase the LCD, it causes flicker
  • Play sound just enables Timer2A

13-12

13 of 18

Three threads

void SysTick_Handler(void){ // 30 Hz, every 33ms

// read switches, what do the switches mean?

// read ADC, what does the slide pot mean?

// run the game engine, move sprites, collisions

// if needed, start sound (arm TIMER2A, set parameters)

Semaphore = 1; // things have changed

} // time to execute this ISR is much less than 33ms

int main(void){

DisableInterrupts();

// initializations

EnableInterrupts();

while(1){

if(Semaphore){

// LCD output

Semaphore = 0;

}

}

}

void Timer2A_Handler(void){// 11kHz

// acknowledge interrupt

// if playing sound, one DAC out

}

13-13

14 of 18

Need more timers?

  • PeriodicTimer0AInts_4C123
  • PeriodicTimer1AInts_4C123
  • PeriodicTimer2AInts_4C123
  • PeriodicTimer3AInts_4C123
    • 32-bit
    • Period up to 232*12.5ns= 53 sec
    • Separate ISR
    • Set priority
    • Function pointer

13-14

15 of 18

Timer 2A Periodic interrupt

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

  • Resolution: bus period
  • Precision: 32 bits
  • Max period: 53 sec (80 MHz)
  • Starter code for 0A, 1A, 2A, 3A

0) activate timer2 clock

1) disable timer2A

2) Precision to 32 bits

3) periodic mode

4) TAILR value (analogous to RELOAD)

5) clock resolution

6) clear timeout flag

7) arm timeout

8) priority 4

9) enable in NVIC

10) enable timer2A

13-15

16 of 18

Timer 2A Periodic interrupt

void (*PeriodicTask)(void); // user function

void Timer2_Init(void(*task)(void), uint32_t period){

SYSCTL_RCGCTIMER_R |= 0x04; // 0) activate timer2

PeriodicTask = task; // user function

TIMER2_CTL_R = 0x00000000; // 1) disable timer2A

TIMER2_CFG_R = 0x00000000; // 2) 32-bit

TIMER2_TAMR_R = 0x00000002; // 3) periodic mode

TIMER2_TAILR_R = period-1; // 4) reload value

TIMER2_TAPR_R = 0; // 5) 12.5ns resolution

TIMER2_ICR_R = 0x00000001; // 6) clear timeout flag

TIMER2_IMR_R = 0x00000001; // 7) arm timeout

NVIC_PRI5_R = (NVIC_PRI5_R&0x00FFFFFF)|0x80000000;

// 8) priority 4

// vector number 39, interrupt number 23

NVIC_EN0_R = 1<<23; // 9) enable IRQ 23 in

TIMER2_CTL_R = 0x00000001; // 10) enable timer2A

}

Starter sounds are 8-bit 11.025 kHz

Output one data to DAC at 11.025 kHz

Slowest period is 53 sec

13-16

17 of 18

Timer 2A plays sounds

// trigger is Timer2A Time-Out Interrupt

// set periodically TATORIS set on rollover

void Timer2A_Handler(void){

TIMER2_ICR_R = TIMER_ICR_TATOCINT;// ack

(*PeriodicTask)(); // execute user task

}

void Timer2A_Stop(void){

TIMER2_CTL_R &= ~0x00000001; // disable

}

void Timer2A_Start(void){

TIMER2_CTL_R |= 0x00000001; // enable

}

Ack

Stuff

Output one value to DAC to create sound

Call to stop sound

Call to start sound

TATORIS

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

13-17

18 of 18

Sound

  • Convert wav to text
    • Select number of bits
    • Choose a fixed sampling rate
    • Store as array in ROM
  • Start sound (from game engine)
    • Set Flag or arm interrupt
    • Set pointer to sound array
    • Index=0
    • Size=number of points in array
  • Timer interrupt
    • Output one data to DAC
    • Stop at end (Index==Size)
      • Either set flag=0
      • Or disarm

Bard, Tiwari, Cuevas, Holt, Gerstlauer, Valvano, Erez, Telang, Yerraballi

http://users.ece.utexas.edu/~valvano/Volume1/downloads.htm

http://users.ece.utexas.edu/~valvano/Volume1/WC.m

http://users.ece.utexas.edu/~valvano/Volume1/WavPlay.zip

https://youtu.be/YHZj54ag83A

https://youtu.be/ThSmcr06Pnc

13-18