Handling events, button interrupts and timer interrupts. We want to be able to respond to external events, as they occur. Or to create a precisely timed series of events.
when the pin chages from a 0 to a 1
when the pin chages from a 1 to a 0
The repository s2.1 uses a falling and rising edge interrupt on each of the two buttons on the base board.
The FRDM-K64F had a Periodic Interrupt Timer (PIT). This can generate an interrupt at a given rate. There are 4 individual timers, which can be used in isolation or chained together to give a more flexible (and longer period) interrupt pattern.
The Mbed library uses this to drive a soft-timer. This allows an arbitrary number of functions to be called at given periods, rather that depend on hardware limits.
Clone s2.2
Modify the program to use a callback every 1ms (1000µs).
Use the callback function (flash()
) to count in ms, and flash an led with the following pattern:
Try some of the flashing patterns from seminar 01
The MBED library uses a soft timer with a microsecond (μs) resolution.
We can write our own simpler version, to control an LED flashing. s2.3
period
and duration
of the flashesMorse is sent as a series of flashes, dots and dashes. There is a convention for the timing as follows:
The dot duration is the basic unit of time measurement in code transmission.
The duration of a dash is three times the duration of a dot.
Each dot or dash is followed by a short silence, equal to the dot duration.
The letters of a word are separated by a space equal to three dots (one dash),
and the words are separated by a space equal to seven dots.
0
for off 1
for on, a dash is 111
)0
s and 1
s turning the LED on or off as required.The word PARIS is often used to measure timing in Morse transmissions, it is 50 dot-units long. At 10 words per-minute, what is the length of a dot-unit? Use this as the period for the timer.
0
s and 1
s?How would you convert it directly into 0
s and 1
s?
0
s and 1
s as bits, how would you store a message in memory?One suggestion of how the skeleton of the callback might look.
Assume the message is a string/array pointed to by message
char c = *message++; /* sets c to the next character,
and moves the pointer on by one */
if( c=='0' ) /* off */
if( c=='1' ) /* off */
if( c=='\0' ) /* NUL character at the end of a C string */
Now you have created one of the first digital network communications devices!
You can send messages to each other.
(assuming you can read Morse)