Task 3: Simplified digital piano (1.5 points)
A digital piano uses PWM to generate a tone on a speaker. A square wave can be created (50% duty cycle H = L) with a period selected for the desired tone frequency. Consider generating music notes. A musical note can be generated using a signal of a particular frequency. Frequencies for some notes are shown in the table below. These are low notes, corresponding perhaps to the leftmost keys on a piano (for reference, "middle C" is C4 which is 261.63 Hz).
Note Freq. (Hz) Period (sec)
Co 16.35 0.061
Do 18.35 0.054
Eo 20.60 0.049
Fo 21.83 0.046
Go 24.50 0.041
Ao 27.50 0.036
Bo 30.87 0.032
C1 32.70 0.031
Figure 1: Musical Notes and Frequencies.
Suppose each switch A0, A1,... A7 corresponds to notes C0, D0,...C1, with higher inputs having priority over lower inputs. A synchSM can be constructed with a period of 20 ms that spends H ticks in a state that outputs B0=1 and L ticks outputs B0=0. Another state can set variable X to the interval required by the input switch. (Note: RIMS does not presently support periods less than 20 ms). Tones generated by square waves. BO=0 while no key is pressed.
Tips: Use 2 SynchSMs, one for reading the Keys, and the other for generating the tones, and use a global variable to share data between them. Since RIMS cannot simulate sound output, we assumed X = 10 key. Key is A0...A7 value 1-8. H = L = 2X.
Tasks:
3.1 Design and Implement the above digital piano system in RIBS. (1 point)
3.2 Screenshot RIMS and generated timing diagram while A = 64. (0.5 point)