08.01.2013 Views

Introduction to Microcontrollers

Introduction to Microcontrollers

Introduction to Microcontrollers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2.3. DIGITAL I/O 39<br />

Note that a prudent hardware designer will make sure that you can set the two registers either<br />

way by designing the external circuit in such a manner that the default state of the hardware if it is<br />

not driven by the controller (this occurs for example during a reset of the controller, so the hardware<br />

designer must provide for it) is the same as when the controller pin outputs its PORT reset value. This<br />

way, if you set the pin <strong>to</strong> output first, there will be no change in its value and you can set the PORT<br />

pin at your leisure.<br />

To conclude, if the controller allows and the hardware does not mind, set PORT first and DDR<br />

afterwards. But always check <strong>to</strong> be sure this has no ill side-effects!<br />

2.3.3 Exercises<br />

Exercise 2.3.1 The sole task of your microcontroller is <strong>to</strong> moni<strong>to</strong>r a digital signal which has impulses<br />

of duration ≥ 1µs. To do so, you continuously read and process the pin state. Reading takes 1 cycle,<br />

processing the value takes 3 cycles. How fast does your microcontroller have <strong>to</strong> be so that you will<br />

never miss any impulses?<br />

Exercise 2.3.2 If you enhance the previous example by another line of code that puts the read value<br />

on an output pin as well (1 cycle), what is you minimum operating frequency? How much can the<br />

output signal generated by you differ from the input signal (delay and dis<strong>to</strong>rtions)?<br />

Exercise 2.3.3 Can you think of a situation where enabling the pull-up resis<strong>to</strong>r of a pin before setting<br />

it <strong>to</strong> output can cause a problem in the external circuit?<br />

Exercise 2.3.4 Assume that the Schmitt-trigger of Figure 2.11 has a propagation delay (that is, the<br />

time the signal is delayed while passing through the component) of k1 ns, and a latch has a propagation<br />

delay of k2 ns. Augment din accordingly.<br />

Exercise 2.3.5 In Figure 2.12, we have connected the switch directly <strong>to</strong> the controller pin without any<br />

current limiting resis<strong>to</strong>r in series with the switch. Was this wise? Even if the controller can handle<br />

the current, what reasons might a hardware designer have <strong>to</strong> put in a resis<strong>to</strong>r anyway?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!