Page 264 - ARM Based Microcontroller Projects Using MBED
P. 264
250 8. INTERMEDIATE LEVEL PROJECTS
BEGIN
Configure PA_8 as PWM port
Define melody frequencies
Define melody durations
DO for all Notes
Calculate melody periods
Calculate melody durations
Set the Duty Cycles to 50%
ENDDO
DO FOREVER
DO for all Notes
Set PWM period for a note
Set the pulse width for a note
Wait for the note duration
Stop the PWM
Wait 100ms note gap
Get next note
ENDDO
Wait 3 seconds
ENDDO
END
FIG. 8.120 PDL of the project.
8.35.8 Suggestions for Additional Work
Modify the program given in Fig. 8.121 by changing the durations between the notes and
see its effects. How can you make the melody run quicker?
8.36 PROJECT 30—ELECTRONIC ORGAN
8.36.1 Description
This is an electronic organ project. Keys a–k on the keyboard are used to generate the
musical notes in the octave range C5—C6. Pressing a key generates the musical note for
the duration of 200ms. PWM waveforms with 50% duty cycles are generated for the notes.
Serial interrupts are used in this program and all the notes are generated inside the
serial ISR.