Digital Circuits
Microcontroller Principles
20 questions By Tony R. Kuphaldt
-
Question 10 of 20
A microcontroller is a specialized type of digital computer used to provide automatic sequencing or control of a system. Microcontrollers differ from ordinary digital computers in being very small (typically a single integrated circuit chip), with several dedicated pins for input and/or output of digital signals, and limited memory. Instructions programmed into the microcontroller’s memory tell it how to react to input conditions, and what types of signals to send to the outputs.
The simplest type of signal “understood” by a microcontroller is a discrete voltage level: either “high” (approximately V) or “low” (approximately ground potential) measured at a specified pin on the chip. Transistors internal to the microcontroller produce these “high” and “low” signals at the output pins, their actions being modeled by SPDT switches for simplicity’s sake:

It does not require much imagination to visualize how microcontrollers may be used in practical systems: turning external devices on and off according to input pin and/or time conditions. Examples include appliance control (oven timers, temperature controllers), automotive engine control (fuel injectors, ignition timing, self-diagnostic systems), and robotics (servo actuation, sensory processing, navigation logic). In fact, if you live in an industrialized nation, you probably own several dozen microcontrollers (embedded in various devices) and don’t even realize it!
One of the practical limitations of microcontrollers, though, is their low output drive current limit: typically less than 50 mA. The miniaturization of the microcontroller’s internal circuitry prohibits the inclusion of output transistors having any significant power rating, and so we must connect transistors to the output pins in order to drive any significant load(s).
Suppose we wished to have a microcontroller drive a DC-actuated solenoid valve requiring 2 amps of current at 24 volts. A simple solution would be to use an NPN transistor as an “interposing” device between the microcontroller and the solenoid valve like this:

Unfortunately, a single BJT does not provide enough current gain to actuate the solenoid. With 20 mA of output current from the microcontroller pin and a β of only 25 (typical for a power transistor), this only provides about 500 mA to the solenoid coil.
A solution to this problem involves two bipolar transistors in a Darlington pair arrangement:

However, there is another solution yet - replace the single BJT with a single MOSFET, which requires no drive current at all. Show how this may be done:

Reveal answer
Notes:The purpose of this long-winded question is not just to have students figure out how to replace a BJT with a MOSFET, but also to introduce them to the concept of the microcontroller, which is a device of increasing importance in modern electronic systems.
Some students may inquire as to the purpose of the diode in this circuit. Explain to them that this is a commutating diode, sometimes called a free-wheeling diode, necessary to prevent the transistor from being overstressed by high-voltage transients produced by the solenoid coil when de-energized (“inductive kickback”).
-
Question 11 of 20
A microcontroller is used to provide automatic power factor correction for an AC load:

Examine this schematic diagram, then answer the following questions:
- •
- How can the microcontroller sense the power factor of the AC load?
- •
- How many discrete steps of power factor correction can the microcontroller engage through its four output pins?
- •
- What would the MCU’s output be to correct for a load drawing 15 amps with a lagging power factor of 0.77? Assume a line frequency of 60 Hz, and a correction algorithm that adjusts for the best lagging power factor (i.e. it will never over-correct and produce a leading power factor).
- •
- What is the corrected (total) power factor with those capacitors engaged?
Reveal answerI’ll let you and your classmates discuss how the MCU might detect power factor. There is more than one valid solution for doing so!
The 20 μF and 80 μF capacitors would both be engaged: MCU output DCBA would be 0101 (note that the outputs must go low to energize their respective relays!). With this output, the corrected power factor would be 0.99939 rather than the original 0.77.
Notes:This question poses some interesting concepts for review, as well as synthesizing old and new concepts in electronics for your students to consider. Be sure to allow plenty of time for discussion on this question, as well as any necessary review time for power factor calculations!
-
Question 12 of 20
This microcontroller is programmed to vary the perceived brightness of an LED by means of pulse-width modulation (PWM) control of pin 0’s output:

Pseudocode listing Declare Pin0 as an output
Declare X as an integer variable
LOOP
Set Pin0 LOW
Pause for 100 - X microseconds
Set Pin0 HIGH
Pause for X microseconds
ENDLOOP
Determine what the value of X must be to set the LED’s brightness at 80%, and also what the frequency of the PWM signal is.
Reveal answerThis question is probably best answered by drawing a timing diagram of Pin 0’s output, noting the times of 100 - X μs and X μs.
Follow-up question: what is the resolution of this PWM control, given that X is an integer variable? How might we improve the resolution of this PWM control scheme?
Notes:Pulse-width modulation (PWM) is a very common and useful way of generating an analog output from a microcontroller (or other digital electronic circuit) capable only of “high” and “low” voltage level output. With PWM, time (or more specifically, duty cycle) is the analog domain, while amplitude is the digital domain. This allows us to “sneak” an analog signal through a digital (on-off) data channel.
In case you’re wondering why I write in pseudocode, here are a few reasons:
- No prior experience with programming required to understand pseudocode
- It never goes out of style
- Hardware independent
- No syntax errors
If I had decided to showcase code that would actually run in a microcontroller, I would be dooming the question to obsolescence. This way, I can communicate the spirit of the program without being chained to an actual programming standard. The only drawback is that students will have to translate my pseudocode to real code that will actually run on their particular MCU hardware, but that is a problem guaranteed for some regardless of which real programming language I would choose.
Of course, I could have taken the Donald Knuth approach and invented my own (imaginary) hardware and instruction set . . .






